Update MD034/no-bare-urls to handle more scenarios, simplify slightly, replace blanket MD034 suppression for https://github.com/mdn/content with specific (valid) issues (refs #607).

This commit is contained in:
David Anson 2022-12-15 14:27:07 -08:00
parent 2e2937081e
commit d352d4ece1
6 changed files with 103 additions and 18 deletions

View file

@ -32,7 +32,11 @@ As is <a href="https://example.com/info.htm">https://example.com/info.htm text</
This is not a bare [link]( https://example.com ).
URLs in HTML are not bare:
Nor is [link](https://example.com/path-with(parens)).
Or <https://example.com/path-with(parens)>.
URLs in HTML attributes are not bare:
<element-name first-attribute=" https://example.com/first " second-attribute=" https://example.com/second ">
Text
@ -42,8 +46,27 @@ URLs in HTML are not bare:
first-attribute=" https://example.com/first "
second-attribute=" https://example.com/second "></element-name>
URLs surrounded by HTML tags are not bare:
Not <code>https://example.com</code> bare.
Not <pre>https://example.com</pre> bare.
<p>
Not bare due to being in an HTML block:
https://example.com
<code>https://example.com</code>
<pre>https://example.com</pre>
</p>
URLs in link and image text are not bare:
Text [link to https://example.com site](https://example.com) text.
Image ![for https://example.com site](https://example.com) text.
URLs may end with a dash: https://example.com#heading- {MD034}
... when explicit: <https://example.com#heading->
... when embedded: <code>https://example.com#heading-</code>

View file

@ -147,7 +147,11 @@ test("https://github.com/mdn/content", (t) => {
const rootDir = "./test-repos/mdn-content";
const globPatterns = [ join(rootDir, "**/*.md") ];
const configPath = join(rootDir, ".markdownlint-cli2.jsonc");
const ignoreRes = [ /^[^:]+: \d+: MD034\/.*$\r?\n?/gm ];
const ignoreRes = [
/test-repos\/mdn-content\/files\/en-us\/mdn\/community\/pull_requests\/index.md: \d+: MD034\/.*$\r?\n?/gm,
/test-repos\/mdn-content\/files\/en-us\/web\/api\/customelementregistry\/whendefined\/index.md: \d+: MD034\/.*$\r?\n?/gm,
/test-repos\/mdn-content\/files\/en-us\/web\/api\/css_painting_api\/guide\/index.md: \d+: MD034\/.*$\r?\n?/gm
];
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
});

View file

@ -2966,6 +2966,26 @@ Generated by [AVA](https://avajs.dev).
'no-bare-urls',
],
},
{
errorContext: 'https://example.com#heading-',
errorDetail: null,
errorRange: [
27,
28,
],
fixInfo: {
deleteCount: 28,
editColumn: 27,
insertText: '<https://example.com#heading->',
},
lineNumber: 68,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
],
fixed: `# Detailed Results Bare URLs␊
@ -3001,7 +3021,11 @@ Generated by [AVA](https://avajs.dev).
This is not a bare [link]( https://example.com ).␊
URLs in HTML are not bare:␊
Nor is [link](https://example.com/path-with(parens)).␊
Or <https://example.com/path-with(parens)>.␊
URLs in HTML attributes are not bare:␊
<element-name first-attribute=" https://example.com/first " second-attribute=" https://example.com/second ">
Text␊
@ -3011,11 +3035,30 @@ Generated by [AVA](https://avajs.dev).
first-attribute=" https://example.com/first "␊
second-attribute=" https://example.com/second "></element-name>
URLs surrounded by HTML tags are not bare:␊
Not <code>https://example.com</code> bare.␊
Not <pre>https://example.com</pre> bare.␊
<p>
Not bare due to being in an HTML block:␊
https://example.com␊
<code>https://example.com</code>
<pre>https://example.com</pre>
</p>
URLs in link and image text are not bare:␊
Text [link to https://example.com site](https://example.com) text.␊
Image ![for https://example.com site](https://example.com) text.␊
URLs may end with a dash: <https://example.com#heading-> {MD034}␊
... when explicit: <https://example.com#heading->
... when embedded: <code>https://example.com#heading-</code>
`,
}