Skip to content

feat(schema): describe rule sections and option types in rumdl.schema.json - #997

Merged
rvben merged 1 commit into
rvben:mainfrom
anci3ntr0ck:feat/schema-rule-sections
Nov 12, 2026
Merged

rvben merged 1 commit into
rvben:mainfrom
anci3ntr0ck:feat/schema-rule-sections

Conversation

@anci3ntr0ck

@anci3ntr0ck anci3ntr0ck commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Stage 1 of #988.

rumdl.schema.json described the envelope of rumdl.toml (extends, global, per-file-ignores, per-file-flavor, code-block-tools) and nothing about rules: RuleConfig was { severity } with additionalProperties: 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

  • one $defs/<MD###> per rule (90) holding severity, enabled and that rule's own option keys — in both spellings, plus the extra keys its config_aliases() declares (493 rule-option properties in total, e.g. 53 under MD013);
  • 213 root properties: 90 canonical IDs + 95 name aliases + 22 [global] shorthand spellings + the 5 built-in section keys + rules;
  • a [rules] wrapper, because [rules.MD013] is accepted as an alias for [MD013] (src/config/parsers.rs:855), reusing the same 185-property table;
  • enabled on $defs/RuleConfig, and a case-insensitive severity pattern;
  • anyOf on 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_length and LINE-LENGTH, root-level line-length = 100, [MDD13] (unknown rule), [blanks_around_headings] (alias section), severity = "WARNING", [MD013] heading_line_length, [MD054] preferred-style as a list. test_schema_accepts_every_spelling_rumdl_accepts lists them; test_schema_lists_each_rule_once fails if two root properties normalise to the same key.

Three things are deliberately left unconstrained:

  1. Keys the schema does not know. rumdl only warns about those (src/config/validation.rs:11) and, because key matching is case- and separator-insensitive, the accepted set is open — no finite properties list can close a section without rejecting something rumdl takes.
  2. enable, disable, fixable, unfixable, per-file-ignores stay {"type": "string"}. An enum would be case-sensitive, so it would reject valid configs; relax_severity shows a pattern is buildable, so the reason here is parity, not expressiveness.
  3. $defs/GlobalConfig keeps additionalProperties open. Closing it would need the snake_case spellings that test_schema_globalconfig_uses_kebab_case deliberately 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, or disable = ["MD013"] in [global]). test_schema_rejects_a_rule_section_written_as_a_value pins 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.rs and tests/config/schema_validation_test.rs each had their own copy of the pipeline. They all call rumdl_config::config_schema_json() now, and the committed file is compared byte for byte with what the command produces, so make schema and CI can no longer disagree.

Verification

Command Result
cargo fmt --check clean
cargo clippy --lib --bins --tests -- -D warnings -D clippy::uninlined_format_args clean
cargo test --lib 9224 passed, 0 failed, 1 ignored
cargo test --tests -- --skip perf:: 13 test binaries, 0 failed
cargo test --doc 40 passed, 14 ignored
rumdl schema check / schema generate up to date, idempotent
RUMDL_UPDATE_SCHEMA=1 cargo test test_generate_json_schema regenerates, byte-identical on a second run

Linux numbers (--skip vscode::tests only because those four cases spawn a real editor binary). A native Windows run on x86_64-pc-windows-gnu also passes apart from the pre-existing code.cmd failure in tests/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:

schema errors in the editor

A rule section written as a value and a wrongly typed option are now reported:

every accepted spelling stays valid

and every spelling rumdl accepts — misspelled key, snake_case key, unknown rule name, alias section — stays quiet.

Notes

  • The schema is documented as stable and additive (docs/stability.md:32). Everything here is additive except $defs/Severity, which trades its enum for an equivalent case-insensitive pattern (the loader lowercases before matching), so editors keep validating but lose the value list; the descriptions move to stage 2, as does deriving schemars::JsonSchema on the rule config structs so option-level docs and enums come from the types themselves.
  • Written with an AI coding agent under review, as noted in feat(schema): describe rule sections and options in rumdl.schema.json #988; happy to split or rework anything.

….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
@rvben
rvben merged commit da0faf7 into rvben:main Nov 12, 2026
12 of 15 checks passed
@rvben

rvben commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @anci3ntr0ck for the work, looks good! 👍 Merged.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants