mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Refactor to remove forEachLine and getLineMetadata helpers, reimplement MD012/MD018/MD020/MD031 using micromark tokens.
This commit is contained in:
parent
7efc2605b1
commit
c8fd9eb4b3
13 changed files with 198 additions and 308 deletions
|
|
@ -62,5 +62,5 @@ Text
|
|||
|
||||
1. Text
|
||||
```shell
|
||||
fence {MD031:64} {MD031:65} {MD032:65} {MD040:66}
|
||||
fence {MD031:64} {MD031:65} {MD031:66} {MD032:65} {MD040:66}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -2,24 +2,19 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { forEachLine, getLineMetadata } = require("../../helpers");
|
||||
|
||||
/** @type import("../../lib/markdownlint").Rule */
|
||||
module.exports = {
|
||||
"names": [ "every-n-lines" ],
|
||||
"description": "Rule that reports an error every N lines",
|
||||
"tags": [ "test" ],
|
||||
"parser": "markdownit",
|
||||
"parser": "none",
|
||||
"function": (params, onError) => {
|
||||
const n = params.config.n || 2;
|
||||
forEachLine(getLineMetadata(params), (line, lineIndex) => {
|
||||
const lineNumber = lineIndex + 1;
|
||||
if ((lineNumber % n) === 0) {
|
||||
onError({
|
||||
"lineNumber": lineNumber,
|
||||
"detail": "Line number " + lineNumber
|
||||
});
|
||||
}
|
||||
});
|
||||
for (let lineNumber = n; lineNumber <= params.lines.length; lineNumber += n) {
|
||||
onError({
|
||||
"lineNumber": lineNumber,
|
||||
"detail": "Line number " + lineNumber
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35694,6 +35694,23 @@ Generated by [AVA](https://avajs.dev).
|
|||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '```',
|
||||
errorDetail: null,
|
||||
errorRange: null,
|
||||
fixInfo: {
|
||||
insertText: `␊
|
||||
`,
|
||||
lineNumber: 66,
|
||||
},
|
||||
lineNumber: 66,
|
||||
ruleDescription: 'Fenced code blocks should be surrounded by blank lines',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md031.md',
|
||||
ruleNames: [
|
||||
'MD031',
|
||||
'blanks-around-fences',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: 'fence {MD031:64} {MD031:65} {M...',
|
||||
errorDetail: null,
|
||||
|
|
@ -35798,7 +35815,7 @@ Generated by [AVA](https://avajs.dev).
|
|||
1. Text␊
|
||||
␊
|
||||
\`\`\`shell␊
|
||||
fence {MD031:64} {MD031:65} {MD032:65} {MD040:66}␊
|
||||
fence {MD031:64} {MD031:65} {MD031:66} {MD032:65} {MD040:66}␊
|
||||
␊
|
||||
\`\`\`␊
|
||||
`,
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue