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

Possible to use different configs for different folders? #96

Open
borekb opened this issue May 15, 2020 · 7 comments
Open

Possible to use different configs for different folders? #96

borekb opened this issue May 15, 2020 · 7 comments

Comments

@borekb
Copy link

borekb commented May 15, 2020

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
Copy link
Author

borekb commented May 15, 2020

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.

@DavidAnson
Copy link
Collaborator

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

@borekb
Copy link
Author

borekb commented May 16, 2020

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"]
};

@DavidAnson
Copy link
Collaborator

@borekb: Per my comments at #45 (comment) 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!

@borekb
Copy link
Author

borekb commented Aug 2, 2020

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
Copy link
Author

borekb commented Aug 13, 2020

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

@DavidAnson
Copy link
Collaborator

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

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

No branches or pull requests

2 participants