mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-26 01:36:03 +03:00
[GH-ISSUE #576] Configurable custom rules in .markdownlint.jsonc #459
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#459
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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.
@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.
@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.
@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--rulesparameter, 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/markdownlintcli2I’m not sure I understand your scenario, but it sounds like you might choose to include the code for
markdownlint-rule-helpersdirectly as it is a single file with no dependencies: https://github.com/DavidAnson/markdownlint/blob/main/helpers/helpers.js@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?@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
@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?
@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.