mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 01:05:55 +03:00
[GH-ISSUE #42] Add support for custom rules #34
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#34
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 @miljan-aleksic on GitHub (Jan 13, 2017).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/42
Hi, nice tool! Thanks.
I would like to add my own custom rules, similar to rules param object, declare custom rules in the config. Would you consider?
@DavidAnson commented on GitHub (Jan 14, 2017):
Thanks!
The topic of custom rules was raised before in issue #39 - please have a look at my comments there for more. Briefly, this is an eventual goal, but there are a number of questions I need to answer before starting work.
In the meantime, if you list out the rules you have in mind, they might be things I think are broadly applicable and worth adding to the core set of rules myself.
@miljan-aleksic commented on GitHub (Jan 14, 2017):
Hi @DavidAnson!
Basically, I would like to be able to fix some common issues when copy/pasting the content (for external checking for example) where the result ends up with double spaces, double dots, a missing space after point or comma, invalid carachters. etc. I would gladly help working on this rule for the core, if you find it useful.
@DavidAnson commented on GitHub (Jan 14, 2017):
Double spaces was already on my list. What you describe seems like a generalization of that. I will add that to my notes. If you want to create this rule, please begin by proposing a name, parameters, and behavior (in a new issue) so we can be sure we agree on the basics first. Thanks!
@DavidAnson commented on GitHub (May 20, 2017):
More details about a proposed "typography" rule are captured in #51. The idea of custom rules has been on my list, but needs more thought/planning (see #39). I'm going to close this issue since it seems the intent is captured elsewhere. Thanks again!
@henrikhaugboelle commented on GitHub (Sep 25, 2017):
I have mixed feelings about posting this, but I badly needed a way to extend the existing rules. So I went on a JavaScript adventure and cooked up a hacky solution for it. I'm using webpack and am using the markdownlint in the browser.
The
markdownlint.jsfile looks for./rules, which contains the ruleset. We can tell webpack to resolve./rulesto whatever we like using aliases. So we'll tell it to resolve to a custom lint-rules.js file:In our custom
lint-rules.jsfile, we can import and subsequently export the original rules like this:At this stage, the markdownlint library should pretty much just behave as it usually does. But hey! Know we have got an opportunity to modify the rules. So we can do stuff like this:
Now we've effectively added a new rule (
KG001) to the ruleset that the markdownlint library uses. (Note: I needed to copy a few of the helper methods from the originalrules.js, so I could use them in my new custom rule).Finally I needed to turn on the rule in the markdownlint options config.
Warning: It goes without saying that this is not a viable solution and it will certainly not fit every scenario. Even worse, it relies on the internals of the library, so if these changes, this approach will most likely break. But it is a way to add custom rules.
@DavidAnson commented on GitHub (Sep 25, 2017):
This is awesome! Thank you for sharing. :)