ruff/crates/ruff_dev/src
Micha Reiser 26c37b1e0e
Add knot.toml schema (#15735)
## Summary

Adds a JSON schema generation step for Red Knot. This PR doesn't yet add
a publishing step because it's still a bit early for that


## Test plan

I tested the schema in Zed, VS Code and PyCharm:

* PyCharm: You have to manually add a schema mapping (settings JSON
Schema Mappings)
* Zed and VS code support the inline schema specification

```toml
#:schema /Users/micha/astral/ruff/knot.schema.json


[environment]
extra-paths = []


[rules]
call-possibly-unbound-method = "error"
unknown-rule = "error"

# duplicate-base = "error"
```

```json
{
    "$schema": "file:///Users/micha/astral/ruff/knot.schema.json",

    "environment": {
        "python-version": "3.13",
        "python-platform": "linux2"
    },

    "rules": {
        "unknown-rule": "error"
    }
}
```


https://github.com/user-attachments/assets/a18fcd96-7cbe-4110-985b-9f1935584411


The Schema overall works but all editors have their own quirks:

* PyCharm: Hovering a name always shows the section description instead
of the description of the specific setting. But it's the same for other
settings in `pyproject.toml` files 🤷
* VS Code (JSON): Using the generated schema in a JSON file gives
exactly the experience I want
* VS Code (TOML): 
* Properties with multiple possible values are repeated during
auto-completion without giving any hint how they're different. ![Screen
Shot 2025-02-06 at 14 05 35
PM](https://github.com/user-attachments/assets/d7f3c2a9-2351-4226-9fc1-b91aa192a237)
* The property description mushes together the description of the
property and the value, which looks sort of ridiculous. ![Screen Shot
2025-02-06 at 14 04 40
PM](https://github.com/user-attachments/assets/8b72f04a-c62a-49b5-810f-7ddd472884d0)
* Autocompletion and documentation hovering works (except the
limitations mentioned above)
* Zed:
* Very similar to VS Code with the exception that it uses the
description attribute to distinguish settings with multiple possible
values ![Screen Shot 2025-02-06 at 14 08 19
PM](https://github.com/user-attachments/assets/78a7f849-ff4e-44ff-8317-708eaf02dc1f)


I don't think there's much we can do here other than hope (or help)
editors improve their auto completion. The same short comings also apply
to ruff, so this isn't something new. For now, I think this is good
enough
2025-02-07 10:59:40 +01:00
..
format_dev.rs Alternate quotes for strings inside f-strings in preview (#13860) 2024-10-23 07:57:53 +02:00
generate_all.rs Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
generate_cli_help.rs help: enable auto-wrapping of help output (#9633) 2024-01-24 10:51:07 -05:00
generate_docs.rs DOCS: navigate back to rule overview linter (#13368) 2024-09-16 16:21:26 +00:00
generate_json_schema.rs Move Configuration to ruff_workspace crate (#6920) 2023-08-28 06:21:35 +00:00
generate_knot_schema.rs Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
generate_options.rs Promote lint. settings over top-level settings (#9476) 2024-02-01 13:35:02 -06:00
generate_rules_table.rs Improve Docs: Pylint subcategories' codes (#15909) 2025-02-03 13:53:36 +01:00
main.rs Add knot.toml schema (#15735) 2025-02-07 10:59:40 +01:00
print_ast.rs Maintain synchronicity between the lexer and the parser (#11457) 2024-06-03 18:23:50 +05:30
print_cst.rs Disallow unreachable_pub (#4314) 2023-05-11 18:00:00 -04:00
print_tokens.rs Manual impl of Debug on Token (#11958) 2024-06-22 04:18:24 +00:00
round_trip.rs Harmonise methods for distinguishing different Python source types (#13682) 2024-10-09 13:18:52 +00:00