DavidAnson / markdownlint

A Node.js style checker and lint tool for Markdown/CommonMark files.
MIT License
4.76k stars 723 forks source link

Include additional schema/types for strict rule name verification #1248

Closed regseb closed 1 month ago

regseb commented 4 months ago

If the configuration contains an unknown rule: Markdownlint must report that the rule isn't supported.

For example, ESLint reports the error: Definition for rule 'no-konsole' was not found.

7 years ago, I misspelled the commonds-show-output rule. And I've just realized it, thanks to a spellchecker that reported that the word commonds doesn't exist.

DavidAnson commented 4 months ago

This has come up before, though I can’t find the discussion. Basically, because custom rules (like the one you are using) exist, there is no definitive list of valid rules they could appear in configuration. There IS a schema for configuration files and I have instructions for how to use it generally as well as how to identify non-core rules here: https://github.com/DavidAnson/markdownlint/blob/main/schema/ValidatingConfiguration.md

But I do not think it is appropriate to throw an error just because a configured rule does not happen to be in use at the moment. That same configuration file could be used across multiple runs of the tool and some of those runs may include or exclude various rules. It’s not wrong to configure a rule that isn’t in use, though I understand why you would have liked to be alerted in this scenario.

I’m open to suggestions, but think that validating with a schema as above is a reasonable approach.

regseb commented 3 months ago

You could provide two schemas: the current markdownlint-config-schema.json and the new markdownlint-config-strict-schema.json which is the same schema, but with “additionalProperties”: false. And export a new type ConfigurationStrict which is type Configuration without [k: string]: unknown.

With this solution, I can detect my problem with the JSDoc /** @type {import("markdownlint").ConfigurationStrict} */ and TypeScript.