mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add includesSorted function, use for faster searches of sorted arrays.
This commit is contained in:
parent
d7c0d195d7
commit
9b9532e163
8 changed files with 86 additions and 50 deletions
16
lib/md009.js
16
lib/md009.js
|
@ -3,6 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
const shared = require("./shared");
|
||||
const { addError, filterTokens, forEachLine, includesSorted, rangeFromRegExp,
|
||||
trimRight } = shared;
|
||||
|
||||
const trailingSpaceRe = /\s+$/;
|
||||
|
||||
|
@ -20,24 +22,24 @@ module.exports = {
|
|||
(listItemEmptyLines === undefined) ? false : !!listItemEmptyLines;
|
||||
const listItemLineNumbers = [];
|
||||
if (allowListItemEmptyLines) {
|
||||
shared.filterTokens(params, "list_item_open", function forToken(token) {
|
||||
filterTokens(params, "list_item_open", (token) => {
|
||||
for (let i = token.map[0]; i < token.map[1]; i++) {
|
||||
listItemLineNumbers.push(i + 1);
|
||||
}
|
||||
});
|
||||
listItemLineNumbers.sort((a, b) => a - b);
|
||||
}
|
||||
const expected = (brSpaces < 2) ? 0 : brSpaces;
|
||||
shared.forEachLine(function forLine(line, lineIndex) {
|
||||
forEachLine((line, lineIndex) => {
|
||||
const lineNumber = lineIndex + 1;
|
||||
if (trailingSpaceRe.test(line) &&
|
||||
(listItemLineNumbers.indexOf(lineNumber) === -1)) {
|
||||
const actual = line.length - shared.trimRight(line).length;
|
||||
!includesSorted(listItemLineNumbers, lineNumber)) {
|
||||
const actual = line.length - trimRight(line).length;
|
||||
if (expected !== actual) {
|
||||
shared.addError(onError, lineNumber,
|
||||
addError(onError, lineNumber,
|
||||
"Expected: " + (expected === 0 ? "" : "0 or ") +
|
||||
expected + "; Actual: " + actual,
|
||||
null,
|
||||
shared.rangeFromRegExp(line, trailingSpaceRe));
|
||||
null, rangeFromRegExp(line, trailingSpaceRe));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue