Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export a list of available (and/or fixable) rules #1320

Closed
danbeam opened this issue Aug 6, 2024 · 5 comments
Closed

Export a list of available (and/or fixable) rules #1320

danbeam opened this issue Aug 6, 2024 · 5 comments
Labels

Comments

@danbeam
Copy link

danbeam commented Aug 6, 2024

I'd like to apply all possible fixes for rules found in this library (use case: autofix bot) and would like to not have to handle the discovery myself.

A possible solution: publicly expose a list of all rules or the fixableRuleNames that are exported in lib/constants.js but more publicly (at least I haven't found a good way to otherwise get at this data).

I'm currently deriving a list of all rules via:

globby.sync('node_modules/markdownlint/doc/md*.md').map((file) => path.basename(file, '.md'))

which is fairly icky in that it's looking at the internals of the package 😅 .

@DavidAnson
Copy link
Owner

Sorry, I don't understand your scenario. What I would expect is to call the library to lint some sort of files and then look at the results of that operation. That provides the list of failing rules and those errors with fix information are fixable. If you want to make your life easier, pass that to the applyFixes helper and update the file accordingly. I'm not seeing why you need to enumerate the implemented rules or the fixable rules as that information doesn't seem necessary per the scenario above.

function applyFixes(input, errors) {

@DavidAnson
Copy link
Owner

(Or invoke markdownlint-cli2 and tell it to apply fixes for you.)

@danbeam
Copy link
Author

danbeam commented Aug 9, 2024

The script takes a --rule option and I'm feeding yargs all the choices: string[] so that yargs() does the validation and also shows them all in --help.

I might also eventually show aliases or resolve to a canonical format because right now it's possible to get into a funky state (e.g. --rule <alias> is invalid and alias: false in our .markdownlint.cjs + equivalent --rule md0## has no effect).

@danbeam
Copy link
Author

danbeam commented Aug 9, 2024

Generally speaking though, is there not currently / do you not see the point of a rule discovery mechanism? At the simplest, just a list of all rules? Preferably with references to each of the rules' metadata.

Isn't your own doc making use of this type of list (IIRC you're using fixableRuleNames as a set and asking if that set .has() that rule name when generating your own doc .md files, eh)?

@DavidAnson
Copy link
Owner

It sounds like you are implementing another CLI? If so, I would be curious what about the existing ones is lacking?

But regarding rule metadata, everything you mention above (and more) is available in the JSON schema for configuration. This is intended to be a consumable artifact, so it is perfectly reasonable to reference and use it from the package.

https://github.com/DavidAnson/markdownlint/blob/main/schema/markdownlint-config-schema.json

@DavidAnson DavidAnson closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants