Fix issue with MD044/proper-names where stateful RegExp could fail to match bare URLs, remove unnecessary use of bareUrlRe by MD033/no-inline-html.

This commit is contained in:
David Anson 2019-10-21 22:17:26 -07:00
parent 57c661700a
commit 31ffe52f0f
4 changed files with 51 additions and 5 deletions

View file

@ -2,8 +2,7 @@
"use strict"; "use strict";
const { addError, bareUrlRe, forEachLine, unescapeMarkdown } = const { addError, forEachLine, unescapeMarkdown } = require("../helpers");
require("../helpers");
const { lineMetadata } = require("./cache"); const { lineMetadata } = require("./cache");
const htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g; const htmlElementRe = /<(([A-Za-z][A-Za-z0-9-]*)(?:\s[^>]*)?)\/?>/g;
@ -24,10 +23,10 @@ module.exports = {
forEachLine(lineMetadata(), (line, lineIndex, inCode) => { forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
let match = null; let match = null;
// eslint-disable-next-line no-unmodified-loop-condition // eslint-disable-next-line no-unmodified-loop-condition
while (!inCode && (match = htmlElementRe.exec(line))) { while (!inCode && ((match = htmlElementRe.exec(line)) !== null)) {
const [ tag, content, element ] = match; const [ tag, content, element ] = match;
if (!allowedElements.includes(element.toLowerCase()) && if (!allowedElements.includes(element.toLowerCase()) &&
!tag.endsWith("\\>") && !bareUrlRe.test(content) && !tag.endsWith("\\>") &&
!emailAddressRe.test(content)) { !emailAddressRe.test(content)) {
const prefix = line.substring(0, match.index); const prefix = line.substring(0, match.index);
if (!linkDestinationRe.test(prefix) && !inlineCodeRe.test(prefix)) { if (!linkDestinationRe.test(prefix) && !inlineCodeRe.test(prefix)) {

View file

@ -24,7 +24,7 @@ module.exports = {
let match = null; let match = null;
while ((match = anyNameRe.exec(line)) !== null) { while ((match = anyNameRe.exec(line)) !== null) {
const fullMatch = match[0]; const fullMatch = match[0];
if (!bareUrlRe.test(fullMatch)) { if (fullMatch.search(bareUrlRe) === -1) {
const wordMatch = fullMatch const wordMatch = fullMatch
.replace(/^\W*/, "").replace(/\W*$/, ""); .replace(/^\W*/, "").replace(/\W*$/, "");
if (!names.includes(wordMatch)) { if (!names.includes(wordMatch)) {

View file

@ -0,0 +1,14 @@
{
"default": true,
"proper-names": {
"names": [
"HTTPS",
"EXAMPLE",
"COM",
"DIRECTORY",
"FILE"
]
},
"no-bare-urls": false,
"code-block-style": false
}

33
test/proper-names-urls.md Normal file
View file

@ -0,0 +1,33 @@
# Proper Names in URLs
Text https text {MD044}
Text example text {MD044}
Text com text {MD044}
Text directory text {MD044}
Text file text {MD044}
Text HTTPS EXAMPLE COM DIRECTORY FILE text
> The following lines are deliberately duplicated
Text https://example.com/directory/file text
Text https://example.com/directory/file text
Text <https://example.com/directory/file> text
Text <https://example.com/directory/file> text
Text [https://example.com/directory/file](https://example.com/directory/file) text
Text [https://example.com/directory/file](https://example.com/directory/file) text
Text `https://example.com/directory/file` text
Text `https://example.com/directory/file` text
```text
Text https://example.com/directory/file text
Text https://example.com/directory/file text
```
Text https://example.com/directory/file text
Text https://example.com/directory/file text