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
|
@ -3,9 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
const shared = require("./shared");
|
||||
const {
|
||||
addErrorDetailIf, filterTokens, forEachHeading, forEachLine, rangeFromRegExp
|
||||
} = shared;
|
||||
const { addErrorDetailIf, filterTokens, forEachHeading, forEachLine,
|
||||
includesSorted, rangeFromRegExp } = shared;
|
||||
|
||||
const longLineRePrefix = "^(.{";
|
||||
const longLineRePostfix = "})(.*\\s.*)$";
|
||||
|
@ -59,13 +58,13 @@ module.exports = {
|
|||
});
|
||||
forEachLine((line, lineIndex, inCode, onFence, inTable) => {
|
||||
const lineNumber = lineIndex + 1;
|
||||
const isHeading = headingLineNumbers.indexOf(lineNumber) >= 0;
|
||||
const isHeading = includesSorted(headingLineNumbers, lineNumber);
|
||||
const length = isHeading ? headingLineLength : lineLength;
|
||||
const lengthRe = isHeading ? longHeadingLineRe : longLineRe;
|
||||
if ((includeCodeBlocks || !inCode) &&
|
||||
(includeTables || !inTable) &&
|
||||
(includeHeadings || !isHeading) &&
|
||||
(linkOnlyLineNumbers.indexOf(lineNumber) < 0) &&
|
||||
!includesSorted(linkOnlyLineNumbers, lineNumber) &&
|
||||
lengthRe.test(line) &&
|
||||
!labelRe.test(line)) {
|
||||
addErrorDetailIf(onError, lineNumber, length, line.length,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue