mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01: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
11
lib/md024.js
11
lib/md024.js
|
|
@ -3,6 +3,7 @@
|
|||
"use strict";
|
||||
|
||||
const shared = require("./shared");
|
||||
const { addErrorContext, forEachHeading } = shared;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD024", "no-duplicate-heading", "no-duplicate-header" ],
|
||||
|
|
@ -14,7 +15,7 @@ module.exports = {
|
|||
const knownContents = [ null, [] ];
|
||||
let lastLevel = 1;
|
||||
let knownContent = knownContents[lastLevel];
|
||||
shared.forEachHeading(params, function forHeading(heading, content) {
|
||||
forEachHeading(params, (heading, content) => {
|
||||
if (siblingsOnly) {
|
||||
const newLevel = heading.tag.slice(1);
|
||||
while (lastLevel < newLevel) {
|
||||
|
|
@ -27,11 +28,11 @@ module.exports = {
|
|||
}
|
||||
knownContent = knownContents[newLevel];
|
||||
}
|
||||
if (knownContent.indexOf(content) === -1) {
|
||||
knownContent.push(content);
|
||||
} else {
|
||||
shared.addErrorContext(onError, heading.lineNumber,
|
||||
if (knownContent.includes(content)) {
|
||||
addErrorContext(onError, heading.lineNumber,
|
||||
heading.line.trim());
|
||||
} else {
|
||||
knownContent.push(content);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue