Skip to content

Conversation

@Prathamesh-tech-eng
Copy link

Description:
This PR adds JSON schemas (pyrefly.json and pyproject-tool-pyrefly.json) to enable editor support (auto-completion, validation, and documentation) for Pyrefly configuration files in pyrefly.toml and pyproject.toml.

Fixes #536

Notes:

  • I've constructed this schema based on crates/pyrefly_config/src/config.rs and and crates/pyrefly_config/src/base.rs
  • I used kebab-case for keys (e.g., project-includes) as defined by the Serde structs.
  • I placed the schema in the schemas/ directory

@meta-cla
Copy link

meta-cla bot commented Jan 13, 2026

Hi @Prathamesh-tech-eng!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Copy link
Contributor

@connernilsen connernilsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Prathamesh-tech-eng, thanks for working on this!

I have a few recommendations for changes, and an additional followup to make sure this is integrated into Schemastore as well.

For the followup, can we:

  1. make a PR to schemastore to add our pyrefly.json there.
  2. update their pyproject.toml to have a tool entry for Pyrefly.
  3. Add some tests like the ones for pyproject.toml? Doesn't need to be a ton, but just some stuff to verify what we're doing is generally correct.

Comment on lines 237 to 260
"errors": {
"description": "Error configuration overrides for matched files.",
"type": "object",
"additionalProperties": {
"type": "boolean"
}
},
"replace-imports-with-any": {
"description": "Module glob patterns to replace with typing.Any for matched files.",
"type": "array",
"items": {
"type": "string"
}
},
"untyped-def-behavior": {
"description": "Override untyped function behavior for matched files.",
"type": "string",
"enum": ["check-and-infer-return-type", "check-and-infer-return-any", "skip-and-infer-return-any"]
},
"ignore-errors-in-generated-code": {
"description": "Override generated code error handling for matched files.",
"type": "boolean"
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is possible, so if you struggle to find a way to do this, don't worry about it.

Could we pull this out into a subschema and do two things with it?

  1. flatten the subschema into the top-level object
  2. reuse that sub-schema here

This would help us avoid redefining definitions in multiple places, which means we won't have to remember to update multiple things if there are changes to the config base object.

Again, not sure if flattening is possible, but it would be awesome if it works!

@@ -0,0 +1,277 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at how the pyproject.toml in schemastore works, we might be able to get away with just the pyrefly.json config below and reference it in a pyproject definition.

When we merge into schemastore, I'd like to follow those examples, so this file will be redundant.

"description": "The Python version to use for type checking. Format: <major>[.<minor>[.<micro>]]",
"type": "string",
"default": "3.13.0",
"pattern": "^\\d+(\\.\\d+)?(\\.\\d+)?$"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome validation!

Comment on lines 183 to 209
{
"if": {
"properties": {
"type": {"const": "buck"}
}
},
"then": {
"properties": {
"isolation-dir": true,
"extras": true
}
}
},
{
"if": {
"properties": {
"type": {"const": "custom"}
}
},
"then": {
"required": ["command"],
"properties": {
"command": true,
"repo_root": true
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to set not conditions here for the custom-only fields when using the buck type, and vice versa for custom with buck-only fields?

It might be possible to do a subschema for the buck and custom fields, specify both subschemas in the field definitions, and just list the subschemas here to simplify the conditions.

Comment on lines 191 to 193
"isolation-dir": true,
"extras": true
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check, these aren't required fields, right? Just fields that are allowed with the buck type?

"required": ["command"],
"properties": {
"command": true,
"repo_root": true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repo root should be for all types, not just custom

- Extract configBase into reusable  subschema
- Flatten configBase properties into top-level schema
- Reuse configBase in sub-config via
- Fix build-system: move repo_root to all types, add not conditions
- Simplify pyproject-tool-pyrefly.json to reference pyrefly.json
- All tests passing
@Prathamesh-tech-eng
Copy link
Author

@connernilsen I've addressed all the feedback! Here is a summary of the changes:

  1. Extracted configBase to avoid repetition
    I created a $defs/configBase section containing all the shared properties (like errors, untyped-def-behavior, replace-imports-with-any, etc.).

  2. Flattened ConfigBase into the root
    All configBase properties are now duplicated in the main properties section so they're available at the root level. This ensures the schema works correctly with additionalProperties: false.

  3. Applied ConfigBase to sub-config
    The sub-config items now use allOf with { "$ref": "#/$defs/configBase" }. This ensures that any future changes to the base config automatically propagate to sub-configs without manual duplication.

  4. Fixed Build System Logic
    I cleaned up the validation logic:

Moved repo_root: It is now a top-level property inside build-system, accessible to both buck and custom types (addressing your comment about it being for all types).

Added strict not conditions:

If type: "buck", the schema explicitly forbids command.

If type: "custom", the schema requires command but forbids isolation-dir and extras.

Clarified optional fields: isolation-dir and extras are defined as properties but not required (answering your question about them).

  1. Simplified pyproject-tool-pyrefly.json
    I updated this to just reference pyrefly.json via $ref rather than duplicating 270+ lines. This aligns with the SchemaStore pattern you mentioned.

Once this is approved, I'll proceed with opening the PR to SchemaStore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Pyrefly config to schemastore

2 participants