Repository navigation
feat(schema): describe rule options from the config structs - #1000
Merged
Merged
Conversation
Every rule config struct now derives `schemars::JsonSchema`, so `rumdl.schema.json` publishes the doc comment and the default of each option instead of only the type inferred from a serialized default. The struct that deserializes a section is the struct that describes it, so the keys an editor completes and the keys the loader accepts cannot drift apart. `Rule::config_json_schema` is the new trait method; `impl_rule_config_schema!` implements it for the 55 rules that go through it, and `RuleRegistry` collects the result next to the rest of the per-rule metadata, so generating the schema still constructs no rule of its own. Rules that do not derive the trait keep the types inferred from their registry entry. Two things stay open on purpose, for the same reason as before: a key the registry marks as untyped (sentinel) keeps an empty schema, and an option whose value is an enum is described rather than enumerated, because `#[serde(alias)]` on a variant widens the spellings the loader takes and `schemars` does not report aliases. Both decisions are documented in the module and pinned by tests: - `test_schema_accepts_every_rule_default` validates all 170 non-sentinel rule defaults against the schema; - `test_schema_accepts_enum_aliases_rumdl_accepts` loads `reflow-mode = "sentence_per_line"` and friends through the real loader and asserts the schema takes them too; - `test_schema_describes_the_options_it_derives` pins the description, the default and the sentinel case, and fails if the derives are dropped. The schema grows from 100,941 to 176,660 bytes: 331 of 498 rule option properties now carry a description. Refs rvben#988
Review of a83ef10 turned up two places where the generated schema was stricter than the loader and one where it was needlessly silent. MD084/MD088 `allow` took the derived HashSet<char> schema, which caps each item at one character and forbids repeats; the loader reads the same values from strings like "U+200B", so both written forms and duplicates are accepted there and now validate here. schemars also writes format "uint" and "uint8" for usize/u8, neither of which JSON Schema defines and both of which editors have reported as errors before (rvben#368); the non-standard formats are stripped, leaving the minimum/maximum the derive already provides. Options the registry deliberately leaves untyped kept an empty schema. They now keep their description, which constrains nothing: an editor shows what `preferred-style` does without being told which of its two shapes is legal. The rest is coverage: field doc comments for the options that had none (MD033/MD044/MD060/MD054/MD026/MD055/MD061), MD076 hooked up through config_json_schema_named instead of being skipped, relax_value_enums recursing into the array and map keywords it used to miss, and a single is_sentinel predicate instead of two copies. Described rule options go from 241/318 to 311/318, the remainder being MD073, the one rule without a config struct. Refs rvben#988
schemars names enum variants after the Rust identifiers, but the enums that deserialize by hand take kebab-case: the schema offered `MD003 style = "AtxClosed"` and `MD063 style = "TitleCase"` in a hover and then rejected them, and the same leak showed up for MD046, MD048, MD049, MD050, MD060 and MD076. Each variant now carries the spelling its `Display` and `Deserialize` agree on. test_schema_publishes_spellings_the_loader_accepts walks every "One of" list in the generated descriptions, feeds each spelling to the real loader and asserts the schema takes it too, so a hand-written enum that forgets this fails the build instead of the editor. Refs rvben#988
The guard added with the enum renames loaded a `rumdl.toml` and expected the loader to reject a spelling it could not parse. It never does: `rule_config_serde` warns about a value it cannot parse and keeps the rule's default, so the load succeeded and the assertion could not fail. Parse instead. `HeadingStyle`, `ColumnAlign` and `HeadingCapStyle` carry their own `FromStr`/`Deserialize`, so the check runs from `src/rules/mod.rs` against the spellings in the schema's own "One of" text. `CodeBlockStyle`, `CodeFenceStyle`, `EmphasisStyle` and `StrongStyle` are parsed by their config modules, so each of those carries the same check beside the parser it is checking. MD076's style is matched inside `from_config` and has no deserializable config struct to route the check through, so it stays with the description as its only contract. Mutation-checked: renaming MD003's `atx-closed` back to `AtxClosed`, or MD046's `fenced` to `atx`, fails the test with the offending spelling in the message. Refs rvben#988
The spelling guard had six copies of "find the words after One of", and the one in `config/tests.rs` skipped a description it could not parse. Read the list through a single helper, `schema_gen::published_spellings`, which panics when a description stops enumerating its spellings, so a wording drift fails the test instead of quietly reducing what is covered. MD076's style was the last uncovered spelling set: it is matched inside `from_config` rather than by a derive. Move that match into `ListItemSpacingStyle::from_spelling` (behaviour unchanged — an unknown value still keeps the default) and check the schema's spellings against it, like the other four config modules. Refs rvben#988
rvben
approved these changes
Nov 13, 2026
rvben
left a comment
Owner
There was a problem hiding this comment.
Thanks for adding the schema descriptions. The schema tests pass locally, and I’ll merge once the required checks pass.
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.
What this is
Stage 2 of #988. Stage 1 (#997) taught
rumdl.schema.jsonwhich sections exist and which keys each one takes; the type of an option came from the default value its rule serialised, so an editor could flagline-length = "eighty"but had nothing to say about whatline-lengthmeans.This PR derives
schemars::JsonSchemaon the rule config structs and publishes what they already document: a description per option, the real default, and the accepted spellings.What the schema now says
$defs/ root propertiesThe seven options that remain undescribed are
MD073's: it is the only rule with no config struct (it writes its section by hand), so its options keep the types inferred from the default. A test namesMD073as the only allowed gap, so a new rule cannot join that list quietly.$defs/MD013.properties.line-lengthnow reads, next to the key an editor completes:Two options stay looser than the struct, on purpose
Your first constraint was that the schema must never be stricter than rumdl. Two places needed that to win over detail:
preferred-styletakes a string or a list). The derived schema would describe whichever variant the field'sDeserializenames first and reject the other, so those 38 options publish a description and no type.reflow-mode = "sentence_per_line"is accepted because the field carries a#[serde(alias)], and schemars does not report aliases; several style enums are parsed by hand and are case-insensitive. Publishing anenumwould reject configs rumdl accepts, so the spellings go into the description instead ("One ofdefault,normalize, …"). The cost is real — no value completion for those keys — and it is the same trade$defs/Severityalready makes.The spelling of an enum is now the spelling users type
Deriving the schema surfaced a bug Stage 1 could not have: enums with a hand-written
Deserializehave noserde(rename_all), so schemars published the Rust variant name and an editor suggestedMD003 style = "AtxClosed", which the loader rejects. Each variant now carries#[schemars(rename = …)]with the spelling from its ownDisplay/FromStr. A guard test reads the spellings back out of the generated descriptions and parses each one, in the module that owns its parser.Tests
test_schema_accepts_every_rule_default— every default a rule publishes validates.test_schema_accepts_values_the_loader_parses—MD084/MD088allow = ["U+200B"], duplicates andU+1F3FBload, then validate.test_schema_accepts_enum_aliases_rumdl_accepts— thereflow-mode/length-modealiases.test_schema_describes_the_options_it_derives— descriptions, defaults, and the single rule allowed to have none.test_schema_never_enumerates_option_values— no rule option publishesenum/const.test_schema_accepts_the_spellings_it_publishes— every listed spelling validates.schema_publishes_spellings_that_parse(×5, one per parsing module) — every listed spelling parses, with negative controls that must fail.Verification
cargo fmt --check,cargo clippy --lib --bins --tests -- -D warnings -D clippy::uninlined_format_args,cargo test --lib(9,331 passed),cargo test --tests(14 binaries),cargo test --doc,RUSTDOCFLAGS="-D warnings" cargo doc --no-deps,rumdl schema check, andrumdl fmt --check docs/all pass.RUMDL_UPDATE_SCHEMA=1reproduces the committed file byte for byte.What it looks like in an editor
Hovering
reflow-modein[MD013]now shows the description, the default and the accepted spellings — all three read from the struct field, so they cannot drift from what the loader parses:CHANGELOG.mdentry:CONTRIBUTING.mdcalls this routine, and Stage 1 took the same route.MD013 = falseis rejected while the parser warns and drops it) is unchanged, as is the[rules]wrapper.Stable — additive changes onlyperdocs/stability.md; this is additive.Refs #988