[GH-ISSUE #576] Configurable custom rules in .markdownlint.jsonc #459

Closed
opened 2026-03-03 01:27:05 +03:00 by kerem · 7 comments
Owner

Originally created by @NomarCub on GitHub (Sep 8, 2022).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/576

I can't see any info on how to configure custom rules in a json file, or if it is even possible.
I've seen it here that it's supposedly possible in cli2, but I'd like to use custom rules in the VSCode plugin (and the cli1 if possible).
Also, do I need to make an npm package to make custom rules? The only examples I've seen are npm packages, or custom rules within in js code in this repo, which I can't directly use in the cli or the VSCode extension.

Originally created by @NomarCub on GitHub (Sep 8, 2022). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/576 I can't see any info on how to configure custom rules in a json file, or if it is even possible. I've seen it [here](https://www.npmjs.com/package/markdownlint-rule-github-internal-links) that it's supposedly possible in cli2, but I'd like to use custom rules in the VSCode plugin (and the cli1 if possible). Also, do I need to make an npm package to make custom rules? The only examples I've seen are npm packages, or custom rules within in js code in this repo, which I can't directly use in the cli or the VSCode extension.
kerem 2026-03-03 01:27:05 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@DavidAnson commented on GitHub (Sep 8, 2022):

Custom rules are not supported by CLI1. You can find examples of configuring and using them (as packages and loose files) in the CLI2 repository here: https://github.com/DavidAnson/markdownlint-cli2/tree/main/test/customRules

Scenarios where the custom rule is available within the repository should work as-is with the VS Code extension when used as a desktop app.

<!-- gh-comment-id:1240944870 --> @DavidAnson commented on GitHub (Sep 8, 2022): Custom rules are not supported by CLI1. You can find examples of configuring and using them (as packages and loose files) in the CLI2 repository here: https://github.com/DavidAnson/markdownlint-cli2/tree/main/test/customRules Scenarios where the custom rule is available within the repository should work as-is with the VS Code extension when used as a desktop app.
Author
Owner

@NomarCub commented on GitHub (Sep 8, 2022):

Shouldn't the docs for custom rule configs be here then, if it's also supported in the VSCode plugin, not only in cli2?
Also, is it not supported in cli1 as command line input or in any way from a json config? The readmes say there's supposed to be feature parity between cli1 and cli2.

I mucked around with the cli2 repo, but I haven't found the match for my use case yet. I already store a .markdownlint.jsonc in my repo with no node modules and I'd like to keep it that way with the custom rules. However I need the helpers if I want to do anything easily, and I can't get the require() to work with a global markdownlint npm install.

<!-- gh-comment-id:1241221783 --> @NomarCub commented on GitHub (Sep 8, 2022): Shouldn't the docs for custom rule configs be here then, if it's also supported in the VSCode plugin, not only in cli2? Also, is it not supported in cli1 as command line input or in any way from a json config? The readmes say there's supposed to be feature parity between cli1 and cli2. I mucked around with the cli2 repo, but I haven't found the match for my use case yet. I already store a .markdownlint.jsonc in my repo with no node modules and I'd like to keep it that way with the custom rules. However I need the helpers if I want to do anything easily, and I can't get the require() to work with a global markdownlint npm install.
Author
Owner

@DavidAnson commented on GitHub (Sep 9, 2022):

Configuring custom rules with a file is done via .markdownlint-cli2.* which has no direct relevance to this project which implements only the core library. That configuration file format is documented by CLI2 which implements support for it. It is referenced by the VS Code extension which supports it by virtue of reusing CLI2. CLI1 allows the use of custom rules via the --rules parameter, though the implementation is different. I make no claim of feature parity between CLI1 and CLI2. If you have a reference to somewhere that suggests otherwise, I can try to correct their understanding. I wrote about the deliberately different approach I took with CLI2 here: https://dlaa.me/blog/post/markdownlintcli2

I’m not sure I understand your scenario, but it sounds like you might choose to include the code for markdownlint-rule-helpers directly as it is a single file with no dependencies: https://github.com/DavidAnson/markdownlint/blob/main/helpers/helpers.js

<!-- gh-comment-id:1241489196 --> @DavidAnson commented on GitHub (Sep 9, 2022): Configuring custom rules with a file is done via `.markdownlint-cli2.*` which has no direct relevance to this project which implements only the core library. That configuration file format is documented by CLI2 which implements support for it. It is referenced by the VS Code extension which supports it by virtue of reusing CLI2. CLI1 allows the use of custom rules via the `--rules` parameter, though the implementation is different. I make no claim of feature parity between CLI1 and CLI2. If you have a reference to somewhere that suggests otherwise, I can try to correct their understanding. I wrote about the deliberately different approach I took with CLI2 here: https://dlaa.me/blog/post/markdownlintcli2 I’m not sure I understand your scenario, but it sounds like you might choose to include the code for `markdownlint-rule-helpers` directly as it is a single file with no dependencies: https://github.com/DavidAnson/markdownlint/blob/main/helpers/helpers.js
Author
Owner

@NomarCub commented on GitHub (Sep 9, 2022):

I missed that the VSCode extension uses cli2, not the lib directly. That clears some things up, thanks!

The sentence "I will continue to update it as I release new versions of the markdownlint library" still kind of suggested to me that the main functionality stems from the lib, and can be expected in both clis. The overview section on cli2 is definitely misleading. It says "different" and "unconventional" and has nothing to say about additional features. The features are there further down, but to know which one, if any is cli2 specific I had to dig through both cli1 and cli2 docs, not just the readme, and still wasn't sure. Even the compatibility section doesn't say anything.

I know I could copy the helper file, but I don't want to version control it and for it to take up space in my repo.
I got a little further, and the global require works from the command line now. The VSCode extension still throws errors:
ERROR: Exception while linting with markdownlint-cli2: Error: Cannot find module 'markdownlint/helpers'. Could it also look for global packages? Or have the markdownlint library included?

<!-- gh-comment-id:1241607727 --> @NomarCub commented on GitHub (Sep 9, 2022): I missed that the VSCode extension uses cli2, not the lib directly. That clears some things up, thanks! The sentence "I will continue to update it as I release new versions of the markdownlint library" still kind of suggested to me that the main functionality stems from the lib, and can be expected in both clis. The [overview](https://github.com/DavidAnson/markdownlint-cli2#overview) section on cli2 is definitely misleading. It says "different" and "unconventional" and has nothing to say about additional features. The features are there further down, but to know which one, if any is cli2 specific I had to dig through both cli1 and cli2 docs, not just the readme, and still wasn't sure. Even the [compatibility](https://github.com/DavidAnson/markdownlint-cli2#compatibility) section doesn't say anything. I know I could copy the helper file, but I don't want to version control it and for it to take up space in my repo. I got a little further, and the global require works from the command line now. The VSCode extension still throws errors: `ERROR: Exception while linting with markdownlint-cli2: Error: Cannot find module 'markdownlint/helpers'`. Could it also look for global packages? Or have the markdownlint library included?
Author
Owner

@DavidAnson commented on GitHub (Sep 9, 2022):

Both CLI implementations use the same core markdownlint library, but in different ways and that leads to some features being available in only one or the other.

For the global require scenario, please see the issue and linked discussion here: https://github.com/DavidAnson/vscode-markdownlint/issues/180

<!-- gh-comment-id:1242169696 --> @DavidAnson commented on GitHub (Sep 9, 2022): Both CLI implementations use the same core markdownlint library, but in different ways and that leads to some features being available in only one or the other. For the global require scenario, please see the issue and linked discussion here: https://github.com/DavidAnson/vscode-markdownlint/issues/180
Author
Owner

@NomarCub commented on GitHub (Sep 9, 2022):

Is this what you meant about require?

Well, I don't exactly need to reach globally installed rules, I'd only need a globally installed markdownlint reachable within / from the VSCode extension. Should I open an issue about that in the extension repo?

<!-- gh-comment-id:1242239545 --> @NomarCub commented on GitHub (Sep 9, 2022): Is [this](https://github.com/DavidAnson/markdownlint-cli2/issues/24#issuecomment-885985945) what you meant about require? Well, I don't exactly need to reach globally installed rules, I'd only need a globally installed markdownlint reachable within / from the VSCode extension. Should I open an issue about that in the extension repo?
Author
Owner

@DavidAnson commented on GitHub (Sep 9, 2022):

Yes. Go ahead and open an issue, though I'm still not sure how it would be addressed. Without a versioning story, exposing the helpers library to custom rules in VS Code extension context could lead to breaks any time a new extension is released. (The custom rules API is deliberately simple and static to try to avoid problems around versioning.) I don't want to try to reimplement a package manager for this scenario when it's pretty straightforward to bundle helpers.js alongside the rule implementation.

<!-- gh-comment-id:1242342459 --> @DavidAnson commented on GitHub (Sep 9, 2022): Yes. Go ahead and open an issue, though I'm still not sure how it would be addressed. Without a versioning story, exposing the helpers library to custom rules in VS Code extension context could lead to breaks any time a new extension is released. (The custom rules API is deliberately simple and static to try to avoid problems around versioning.) I don't want to try to reimplement a package manager for this scenario when it's pretty straightforward to bundle helpers.js alongside the rule implementation.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#459
No description provided.