Update MD044/proper-names to add html_elements parameter (fixes #435).

This commit is contained in:
David Anson 2022-04-25 21:50:33 -07:00
parent 8afec14376
commit 0f845e9ba1
15 changed files with 186 additions and 14 deletions

View file

@ -18,6 +18,14 @@ module.exports.flattenedLists = (value) => {
return flattenedLists;
};
let htmlElementRanges = null;
module.exports.htmlElementRanges = (value) => {
if (value) {
htmlElementRanges = value;
}
return htmlElementRanges;
};
let lineMetadata = null;
module.exports.lineMetadata = (value) => {
if (value) {
@ -29,5 +37,6 @@ module.exports.lineMetadata = (value) => {
module.exports.clear = () => {
codeBlockAndSpanRanges = null;
flattenedLists = null;
htmlElementRanges = null;
lineMetadata = null;
};

View file

@ -495,11 +495,15 @@ function lintContent(
lines,
frontMatterLines
});
cache.lineMetadata(helpers.getLineMetadata(paramsBase));
cache.flattenedLists(helpers.flattenLists(paramsBase.tokens));
const lineMetadata = helpers.getLineMetadata(paramsBase);
cache.lineMetadata(lineMetadata);
cache.codeBlockAndSpanRanges(
helpers.codeBlockAndSpanRanges(paramsBase, cache.lineMetadata())
helpers.codeBlockAndSpanRanges(paramsBase, lineMetadata)
);
cache.htmlElementRanges(
helpers.htmlElementRanges(paramsBase, lineMetadata)
);
cache.flattenedLists(helpers.flattenLists(paramsBase.tokens));
// Function to run for each rule
let results = [];
// eslint-disable-next-line jsdoc/require-jsdoc

View file

@ -4,7 +4,8 @@
const { addErrorDetailIf, bareUrlRe, escapeForRegExp, forEachLine,
forEachLink, overlapsAnyRange, linkReferenceRe } = require("../helpers");
const { codeBlockAndSpanRanges, lineMetadata } = require("./cache");
const { codeBlockAndSpanRanges, htmlElementRanges, lineMetadata } =
require("./cache");
module.exports = {
"names": [ "MD044", "proper-names" ],
@ -15,7 +16,11 @@ module.exports = {
names = Array.isArray(names) ? names : [];
names.sort((a, b) => (b.length - a.length) || a.localeCompare(b));
const codeBlocks = params.config.code_blocks;
const includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
const includeCodeBlocks =
(codeBlocks === undefined) ? true : !!codeBlocks;
const htmlElements = params.config.html_elements;
const includeHtmlElements =
(htmlElements === undefined) ? true : !!htmlElements;
const exclusions = [];
forEachLine(lineMetadata(), (line, lineIndex) => {
if (linkReferenceRe.test(line)) {
@ -37,6 +42,9 @@ module.exports = {
if (!includeCodeBlocks) {
exclusions.push(...codeBlockAndSpanRanges());
}
if (!includeHtmlElements) {
exclusions.push(...htmlElementRanges());
}
for (const name of names) {
const escapedName = escapeForRegExp(name);
const startNamePattern = /^\W/.test(name) ? "" : "\\b_*";