Reimplement MD034/no-bare-urls using micromark tokens (fixes #707).

This commit is contained in:
David Anson 2023-02-05 16:58:06 -08:00
parent 64159fa456
commit b990b3ea77
22 changed files with 1495 additions and 947 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,36 +1,29 @@
This rule is triggered whenever a URL is given that isn't surrounded by angle
brackets:
This rule is triggered whenever a URL or email address appears without
surrounding angle brackets:
```markdown
For more information, see https://www.example.com/.
For more info, visit https://www.example.com/ or email user@example.com.
```
To fix this, add angle brackets around the URL:
To fix this, add angle brackets around the URL or email address:
```markdown
For more information, see <https://www.example.com/>.
For more info, visit <https://www.example.com/> or email <user@example.com>.
```
Note: To use a bare URL without it being converted into a link, enclose it in
a code block, otherwise in some Markdown parsers it *will* be converted:
Note: To include a bare URL or email without it being converted into a link,
wrap it in a code span:
```markdown
`https://www.example.com`
Not a clickable link: `https://www.example.com`
```
Note: The following scenario does *not* trigger this rule to avoid conflicts
with `MD011`/`no-reversed-links`:
Note: The following scenario does not trigger this rule because it could be a
valid shortcut link:
```markdown
[https://www.example.com]
```
The use of quotes around a bare link will *not* trigger this rule, either:
```markdown
"https://www.example.com"
'https://www.example.com'
```
Rationale: Without angle brackets, the URL isn't converted into a link by many
Markdown parsers.
Rationale: Without angle brackets, a bare URL or email isn't converted into a
link by some Markdown parsers.

View file

@ -1410,42 +1410,35 @@ Aliases: `no-bare-urls`
Fixable: Some violations can be fixed by tooling
This rule is triggered whenever a URL is given that isn't surrounded by angle
brackets:
This rule is triggered whenever a URL or email address appears without
surrounding angle brackets:
```markdown
For more information, see https://www.example.com/.
For more info, visit https://www.example.com/ or email user@example.com.
```
To fix this, add angle brackets around the URL:
To fix this, add angle brackets around the URL or email address:
```markdown
For more information, see <https://www.example.com/>.
For more info, visit <https://www.example.com/> or email <user@example.com>.
```
Note: To use a bare URL without it being converted into a link, enclose it in
a code block, otherwise in some Markdown parsers it *will* be converted:
Note: To include a bare URL or email without it being converted into a link,
wrap it in a code span:
```markdown
`https://www.example.com`
Not a clickable link: `https://www.example.com`
```
Note: The following scenario does *not* trigger this rule to avoid conflicts
with `MD011`/`no-reversed-links`:
Note: The following scenario does not trigger this rule because it could be a
valid shortcut link:
```markdown
[https://www.example.com]
```
The use of quotes around a bare link will *not* trigger this rule, either:
```markdown
"https://www.example.com"
'https://www.example.com'
```
Rationale: Without angle brackets, the URL isn't converted into a link by many
Markdown parsers.
Rationale: Without angle brackets, a bare URL or email isn't converted into a
link by some Markdown parsers.
<a name="md035"></a>

View file

@ -6,39 +6,32 @@ Aliases: `no-bare-urls`
Fixable: Some violations can be fixed by tooling
This rule is triggered whenever a URL is given that isn't surrounded by angle
brackets:
This rule is triggered whenever a URL or email address appears without
surrounding angle brackets:
```markdown
For more information, see https://www.example.com/.
For more info, visit https://www.example.com/ or email user@example.com.
```
To fix this, add angle brackets around the URL:
To fix this, add angle brackets around the URL or email address:
```markdown
For more information, see <https://www.example.com/>.
For more info, visit <https://www.example.com/> or email <user@example.com>.
```
Note: To use a bare URL without it being converted into a link, enclose it in
a code block, otherwise in some Markdown parsers it *will* be converted:
Note: To include a bare URL or email without it being converted into a link,
wrap it in a code span:
```markdown
`https://www.example.com`
Not a clickable link: `https://www.example.com`
```
Note: The following scenario does *not* trigger this rule to avoid conflicts
with `MD011`/`no-reversed-links`:
Note: The following scenario does not trigger this rule because it could be a
valid shortcut link:
```markdown
[https://www.example.com]
```
The use of quotes around a bare link will *not* trigger this rule, either:
```markdown
"https://www.example.com"
'https://www.example.com'
```
Rationale: Without angle brackets, the URL isn't converted into a link by many
Markdown parsers.
Rationale: Without angle brackets, a bare URL or email isn't converted into a
link by some Markdown parsers.

View file

@ -816,12 +816,14 @@ function getReferenceLinkImageData(params) {
const filteredTokens =
micromark.filterByTypes(
params.parsers.micromark.tokens,
// definitionLineIndices
"definition", "gfmFootnoteDefinition",
// definitions and definitionLineIndices
"definitionLabelString", "gfmFootnoteDefinitionLabelString",
// references and shortcuts
"gfmFootnoteCall", "image", "link"
[
// definitionLineIndices
"definition", "gfmFootnoteDefinition",
// definitions and definitionLineIndices
"definitionLabelString", "gfmFootnoteDefinitionLabelString",
// references and shortcuts
"gfmFootnoteCall", "image", "link"
]
);
for (const token of filteredTokens) {
let labelPrefix = "";

View file

@ -5,7 +5,8 @@
/* eslint-disable n/no-unpublished-require */
// @ts-ignore
const { gfmFootnote, parse, postprocess, preprocess } = require("../micromark/micromark.cjs");
const { gfmAutolinkLiteral, gfmFootnote, parse, postprocess, preprocess } =
require("../micromark/micromark.cjs");
/**
* Markdown token.
@ -31,7 +32,7 @@ function micromarkParse(markdown, options = {}) {
// Customize options object to add useful extensions
options.extensions ||= [];
options.extensions.push(gfmFootnote());
options.extensions.push(gfmAutolinkLiteral, gfmFootnote());
// Use micromark to parse document into Events
const encoding = undefined;
@ -89,18 +90,20 @@ function micromarkParse(markdown, options = {}) {
* Filter a list of Micromark tokens by predicate.
*
* @param {Token[]} tokens Micromark tokens.
* @param {Function} predicate Filter predicate.
* @param {Function} allowed Allowed token predicate.
* @param {Function} [transform] Transform token list predicate.
* @returns {Token[]} Filtered tokens.
*/
function filterByPredicate(tokens, predicate) {
function filterByPredicate(tokens, allowed, transform) {
const result = [];
const pending = [ ...tokens ];
let token = null;
while ((token = pending.shift())) {
if (predicate(token)) {
if (allowed(token)) {
result.push(token);
}
pending.unshift(...token.tokens);
const transformed = transform ? transform(token.tokens) : token.tokens;
pending.unshift(...transformed);
}
return result;
}
@ -109,11 +112,36 @@ function filterByPredicate(tokens, predicate) {
* Filter a list of Micromark tokens by type.
*
* @param {Token[]} tokens Micromark tokens.
* @param {string[]} types Types to allow.
* @param {string[]} allowed Types to allow.
* @returns {Token[]} Filtered tokens.
*/
function filterByTypes(tokens, ...types) {
return filterByPredicate(tokens, (token) => types.includes(token.type));
function filterByTypes(tokens, allowed) {
return filterByPredicate(
tokens,
(token) => allowed.includes(token.type)
);
}
/**
* Gets information about the tag in an HTML token.
*
* @param {Token} token Micromark token.
* @returns {Object | null} HTML tag information.
*/
function getHtmlTagInfo(token) {
const htmlTagNameRe = /^<([^!>][^/\s>]*)/;
if (token.type === "htmlText") {
const match = htmlTagNameRe.exec(token.text);
if (match) {
const name = match[1];
const close = name.startsWith("/");
return {
close,
"name": close ? name.slice(1) : name
}
}
}
return null;
}
/**
@ -153,9 +181,10 @@ function matchAndGetTokensByType(tokens, matchTypes, resultTypes) {
}
module.exports = {
"parse": micromarkParse,
filterByPredicate,
filterByTypes,
getHtmlTagInfo,
getTokenTextByType,
matchAndGetTokensByType,
"parse": micromarkParse
matchAndGetTokensByType
};

View file

@ -3,10 +3,10 @@
"use strict";
const { addError } = require("../helpers");
const { filterByTypes, parse } = require("../helpers/micromark.cjs");
const { filterByTypes, getHtmlTagInfo, parse } =
require("../helpers/micromark.cjs");
// eslint-disable-next-line regexp/optimal-quantifier-concatenation
const htmlTextRe = /^<([^!/\s>]+)[^\r\n>]*>?/;
const nextLinesRe = /[\r\n][\s\S]*$/;
module.exports = {
"names": [ "MD033", "no-inline-html" ],
@ -20,20 +20,25 @@ module.exports = {
let current = null;
while ((current = pending.shift())) {
const [ offset, tokens ] = current;
for (const token of filterByTypes(tokens, "htmlFlow", "htmlText")) {
for (const token of filterByTypes(tokens, [ "htmlFlow", "htmlText" ])) {
if (token.type === "htmlText") {
const match = htmlTextRe.exec(token.text);
if (match) {
const [ tag, element ] = match;
if (!allowedElements.includes(element.toLowerCase())) {
addError(
onError,
token.startLine + offset,
"Element: " + element,
undefined,
[ token.startColumn, tag.length ]
);
}
const htmlTagInfo = getHtmlTagInfo(token);
if (
htmlTagInfo &&
!htmlTagInfo.close &&
!allowedElements.includes(htmlTagInfo.name.toLowerCase())
) {
const range = [
token.startColumn,
token.text.replace(nextLinesRe, "").length
];
addError(
onError,
token.startLine + offset,
"Element: " + htmlTagInfo.name,
undefined,
range
);
}
} else {
// token.type === "htmlFlow"

View file

@ -2,85 +2,66 @@
"use strict";
const { addErrorContext, filterTokens, funcExpExec, urlFe, withinAnyRange } =
require("../helpers");
const { codeBlockAndSpanRanges, htmlElementRanges, referenceLinkImageData } =
require("./cache");
const htmlLinkRe = /<a(?:\s[^>]*)?>[^<>]*<\/a\s*>/gi;
const { addErrorContext } = require("../helpers");
const { filterByPredicate, getHtmlTagInfo } =
require("../helpers/micromark.cjs");
module.exports = {
"names": [ "MD034", "no-bare-urls" ],
"description": "Bare URL used",
"tags": [ "links", "url" ],
"function": function MD034(params, onError) {
const { lines } = params;
const codeExclusions = [
...codeBlockAndSpanRanges(),
...htmlElementRanges()
];
filterTokens(params, "html_block", (token) => {
for (let i = token.map[0]; i < token.map[1]; i++) {
codeExclusions.push([ i, 0, lines[i].length ]);
}
});
const { definitionLineIndices } = referenceLinkImageData();
for (const [ lineIndex, line ] of lines.entries()) {
if (definitionLineIndices[0] === lineIndex) {
definitionLineIndices.shift();
} else {
let match = null;
const lineExclusions = [];
while ((match = htmlLinkRe.exec(line)) !== null) {
lineExclusions.push([ lineIndex, match.index, match[0].length ]);
}
while ((match = funcExpExec(urlFe, line)) !== null) {
const [ bareUrl ] = match;
// @ts-ignore
const matchIndex = match.index;
const bareUrlLength = bareUrl.length;
const prefix = line.slice(0, matchIndex);
const postfix = line.slice(matchIndex + bareUrlLength);
if (
// Allow <...> to avoid reporting non-bare links
!(prefix.endsWith("<") && postfix.startsWith(">")) &&
// Allow >...</ to avoid reporting <code>...</code>
!(prefix.endsWith(">") && postfix.startsWith("</")) &&
// Allow "..." and '...' to allow quoting a bare link
!(prefix.endsWith("\"") && postfix.startsWith("\"")) &&
!(prefix.endsWith("'") && postfix.startsWith("'")) &&
// Allow ](... to avoid reporting Markdown-style links
!(/\]\(\s*$/.test(prefix)) &&
// Allow [...] to avoid MD011/no-reversed-links and nested links
!(/\[[^\]]*$/.test(prefix) && /^[^[]*\]/.test(postfix)) &&
!withinAnyRange(
lineExclusions, lineIndex, matchIndex, bareUrlLength
) &&
!withinAnyRange(
codeExclusions, lineIndex, matchIndex, bareUrlLength
)
) {
const range = [
matchIndex + 1,
bareUrlLength
];
const fixInfo = {
"editColumn": range[0],
"deleteCount": range[1],
"insertText": `<${bareUrl}>`
};
addErrorContext(
onError,
lineIndex + 1,
bareUrl,
null,
null,
range,
fixInfo
);
const literalAutolinks =
filterByPredicate(
params.parsers.micromark.tokens,
(token) => token.type === "literalAutolink",
(tokens) => {
const result = [];
for (let i = 0; i < tokens.length; i++) {
const openToken = tokens[i];
const openTagInfo = getHtmlTagInfo(openToken);
if (openTagInfo && !openTagInfo.close) {
let count = 1;
for (let j = i + 1; j < tokens.length; j++) {
const closeToken = tokens[j];
const closeTagInfo = getHtmlTagInfo(closeToken);
if (closeTagInfo && (openTagInfo.name === closeTagInfo.name)) {
if (closeTagInfo.close) {
count--;
if (count === 0) {
i = j;
break;
}
} else {
count++;
}
}
}
} else {
result.push(openToken);
}
}
}
}
return result;
});
for (const token of literalAutolinks) {
const range = [
token.startColumn,
token.endColumn - token.startColumn
];
const fixInfo = {
"editColumn": range[0],
"deleteCount": range[1],
"insertText": `<${token.text}>`
};
addErrorContext(
onError,
token.startLine,
token.text,
null,
null,
range,
fixInfo
);
}
}
};

View file

@ -2,6 +2,7 @@
/* eslint-disable n/file-extension-in-import */
export { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal";
export { gfmFootnote } from "micromark-extension-gfm-footnote";
export { parse } from "micromark/lib/parse";
export { postprocess } from "micromark/lib/postprocess";

View file

@ -20,6 +20,7 @@
},
"devDependencies": {
"micromark": "3.1.0",
"micromark-extension-gfm-autolink-literal": "1.0.3",
"micromark-extension-gfm-footnote": "1.0.4",
"webpack": "5.75.0",
"webpack-cli": "5.0.1"

View file

@ -85,6 +85,7 @@
"markdown-it-texmath": "1.0.0",
"markdownlint-rule-helpers": "0.18.0",
"micromark": "3.1.0",
"micromark-extension-gfm-autolink-literal": "1.0.3",
"micromark-extension-gfm-footnote": "1.0.4",
"npm-run-all": "4.1.5",
"strip-json-comments": "5.0.0",

28
test/bare-urls-in-html.md Normal file
View file

@ -0,0 +1,28 @@
# Bare URLs in HTML
<p>
https://example.com/pass
</p>
Text https://example.com/fail text. {MD034}
Text <code>https://example.com/pass</code> text.
Text <code>https://example.com/pass</code> text https://example.com/fail text. {MD034}
Text <code>https://example.com/pass</code> text https://example.com/fail text <code>https://example.com/pass</code> text. {MD034}
Text <em> text <strong>text</strong> https://example.com/pass </em> text.
Text <em> text <em>text</em> https://example.com/pass </em> text.
Text <em> text <em>text</em> text </em> https://example.com/fail text. {MD034}
Text <br> text https://example.com/fail <br> text. {MD034}
Text <br/> text https://example.com/fail <br/> text. {MD034}
<!-- markdownlint-configure-file {
"line-length": false,
"no-inline-html": false
} -->

View file

@ -70,3 +70,9 @@ 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>
Links with spaces inside angle brackets are okay: [blue jay](<https://en.wikipedia.org/wiki/Blue jay>)
Email addresses are treated similarly: user@example.com {MD034}
Angle brackets work the same for email: <user@example.com>

View file

@ -10,6 +10,7 @@ Every Markdown Syntax
Text *emphasized* **strong** ___emphasized+strong___.
Text `code` <strike>html</strike> <https://example.com/page>.
Text [link](https://example.com/page) [link][] [link] ![image][link].
Text https://example.com/page.
Hard
line break

View file

@ -116,3 +116,10 @@ Text
<details>
{MD033:116}
<custom-element attribute1="value1"
attribute2="value2" />
{MD033:120}
Text <!-- <commented-out html="tag"> --> text.

View file

@ -8,8 +8,6 @@ https://www.google.com/ {MD034}
hTtPs://gOoGlE.cOm/ {MD034}
ftp://user:password@ftp-server.example.com/dir/file.txt {MD034}
This link should be fine: <https://www.google.com/>
The following are allowed to avoid conflicts with MD011/no-reversed-links:
@ -17,13 +15,6 @@ The following are allowed to avoid conflicts with MD011/no-reversed-links:
[https://example.com]
[https://example.com/search?query=text]
The following are allowed to avoid conflicts with HTML-like syntax:
"https://example.com"
"https://example.com/search?query=text"
'https://example.com'
'https://example.com/search?query=text'
Other enclosures are not allowed:
(https://example.com) {MD034}

View file

@ -139,7 +139,30 @@ test("https://github.com/dotnet/docs", (t) => {
const rootDir = "./test-repos/dotnet-docs";
const globPatterns = [ join(rootDir, "**/*.md") ];
const configPath = join(rootDir, ".markdownlint-cli2.jsonc");
return lintTestRepo(t, globPatterns, configPath);
const ignoreRes = [
/^test-repos\/dotnet-docs\/docs\/core\/diagnostics\/dotnet-symbol\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/core\/install\/linux-package-mixup\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/core\/porting\/third-party-deps\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/configure-apps\/file-schema\/wcf\/issuedtokenparameters\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/configure-apps\/file-schema\/wcf\/servicemetadata\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/configure-apps\/file-schema\/wcf\/userprincipalname\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/extending\/how-to-compare-claims\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/extending\/overriding-the-identity-of-a-service-for-authentication\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/feature-details\/managing-claims-and-authorization-with-the-identity-model\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/feature-details\/message-filters\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/feature-details\/stand-alone-json-serialization\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/feature-details\/wcf-security-terminology\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/feature-details\/xml-and-ado-net-types-in-data-contracts\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/privacy-information\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/samples\/custom-channel-dispatcher\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/samples\/security-validation\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/wcf\/service-versioning\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/framework\/whats-new\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/orleans\/tutorials-and-samples\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/standard\/base-types\/regular-expression-source-generators\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/dotnet-docs\/docs\/standard\/serialization\/xml-schema-def-tool-gen\.md: \d+: MD034\/.*$\r?\n?/gm
];
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
});
test("https://github.com/electron/electron", (t) => {
@ -160,7 +183,10 @@ test("https://github.com/eslint/eslint", (t) => {
const rootDir = "./test-repos/eslint-eslint";
const globPatterns = [ join(rootDir, "docs/**/*.md") ];
const configPath = join(rootDir, ".markdownlint.yml");
const ignoreRes = [ /^[^:]+: \d+: MD051\/.*$\r?\n?/gm ];
const ignoreRes = [
/^[^:]+: \d+: MD051\/.*$\r?\n?/gm,
/^test-repos\/eslint-eslint\/docs\/src\/library\/link-card\.md: \d+: MD034\/.*$\r?\n?/gm
];
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
});
@ -168,7 +194,44 @@ 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");
return lintTestRepo(t, globPatterns, configPath);
const ignoreRes = [
/^test-repos\/mdn-content\/files\/en-us\/games\/techniques\/3d_on_the_web\/building_up_a_basic_demo_with_a-frame\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/techniques\/3d_on_the_web\/building_up_a_basic_demo_with_babylon.js\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/techniques\/3d_on_the_web\/building_up_a_basic_demo_with_playcanvas\/engine\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/techniques\/3d_on_the_web\/building_up_a_basic_demo_with_three.js\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/animations_and_tweens\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/bounce_off_the_walls\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/build_the_brick_field\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/buttons\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/collision_detection\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/extra_lives\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/game_over\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/initialize_the_framework\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/load_the_assets_and_print_them_on_screen\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/move_the_ball\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/physics\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/player_paddle_and_controls\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/randomizing_gameplay\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/scaling\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/the_score\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_phaser\/win_the_game\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/bounce_off_the_walls\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/build_the_brick_field\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/collision_detection\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/create_the_canvas_and_draw_on_it\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/finishing_up\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/game_over\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/mouse_controls\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/move_the_ball\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/paddle_and_keyboard_controls\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/games\/tutorials\/2d_breakout_game_pure_javascript\/track_the_score_and_win\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/learn\/server-side\/apache_configuration_htaccess\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/mozilla\/add-ons\/webextensions\/manifest.json\/content_security_policy\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/web\/api\/window\/window\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/web\/html\/element\/input\/email\/index\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mdn-content\/files\/en-us\/web\/http\/headers\/www-authenticate\/index\.md: \d+: MD034\/.*$\r?\n?/gm
];
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
});
test("https://github.com/mdn/translated-content", (t) => {
@ -211,6 +274,7 @@ test("https://github.com/mochajs/mocha", (t) => {
const configPath = join(rootDir, ".markdownlint.json");
const ignoreRes = [
/^[^:]+: \d+: MD051\/.*$\r?\n?/gm,
/^test-repos\/mochajs-mocha\/\.github\/CODE_OF_CONDUCT\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/mochajs-mocha\/docs\/index\.md: \d+: MD053\/.*$\r?\n?/gm
];
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
@ -220,14 +284,23 @@ test("https://github.com/pi-hole/docs", (t) => {
const rootDir = "./test-repos/pi-hole-docs";
const globPatterns = [ join(rootDir, "**/*.md") ];
const configPath = join(rootDir, ".markdownlint.json");
return lintTestRepo(t, globPatterns, configPath);
const ignoreRes = [ /^test-repos\/pi-hole-docs\/docs\/guides\/vpn\/wireguard\/route-everything\.md: \d+: MD034\/.*$\r?\n?/gm ];
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
});
test("https://github.com/v8/v8.dev", (t) => {
const rootDir = "./test-repos/v8-v8-dev";
const globPatterns = [ join(rootDir, "src/**/*.md") ];
const configPath = join(rootDir, ".markdownlint.json");
const ignoreRes = [ /^[^:]+: \d+: MD033\/.*\[Element: feature-support\].*$\r?\n?/gm ];
const ignoreRes = [
/^[^:]+: \d+: MD033\/.*\[Element: feature-support\].*$\r?\n?/gm,
/^test-repos\/v8-v8-dev\/src\/docs\/become-committer\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/v8-v8-dev\/src\/docs\/design-review-guidelines\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/v8-v8-dev\/src\/docs\/feature-launch-process\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/v8-v8-dev\/src\/docs\/official-support\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/v8-v8-dev\/src\/features\/import-assertions\.md: \d+: MD034\/.*$\r?\n?/gm,
/^test-repos\/v8-v8-dev\/src\/features\/private-brand-checks\.md: \d+: MD034\/.*$\r?\n?/gm
];
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
});

View file

@ -183,7 +183,7 @@ https://example.com/multi-line-label
[unique8]: https://example.com/unique8
[unique9]: https://example.com/unique9
[unique10]: https://example.com/unique10
[^1]: https://example.com/footnote
[^1]: https://example.com/footnote {MD034}
## Ignored Labels

File diff suppressed because it is too large Load diff

View file

@ -2800,6 +2800,164 @@ Generated by [AVA](https://avajs.dev).
`,
}
## bare-urls-in-html.md
> Snapshot 1
{
errors: [
{
errorContext: 'https://example.com/fail',
errorDetail: null,
errorRange: [
6,
24,
],
fixInfo: {
deleteCount: 24,
editColumn: 6,
insertText: '<https://example.com/fail>',
},
lineNumber: 7,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
{
errorContext: 'https://example.com/fail',
errorDetail: null,
errorRange: [
49,
24,
],
fixInfo: {
deleteCount: 24,
editColumn: 49,
insertText: '<https://example.com/fail>',
},
lineNumber: 11,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
{
errorContext: 'https://example.com/fail',
errorDetail: null,
errorRange: [
49,
24,
],
fixInfo: {
deleteCount: 24,
editColumn: 49,
insertText: '<https://example.com/fail>',
},
lineNumber: 13,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
{
errorContext: 'https://example.com/fail',
errorDetail: null,
errorRange: [
41,
24,
],
fixInfo: {
deleteCount: 24,
editColumn: 41,
insertText: '<https://example.com/fail>',
},
lineNumber: 19,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
{
errorContext: 'https://example.com/fail',
errorDetail: null,
errorRange: [
16,
24,
],
fixInfo: {
deleteCount: 24,
editColumn: 16,
insertText: '<https://example.com/fail>',
},
lineNumber: 21,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
{
errorContext: 'https://example.com/fail',
errorDetail: null,
errorRange: [
17,
24,
],
fixInfo: {
deleteCount: 24,
editColumn: 17,
insertText: '<https://example.com/fail>',
},
lineNumber: 23,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
],
fixed: `# Bare URLs in HTML␊
<p>
https://example.com/pass␊
</p>
Text <https://example.com/fail> text. {MD034}␊
Text <code>https://example.com/pass</code> text.␊
Text <code>https://example.com/pass</code> text <https://example.com/fail> text. {MD034}␊
Text <code>https://example.com/pass</code> text <https://example.com/fail> text <code>https://example.com/pass</code> text. {MD034}␊
Text <em> text <strong>text</strong> https://example.com/pass </em> text.␊
Text <em> text <em>text</em> https://example.com/pass </em> text.␊
Text <em> text <em>text</em> text </em> <https://example.com/fail> text. {MD034}␊
Text <br> text <https://example.com/fail> <br> text. {MD034}␊
Text <br/> text <https://example.com/fail> <br/> text. {MD034}␊
<!-- markdownlint-configure-file {␊
"line-length": false,␊
"no-inline-html": false␊
} -->␊
`,
}
## bare-urls.md
> Snapshot 1
@ -2986,6 +3144,26 @@ Generated by [AVA](https://avajs.dev).
'no-bare-urls',
],
},
{
errorContext: 'user@example.com',
errorDetail: null,
errorRange: [
40,
16,
],
fixInfo: {
deleteCount: 16,
editColumn: 40,
insertText: '<user@example.com>',
},
lineNumber: 76,
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␊
@ -3059,6 +3237,12 @@ Generated by [AVA](https://avajs.dev).
... when explicit: <https://example.com#heading->
... when embedded: <code>https://example.com#heading-</code>
Links with spaces inside angle brackets are okay: [blue jay](<https://en.wikipedia.org/wiki/Blue jay>)␊
Email addresses are treated similarly: <user@example.com> {MD034}␊
Angle brackets work the same for email: <user@example.com>
`,
}
@ -10256,6 +10440,7 @@ Generated by [AVA](https://avajs.dev).
Text *emphasized* **strong** ___emphasized+strong___.␊
Text \`code\` <strike>html</strike> <https://example.com/page>.␊
Text [link](https://example.com/page) [link][] [link] ![image][link].␊
Text https://example.com/page.␊
Hard ␊
line break␊
@ -16679,6 +16864,22 @@ Generated by [AVA](https://avajs.dev).
'no-inline-html',
],
},
{
errorContext: null,
errorDetail: 'Element: custom-element',
errorRange: [
1,
35,
],
fixInfo: null,
lineNumber: 120,
ruleDescription: 'Inline HTML',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md033.md',
ruleNames: [
'MD033',
'no-inline-html',
],
},
],
fixed: `# Detailed HTML Results␊
@ -16798,6 +16999,13 @@ Generated by [AVA](https://avajs.dev).
<details>
{MD033:116}␊
<custom-element attribute1="value1"
attribute2="value2" />␊
{MD033:120}␊
Text <!-- <commented-out html="tag"> --> text.␊
`,
}
@ -22836,26 +23044,6 @@ Generated by [AVA](https://avajs.dev).
'no-bare-urls',
],
},
{
errorContext: 'ftp://user:password@ftp-server...',
errorDetail: null,
errorRange: [
1,
55,
],
fixInfo: {
deleteCount: 55,
editColumn: 1,
insertText: '<ftp://user:password@ftp-server.example.com/dir/file.txt>',
},
lineNumber: 11,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
{
errorContext: 'https://example.com',
errorDetail: null,
@ -22868,7 +23056,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 2,
insertText: '<https://example.com>',
},
lineNumber: 29,
lineNumber: 20,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
@ -22877,18 +23065,18 @@ Generated by [AVA](https://avajs.dev).
],
},
{
errorContext: 'https://example.com',
errorContext: 'https://example.com}',
errorDetail: null,
errorRange: [
2,
19,
20,
],
fixInfo: {
deleteCount: 19,
deleteCount: 20,
editColumn: 2,
insertText: '<https://example.com>',
insertText: '<https://example.com}>',
},
lineNumber: 30,
lineNumber: 21,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
@ -22908,7 +23096,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 3,
insertText: '<https://example.com/>',
},
lineNumber: 36,
lineNumber: 27,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
@ -22928,7 +23116,7 @@ Generated by [AVA](https://avajs.dev).
editColumn: 26,
insertText: '<https://example.com/>',
},
lineNumber: 36,
lineNumber: 27,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
@ -22947,8 +23135,6 @@ Generated by [AVA](https://avajs.dev).
<hTtPs://gOoGlE.cOm/> {MD034}␊
<ftp://user:password@ftp-server.example.com/dir/file.txt> {MD034}␊
This link should be fine: <https://www.google.com/>
The following are allowed to avoid conflicts with MD011/no-reversed-links:␊
@ -22956,17 +23142,10 @@ Generated by [AVA](https://avajs.dev).
[https://example.com]␊
[https://example.com/search?query=text]␊
The following are allowed to avoid conflicts with HTML-like syntax:␊
"https://example.com"␊
"https://example.com/search?query=text"␊
'https://example.com'␊
'https://example.com/search?query=text'␊
Other enclosures are not allowed:␊
(<https://example.com>) {MD034}␊
{<https://example.com>} {MD034}␊
{<https://example.com}> {MD034}␊
Duplicate links in tables should be handled:␊
@ -35200,6 +35379,26 @@ Generated by [AVA](https://avajs.dev).
{
errors: [
{
errorContext: 'https://example.com/footnote',
errorDetail: null,
errorRange: [
7,
28,
],
fixInfo: {
deleteCount: 28,
editColumn: 7,
insertText: '<https://example.com/footnote>',
},
lineNumber: 186,
ruleDescription: 'Bare URL used',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md034.md',
ruleNames: [
'MD034',
'no-bare-urls',
],
},
{
errorContext: '[text][missing]',
errorDetail: 'Missing link or image reference definition: "missing"',
@ -35600,7 +35799,7 @@ Generated by [AVA](https://avajs.dev).
[unique8]: https://example.com/unique8␊
[unique9]: https://example.com/unique9␊
[unique10]: https://example.com/unique10␊
[^1]: https://example.com/footnote
[^1]: <https://example.com/footnote> {MD034}
## Ignored Labels␊