Repository navigation
feat(schema): describe rule sections and option types in rumdl.schema.json - #997
Merged
Merged
Conversation
….json
Editors offered nothing inside a rule table: every section validated as
`{severity}` plus arbitrary keys, so `[MD013]` showed no options and a
misspelled value like `line-length = "eighty"` passed. The rule registry
already knows the rule IDs, aliases, option keys and defaults, so
`rumdl schema generate` now reads it instead of emitting the bare schemars
output:
- one `$defs/<RULE>` per rule, listing every option with the type inferred
from that rule's own serialized default, plus its snake_case spelling and
its aliases, and the rule's own one-line summary as `description`
- root properties for the 90 canonical IDs and their 95 name aliases (the
alias table also lists each ID as its own alias), so `[MD013]` and its
alias spellings resolve, with an `anyOf` merge wherever a rule name is also
a global setting (`line-length`)
- the same properties under the `[rules]` wrapper the parser accepts for
configs ported from markdownlint, instead of leaving it untyped
- root-level global shorthand (`line-length = 100`), which the previous root
`additionalProperties` rejected even though the loader accepts it
- `enabled` added to `RuleConfig`; `severity` relaxed to a case-insensitive
pattern, because the loader lowercases the value
Deliberately never stricter than the loader: unknown keys stay accepted (key
matching is case- and separator-insensitive, so no finite property set can be
closed), `$defs/GlobalConfig` stays open, rule-name lists stay plain strings,
and options whose default is a nullable or polymorphic sentinel are left
unconstrained - exactly the cases where the loader skips its type check.
The one exception is a rule section written as a value. `MD013 = false` is
warned about and then dropped by the parser, so the rule keeps running with
its defaults while the file reads as if it had switched it off; the schema
rejects it, and the module documents the distinction - the name is one the
schema models and its accepted shape is total, unlike the open set of key
spellings, and `[MD013] enabled = false` and `disable = ["MD013"]` stay valid.
Rule summaries are collected by `RuleRegistry` while it already iterates the
rules, so building the schema never constructs a rule instance of its own.
The generator is now a single entry point shared with the tests, so
`rumdl schema generate`, `test_generate_json_schema` and
`test_schema_file_is_up_to_date` cannot drift apart again; the last of those
had carried its own copy of the schemars call.
Refs rvben#988
Owner
|
Thanks @anci3ntr0ck for the work, looks good! 👍 Merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stage 1 of #988.
rumdl.schema.jsondescribed the envelope ofrumdl.toml(extends,global,per-file-ignores,per-file-flavor,code-block-tools) and nothing about rules:RuleConfigwas{ severity }withadditionalProperties: true, so every rule section and every option was invisible to an editor. This PR makes the generator describe rule sections, and the option keys whose type can be derived safely.What the generated schema now contains
$defs/<MD###>per rule (90) holdingseverity,enabledand that rule's own option keys — in both spellings, plus the extra keys itsconfig_aliases()declares (493 rule-option properties in total, e.g. 53 underMD013);[global]shorthand spellings + the 5 built-in section keys +rules;[rules]wrapper, because[rules.MD013]is accepted as an alias for[MD013](src/config/parsers.rs:855), reusing the same 185-property table;enabledon$defs/RuleConfig, and a case-insensitiveseveritypattern;anyOfon the one root name that is both a global setting and a rule section (line-length).The file grows from 21 KB to 99 KB.
Never stricter than rumdl
The schema must accept everything the loader accepts, so the tests pin the spellings rather than the other way round:
[global] exlude(unknown key),line_lengthandLINE-LENGTH, root-levelline-length = 100,[MDD13](unknown rule),[blanks_around_headings](alias section),severity = "WARNING",[MD013] heading_line_length,[MD054] preferred-styleas a list.test_schema_accepts_every_spelling_rumdl_acceptslists them;test_schema_lists_each_rule_oncefails if two root properties normalise to the same key.Three things are deliberately left unconstrained:
src/config/validation.rs:11) and, because key matching is case- and separator-insensitive, the accepted set is open — no finitepropertieslist can close a section without rejecting something rumdl takes.enable,disable,fixable,unfixable,per-file-ignoresstay{"type": "string"}. An enum would be case-sensitive, so it would reject valid configs;relax_severityshows a pattern is buildable, so the reason here is parity, not expressiveness.$defs/GlobalConfigkeepsadditionalPropertiesopen. Closing it would need the snake_case spellings thattest_schema_globalconfig_uses_kebab_casedeliberately forbids in the definition.Where an option's type cannot be derived from its serialized default — the existing nullable and polymorphic sentinels — the generator emits
{}(38 properties today), i.e. exactly where the loader skips its own type check, so the two cannot drift apart.The one place the schema is stricter, on purpose
MD013 = false, at the root or under[rules], is warned about and then dropped by the parser, so the rule keeps running with its defaults while the file reads as if it had switched it off. The schema rejects it: the name is one the schema models, the shape it accepts is total, and the intent has one spelling ([MD013] enabled = false, ordisable = ["MD013"]in[global]).test_schema_rejects_a_rule_section_written_as_a_valuepins both directions. This is the only intentional divergence and it is called out in the module documentation; happy to drop it if you would rather keep stage 1 strictly at parity.One generation path instead of three
rumdl schema generate,src/config/tests.rsandtests/config/schema_validation_test.rseach had their own copy of the pipeline. They all callrumdl_config::config_schema_json()now, and the committed file is compared byte for byte with what the command produces, somake schemaand CI can no longer disagree.Verification
cargo fmt --checkcargo clippy --lib --bins --tests -- -D warnings -D clippy::uninlined_format_argscargo test --libcargo test --tests -- --skip perf::cargo test --docrumdl schema check/schema generateRUMDL_UPDATE_SCHEMA=1 cargo test test_generate_json_schemaLinux numbers (
--skip vscode::testsonly because those four cases spawn a real editor binary). A native Windows run onx86_64-pc-windows-gnualso passes apart from the pre-existingcode.cmdfailure intests/vscode/vscode_test.rs;perf::regression tests are excluded as their module documentation prescribes.What it looks like
Validated by Even Better TOML (taplo), which consumes the schema as-is — no draft-07 conversion needed:
A rule section written as a value and a wrongly typed option are now reported:
and every spelling rumdl accepts — misspelled key, snake_case key, unknown rule name, alias section — stays quiet.
Notes
docs/stability.md:32). Everything here is additive except$defs/Severity, which trades itsenumfor an equivalent case-insensitivepattern(the loader lowercases before matching), so editors keep validating but lose the value list; the descriptions move to stage 2, as does derivingschemars::JsonSchemaon the rule config structs so option-level docs and enums come from the types themselves.