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

@ -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_*";