markdownlint-cli icon indicating copy to clipboard operation
markdownlint-cli copied to clipboard

Possible to use different configs for different folders?

Open borekb opened this issue 5 years ago • 7 comments

I have a project that looks like this:

  • .markdownlintrc (root config, should apply to folders 1..3 below)
  • folder-1
  • folder-2
  • folder-3
  • folder-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.

borekb avatar May 15 '20 12:05 borekb

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.

borekb avatar May 15 '20 12:05 borekb

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.)

DavidAnson avatar May 15 '20 16:05 DavidAnson

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 avatar May 16 '20 08:05 borekb

@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!

DavidAnson avatar Jul 31 '20 21:07 DavidAnson

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.

borekb avatar Aug 02 '20 13:08 borekb

@DavidAnson cli2 works beautifully for this! Does VSCode extension already do this as well?

borekb avatar Aug 13 '20 15:08 borekb

@borekb Yes, the VS Code markdownlint extension respects the "closest" .markdownlint.json file in the current/parent directory of the project.

DavidAnson avatar Aug 14 '20 03:08 DavidAnson