2018-02-15 21:35:58 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2019-04-13 11:27:28 -07:00
|
|
|
const { forEachLine, getLineMetadata } = require("markdownlint-rule-helpers");
|
2019-04-13 11:18:57 -07:00
|
|
|
|
2018-02-15 21:35:58 -08:00
|
|
|
module.exports = {
|
|
|
|
|
"names": [ "every-n-lines" ],
|
|
|
|
|
"description": "Rule that reports an error every N lines",
|
|
|
|
|
"tags": [ "test" ],
|
2019-04-13 11:18:57 -07:00
|
|
|
"function": (params, onError) => {
|
2018-04-27 22:05:34 -07:00
|
|
|
const n = params.config.n || 2;
|
2019-04-13 11:18:57 -07:00
|
|
|
forEachLine(getLineMetadata(params), (line, lineIndex) => {
|
2018-04-27 22:05:34 -07:00
|
|
|
const lineNumber = lineIndex + 1;
|
2018-02-15 21:35:58 -08:00
|
|
|
if ((lineNumber % n) === 0) {
|
|
|
|
|
onError({
|
|
|
|
|
"lineNumber": lineNumber,
|
2018-02-27 21:14:02 -08:00
|
|
|
"detail": "Line number " + lineNumber
|
2018-02-15 21:35:58 -08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|