markdownlint-cli
markdownlint-cli copied to clipboard
Possible to use different configs for different folders?
I have a project that looks like this:
.markdownlintrc(root config, should apply to folders 1..3 below)folder-1folder-2folder-3folder-4.markdownlintrc(special config for folder 4)
The nested folder-4/.markdownlintrc looks like this:
{
"extends": "../.markdownlintrc",
"MD041": false
}
Is there a way to run markdownlint CLI once and have it check all folders in my project – folder 1..3 with the root config and folder 4 with its own?
As a fallback, I plan to run markdownlint twice but wanted to ask first if there's a way to achieve that in one go.
BTW, I was wondering if the CLI could behave like a VSCode extension, which respects the closest config files. Maybe behind some flag to maintain backwards compatibility, for example:
markdownlint --ignore node_modules --use-closest-config-file .
I realize there might be performance implications of this.
Agreed, the two tools should be consistent. Something like what you propose may be a good approach. For now, running two passes is probably what you want to do.
(As you suggest, the scenario is a little different here versus the extension; in the extension it pretty much only ever needs to worry about one file at a time and so spending a bit of effort to find files up the tree isn’t a problem. The CLI does everything at once, so this is more problematic. Specifically, it could turn one call to the library into tens or hundreds and that may create other issues.)
It's worth noting that in the context of lint-staged, markdownlint CLI also runs for a single file only.
At this point, I have to do this:
// .lingstagedrc.js
module.exports = {
"{!(folder-4)/**/,}*.md": ["markdownlint"],
"folder-4/**/*.md": ["markdownlint -c folder-4/.markdownlint.json"],
};
With the proposed behavior, this could be simplified to:
module.exports = {
"**/*.md": ["markdownlint --use-closest-config-file"]
};
@borekb: Per my comments at https://github.com/igorshubovych/markdownlint-cli/issues/45#issuecomment-667377702 you should be able to use markdownlint-cli2 for this scenario as it supports different .markdownlint.json files for each directory. If you try it, please let me know how it goes!
Looks very good, thanks! I won't be able to test this soon but will keep that in mind for future updates of our dev infra.
@DavidAnson cli2 works beautifully for this! Does VSCode extension already do this as well?
@borekb Yes, the VS Code markdownlint extension respects the "closest" .markdownlint.json file in the current/parent directory of the project.