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

@ -19,7 +19,8 @@ const inlineCommentStartRe =
module.exports.inlineCommentStartRe = inlineCommentStartRe;
// Regular expression for matching HTML elements
module.exports.htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g;
const htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g;
module.exports.htmlElementRe = htmlElementRe;
// Regular expressions for range matching
module.exports.bareUrlRe = /(?:http|ftp)s?:\/\/[^\s\]"']*(?:\/|[^\s\]"'\W])/ig;
@ -603,6 +604,25 @@ module.exports.codeBlockAndSpanRanges = (params, lineMetadata) => {
return exclusions;
};
/**
* Returns an array of HTML element ranges.
*
* @param {Object} params RuleParams instance.
* @param {Object} lineMetadata Line metadata object.
* @returns {number[][]} Array of ranges (lineIndex, columnIndex, length).
*/
module.exports.htmlElementRanges = (params, lineMetadata) => {
const exclusions = [];
forEachLine(lineMetadata, (line, lineIndex, inCode) => {
let match = null;
// eslint-disable-next-line no-unmodified-loop-condition
while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) {
exclusions.push([ lineIndex, match.index, match[0].length ]);
}
});
return exclusions;
};
/**
* Determines whether the specified range overlaps another range.
*