mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-26 09:46:01 +03:00
[GH-ISSUE #22] Request: Mandatory headings #16
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#16
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 @originalfoo on GitHub (Jun 18, 2016).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/22
Would it be possible to get a rule which enforces mandatory headings in a file?
For example, in documentation, there may be a style guide that requires the docs to have a specific set of headers.
The rule would take an array of strings, each string being a header that must exist in the file. The rule is violated if any of the headers in the array are not found in the file.
If possible, an optional boolean flag (false by default) would make the rule ensure that the headers are in the same order as those specified in the array.
@originalfoo commented on GitHub (Jun 18, 2016):
Example rule config:
The
#at start of strings denotes heading level - if present, the rule also validates that the heading, if found, is using the specified heading level.@DavidAnson commented on GitHub (Jun 18, 2016):
Seems reasonable, I like the design you've proposed. I'll look into this soon when I work through the backlog of
markdownlintissues. Thanks!@originalfoo commented on GitHub (Jun 18, 2016):
Here's a rough code draft if it's any use:
@DavidAnson commented on GitHub (Jun 21, 2016):
Nice, thanks! I will think about the algorithm independently as well. Also, what about another option
only=trueto fail the check if some other header is present?@originalfoo commented on GitHub (Jun 21, 2016):
Yes, good idea!
@DavidAnson commented on GitHub (Jun 21, 2016):
Thinking about this in the context of something like Wikipedia, I'm not sure what we have so far is expressive enough. So I am playing with the idea of casting this as a regular expression scenario. Imagine if the list of headers was presented as a string similar to how you propose and then the rule runs a regular expression against it.
Example: # Intro\n# Body\n# Summary\n
This makes it possible to enforce simple rules like "exactly these three headers in this order", more complicated ones like "this set of 10 headers, 5 of which are optional", more generic ones like "only level one and two headings", or even stuff like "API documentation where each method is a level two heading followed by any number of level three headings for each parameter".
The concern I have with this is that violations will be harder to identify because there won't be meaningful line numbers. However, in order to cover the kinds of scenarios I see this being used for (GitHub Readme, OSS documentation), I'm thinking such a level of expressivity is necessary - and would be difficult to implement manually.
@originalfoo commented on GitHub (Jun 21, 2016):
I agree the regex approach would be a big improvement in terms of flexibility, so long as your docs provide decent examples for scenarios you cited - regex are often difficult to comprehend for people involved in maintaining documentation and style guides, etc.
Regarding the inability to report violation line numbers, I think that is an acceptable tradeoff in the specific case of headings - because headings are simple to spot in documents. Alternatively, is there some way to pick apart the regex and at least state which headings are missing or incorrect (even if we can't determine line number)?
At the very least, we would need the ability to define a custom error message to point people at style guide in case of violations.
@DavidAnson commented on GitHub (Jul 3, 2016):
I went back and forth on this implementation a bunch. :| What ended up seeming like a reasonable first attempt is what you see in the associated commit. I think that it addresses the common scenarios clearly and in a way a beginner could use (using your syntax, with some changes). I will add more detailed custom error information as part of #23. I may still add
RegExpsupport. If you feel this is not sufficient to start with, please let me know!@sagiegurari commented on GitHub (Jul 4, 2016):
this is a really good feature.
when will this be published to npm?
@DavidAnson commented on GitHub (Jul 5, 2016):
I published version
0.2.0a few minutes ago. :)@sagiegurari commented on GitHub (Jul 6, 2016):
thanks
@originalfoo commented on GitHub (Aug 22, 2016):
Been away due to RL issues, but great to see this feature implemented - many thanks!