mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-02-03 20:41:47 +01:00
Cache results of inlineCodeSpanRanges for use by MD011/MD044.
This commit is contained in:
parent
706f48bd25
commit
7d40926367
6 changed files with 56 additions and 39 deletions
31
lib/cache.js
31
lib/cache.js
|
|
@ -2,14 +2,6 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
let lineMetadata = null;
|
||||
module.exports.lineMetadata = (value) => {
|
||||
if (value) {
|
||||
lineMetadata = value;
|
||||
}
|
||||
return lineMetadata;
|
||||
};
|
||||
|
||||
let flattenedLists = null;
|
||||
module.exports.flattenedLists = (value) => {
|
||||
if (value) {
|
||||
|
|
@ -18,7 +10,24 @@ module.exports.flattenedLists = (value) => {
|
|||
return flattenedLists;
|
||||
};
|
||||
|
||||
module.exports.clear = () => {
|
||||
lineMetadata = null;
|
||||
flattenedLists = null;
|
||||
let inlineCodeSpanRanges = null;
|
||||
module.exports.inlineCodeSpanRanges = (value) => {
|
||||
if (value) {
|
||||
inlineCodeSpanRanges = value;
|
||||
}
|
||||
return inlineCodeSpanRanges;
|
||||
};
|
||||
|
||||
let lineMetadata = null;
|
||||
module.exports.lineMetadata = (value) => {
|
||||
if (value) {
|
||||
lineMetadata = value;
|
||||
}
|
||||
return lineMetadata;
|
||||
};
|
||||
|
||||
module.exports.clear = () => {
|
||||
flattenedLists = null;
|
||||
inlineCodeSpanRanges = null;
|
||||
lineMetadata = null;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -516,7 +516,8 @@ function lintContent(
|
|||
frontMatterLines
|
||||
};
|
||||
cache.lineMetadata(helpers.getLineMetadata(params));
|
||||
cache.flattenedLists(helpers.flattenLists(params));
|
||||
cache.flattenedLists(helpers.flattenLists(params.tokens));
|
||||
cache.inlineCodeSpanRanges(helpers.inlineCodeSpanRanges(params.lines));
|
||||
// Function to run for each rule
|
||||
const result = (resultVersion === 0) ? {} : [];
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addError, forEachLine, inlineCodeSpanRanges, overlapsAnyRange } =
|
||||
require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
const { addError, forEachLine, overlapsAnyRange } = require("../helpers");
|
||||
const { inlineCodeSpanRanges, lineMetadata } = require("./cache");
|
||||
|
||||
const reversedLinkRe =
|
||||
/(?<![\\\]])\(([^)]+)(?<!\\)\)\[([^\]^][^\]]*)(?<!\\)](?!\()/g;
|
||||
|
|
@ -14,7 +13,7 @@ module.exports = {
|
|||
"description": "Reversed link syntax",
|
||||
"tags": [ "links" ],
|
||||
"function": function MD011(params, onError) {
|
||||
const exclusions = inlineCodeSpanRanges(params.lines);
|
||||
const exclusions = inlineCodeSpanRanges();
|
||||
forEachLine(lineMetadata(), (line, lineIndex, inCode, onFence) => {
|
||||
if (!inCode && !onFence) {
|
||||
let match = null;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@
|
|||
"use strict";
|
||||
|
||||
const { addErrorDetailIf, bareUrlRe, escapeForRegExp, forEachLine,
|
||||
inlineCodeSpanRanges, overlapsAnyRange, linkRe, linkReferenceRe } =
|
||||
require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
overlapsAnyRange, linkRe, linkReferenceRe } = require("../helpers");
|
||||
const { inlineCodeSpanRanges, lineMetadata } = require("./cache");
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD044", "proper-names" ],
|
||||
|
|
@ -37,7 +36,7 @@ module.exports = {
|
|||
}
|
||||
});
|
||||
if (!includeCodeBlocks) {
|
||||
exclusions.push(...inlineCodeSpanRanges(params.lines));
|
||||
exclusions.push(...inlineCodeSpanRanges());
|
||||
}
|
||||
for (const name of names) {
|
||||
const escapedName = escapeForRegExp(name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue