mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-10 09:58:50 +01:00
Update previous commit for MD051/link-fragments to rename, refactor, add support for HTML anchors, and validate against
markdown-link-check (fixes #253).
This commit is contained in:
parent
33ee1cd85e
commit
db5d9f6dbb
21 changed files with 355 additions and 181 deletions
|
|
@ -93,4 +93,6 @@ Strong __with__ underscore style
|
|||
|
||||
Strong **with** different style {MD050}
|
||||
|
||||
[Missing link fragment](#missing) {MD051}
|
||||
|
||||
EOF {MD047}
|
||||
|
|
@ -9,5 +9,6 @@
|
|||
"names": [
|
||||
"markdownlint"
|
||||
]
|
||||
}
|
||||
},
|
||||
"MD051": false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -314,31 +314,5 @@
|
|||
"MD050",
|
||||
"strong-style"
|
||||
]
|
||||
},
|
||||
{
|
||||
"errorContext": "#",
|
||||
"errorDetail": "Link Fragment is invalid",
|
||||
"errorRange": null,
|
||||
"fixInfo": null,
|
||||
"lineNumber": 5,
|
||||
"ruleDescription": "Link fragments should be valid",
|
||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051",
|
||||
"ruleNames": [
|
||||
"MD051",
|
||||
"valid-link-fragments"
|
||||
]
|
||||
},
|
||||
{
|
||||
"errorContext": "#one",
|
||||
"errorDetail": "Link Fragment is invalid",
|
||||
"errorRange": null,
|
||||
"fixInfo": null,
|
||||
"lineNumber": 17,
|
||||
"ruleDescription": "Link fragments should be valid",
|
||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051",
|
||||
"ruleNames": [
|
||||
"MD051",
|
||||
"valid-link-fragments"
|
||||
]
|
||||
}
|
||||
]
|
||||
3
test/detailed-results-MD051-MD060.md
Normal file
3
test/detailed-results-MD051-MD060.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# detailed-results-MD051-MD060
|
||||
|
||||
A [link with a missing](#fragment)
|
||||
3
test/detailed-results-MD051-MD060.md.fixed
Normal file
3
test/detailed-results-MD051-MD060.md.fixed
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# detailed-results-MD051-MD060
|
||||
|
||||
A [link with a missing](#fragment)
|
||||
18
test/detailed-results-MD051-MD060.results.json
Normal file
18
test/detailed-results-MD051-MD060.results.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[
|
||||
{
|
||||
"errorContext": "[link with a missing](#fragment)",
|
||||
"errorDetail": null,
|
||||
"errorRange": [
|
||||
3,
|
||||
32
|
||||
],
|
||||
"fixInfo": null,
|
||||
"lineNumber": 3,
|
||||
"ruleDescription": "Link fragments should be valid",
|
||||
"ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md051",
|
||||
"ruleNames": [
|
||||
"MD051",
|
||||
"link-fragments"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
@ -12,17 +12,17 @@
|
|||
|
||||
[text]( <> "title" ) {MD042}
|
||||
|
||||
[text](#) {MD042} {MD051}
|
||||
[text](#) {MD042}
|
||||
|
||||
[text]( # ) {MD042} {MD051}
|
||||
[text]( # ) {MD042}
|
||||
|
||||
[text](# "title") {MD042} {MD051}
|
||||
[text](# "title") {MD042}
|
||||
|
||||
[text]( # "title" ) {MD042} {MD051}
|
||||
[text]( # "title" ) {MD042}
|
||||
|
||||
[text][frag] {MD042} {MD051}
|
||||
[text][frag] {MD042}
|
||||
|
||||
[text][ frag ] {MD042} {MD051}
|
||||
[text][ frag ] {MD042}
|
||||
|
||||
[frag]: #
|
||||
|
||||
|
|
|
|||
94
test/link-fragments.md
Normal file
94
test/link-fragments.md
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
# Valid/Invalid Link Fragments
|
||||
|
||||
## Valid Fragments
|
||||
|
||||
[Valid](#validinvalid-link-fragments)
|
||||
|
||||
[Valid](#valid-fragments)
|
||||
|
||||
[Valid](#valid-h3-heading)
|
||||
|
||||
[Valid](#valid-heading-with-underscores-_)
|
||||
|
||||
[Valid](#valid-heading-with-emphasis)
|
||||
|
||||
[Valid](#valid-heading-with-quotes--and-double-quotes-)
|
||||
|
||||
[Valid](#-valid-heading-with-emoji)
|
||||
|
||||
[Valid](#valid-heading--with-emoji-2)
|
||||
|
||||
[Valid](#valid-closed-atx-heading)
|
||||
|
||||
[Valid](#valid-setext-heading)
|
||||
|
||||
[Valid](#namedlink)
|
||||
|
||||
[Valid](#idlink)
|
||||
|
||||
[Valid](#myident)
|
||||
|
||||
[Valid](#HREFandID)
|
||||
|
||||
[Valid][goodref]
|
||||
|
||||
### Valid H3 Heading
|
||||
|
||||
Text
|
||||
|
||||
### Valid Heading With Underscores _
|
||||
|
||||
Text
|
||||
|
||||
### Valid *Heading* With _Emphasis_
|
||||
|
||||
Text
|
||||
|
||||
### Valid Heading With Quotes ' And Double Quotes "
|
||||
|
||||
Text
|
||||
|
||||
### 🚀 Valid Heading With Emoji
|
||||
|
||||
Text
|
||||
|
||||
### Valid Heading 👀 With Emoji 2
|
||||
|
||||
Text
|
||||
|
||||
### Valid Closed ATX Heading ###
|
||||
|
||||
Text
|
||||
|
||||
Valid Setext Heading
|
||||
--------------------
|
||||
|
||||
Text
|
||||
|
||||
<a name="namedlink"></a>
|
||||
|
||||
<a id = idlink></a>
|
||||
|
||||
<a id="myident" name="myname"/>
|
||||
|
||||
<A href="https://example.com" id="HREFandID">Text</A>
|
||||
|
||||
[goodref]: #namedlink
|
||||
|
||||
## Invalid Fragments
|
||||
|
||||
[Invalid](#invalid-fragment) {MD051}
|
||||
|
||||
[Invalid](#myname) {MD051}
|
||||
|
||||
[Invalid](#hrefandid) {MD051}
|
||||
|
||||
[Invalid][badref] {MD051}
|
||||
|
||||
[badref]: #missing
|
||||
|
||||
<!-- markdownlint-configure-file {
|
||||
"emphasis-style": false,
|
||||
"heading-style": false,
|
||||
"no-inline-html": false
|
||||
} -->
|
||||
|
|
@ -35,13 +35,69 @@ async function lintTestRepo(t, globPatterns, configPath, ignoreRes) {
|
|||
readConfigPromise(configPath, [ jsoncParse, yamlParse ])
|
||||
]).then((globbyAndReadConfigResults) => {
|
||||
const [ files, config ] = globbyAndReadConfigResults;
|
||||
const options = {
|
||||
files,
|
||||
config
|
||||
};
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`${t.title}: Linting ${files.length} files...`);
|
||||
return markdownlintPromise(options).then((results) => {
|
||||
return markdownlintPromise({
|
||||
files,
|
||||
config,
|
||||
"resultVersion": 3
|
||||
// }).then((results) => {
|
||||
// // Cross-check MD051/link-fragments results with markdown-link-check
|
||||
// const resultFiles = [];
|
||||
// const detectedErrors = new Set();
|
||||
// for (const file of Object.keys(results)) {
|
||||
// const errors =
|
||||
// results[file].filter((error) => error.ruleNames[0] === "MD051");
|
||||
// if (errors.length > 0) {
|
||||
// resultFiles.push(file);
|
||||
// }
|
||||
// for (const error of errors) {
|
||||
// const fragment = error.errorContext.replace(/^.*\((#.*)\)$/, "$1");
|
||||
// detectedErrors.add(file + fragment);
|
||||
// }
|
||||
// }
|
||||
// const { readFile } = require("fs").promises;
|
||||
// const markdownLinkCheck = promisify(require("markdown-link-check"));
|
||||
// const expectedErrors = new Set();
|
||||
// return Promise.all(
|
||||
// resultFiles.map((file) => readFile(file, "utf8")
|
||||
// // @ts-ignore
|
||||
// .then((markdown) => markdownLinkCheck(markdown, {
|
||||
// "ignorePatterns": [
|
||||
// {
|
||||
// "pattern": "^[^#]"
|
||||
// }
|
||||
// ]
|
||||
// }))
|
||||
// .then((mlcResults) => {
|
||||
// const deadResults =
|
||||
// mlcResults.filter((result) => result.status === "dead");
|
||||
// for (const link of deadResults.map((result) => result.link)) {
|
||||
// expectedErrors.add(file + link);
|
||||
// }
|
||||
// })
|
||||
// )
|
||||
// ).then(() => {
|
||||
// const extraErrors = [];
|
||||
// // @ts-ignore
|
||||
// for (const detectedError of detectedErrors) {
|
||||
// if (!expectedErrors.has(detectedError)) {
|
||||
// extraErrors.push(detectedError);
|
||||
// }
|
||||
// }
|
||||
// t.deepEqual(extraErrors, [], "Extra errors");
|
||||
// const missingErrors = [];
|
||||
// // @ts-ignore
|
||||
// for (const expectedError of expectedErrors) {
|
||||
// if (!detectedErrors.has(expectedError)) {
|
||||
// missingErrors.push(expectedError);
|
||||
// }
|
||||
// }
|
||||
// t.deepEqual(missingErrors, [], "Missing errors");
|
||||
// return results;
|
||||
// });
|
||||
}).then((results) => {
|
||||
// Fail if any issues were found (that aren't ignored)
|
||||
let resultsString = results.toString();
|
||||
for (const ignoreRe of (ignoreRes || [])) {
|
||||
const lengthBefore = resultsString.length;
|
||||
|
|
@ -93,7 +149,8 @@ test("https://github.com/mkdocs/mkdocs", (t) => {
|
|||
)
|
||||
];
|
||||
const configPath = join(rootDir, ".markdownlintrc");
|
||||
return lintTestRepo(t, globPatterns, configPath);
|
||||
const ignoreRes = [ /^[^:]+: \d+: MD051\/.*$\r?\n?/gm ];
|
||||
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
|
||||
});
|
||||
|
||||
test("https://github.com/mochajs/mocha", (t) => {
|
||||
|
|
@ -107,14 +164,16 @@ test("https://github.com/mochajs/mocha", (t) => {
|
|||
join(rootDir, "example/**/*.md")
|
||||
];
|
||||
const configPath = join(rootDir, ".markdownlint.json");
|
||||
return lintTestRepo(t, globPatterns, configPath);
|
||||
const ignoreRes = [ /^[^:]+: \d+: MD051\/.*$\r?\n?/gm ];
|
||||
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
|
||||
});
|
||||
|
||||
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 = [ /^[^:]+: \d+: MD051\/.*$\r?\n?/gm ];
|
||||
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
|
||||
});
|
||||
|
||||
test("https://github.com/webhintio/hint", (t) => {
|
||||
|
|
@ -142,7 +201,8 @@ if (existsSync(dotnetDocsDir)) {
|
|||
const rootDir = dotnetDocsDir;
|
||||
const globPatterns = [ join(rootDir, "**/*.md") ];
|
||||
const configPath = join(rootDir, ".markdownlint.json");
|
||||
return lintTestRepo(t, globPatterns, configPath);
|
||||
const ignoreRes = [ /^[^:]+: \d+: MD051\/.*$\r?\n?/gm ];
|
||||
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +212,7 @@ if (existsSync(v8v8DevDir)) {
|
|||
const rootDir = v8v8DevDir;
|
||||
const globPatterns = [ join(rootDir, "src/**/*.md") ];
|
||||
const configPath = join(rootDir, ".markdownlint.json");
|
||||
const ignoreRes = [ /^[^:]+: \d+: MD049\/.*$\r?\n?/gm ];
|
||||
const ignoreRes = [ /^[^:]+: \d+: (MD049|MD051)\/.*$\r?\n?/gm ];
|
||||
return lintTestRepo(t, globPatterns, configPath, ignoreRes);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,10 +105,7 @@ test.cb("projectFilesInlineConfig", (t) => {
|
|||
t.plan(2);
|
||||
const options = {
|
||||
"files": [ "doc/Rules.md" ],
|
||||
"config": {
|
||||
"no-inline-html": false,
|
||||
...require("../.markdownlint.json")
|
||||
}
|
||||
"config": require("../.markdownlint.json")
|
||||
};
|
||||
markdownlint(options, function callback(err, actual) {
|
||||
t.falsy(err);
|
||||
|
|
@ -491,10 +488,11 @@ test.cb("styleAll", (t) => {
|
|||
"MD042": [ 81 ],
|
||||
"MD045": [ 85 ],
|
||||
"MD046": [ 49, 73, 77 ],
|
||||
"MD047": [ 96 ],
|
||||
"MD047": [ 98 ],
|
||||
"MD048": [ 77 ],
|
||||
"MD049": [ 90 ],
|
||||
"MD050": [ 94 ]
|
||||
"MD050": [ 94 ],
|
||||
"MD051": [ 96 ]
|
||||
}
|
||||
};
|
||||
// @ts-ignore
|
||||
|
|
@ -536,10 +534,11 @@ test.cb("styleRelaxed", (t) => {
|
|||
"MD042": [ 81 ],
|
||||
"MD045": [ 85 ],
|
||||
"MD046": [ 49, 73, 77 ],
|
||||
"MD047": [ 96 ],
|
||||
"MD047": [ 98 ],
|
||||
"MD048": [ 77 ],
|
||||
"MD049": [ 90 ],
|
||||
"MD050": [ 94 ]
|
||||
"MD050": [ 94 ],
|
||||
"MD051": [ 96 ]
|
||||
}
|
||||
};
|
||||
// @ts-ignore
|
||||
|
|
|
|||
|
|
@ -88,11 +88,11 @@ Text [link(link](#link`link) text `code`. {MD051}
|
|||
|
||||
Text [link)link](#link`link) text `code`. {MD051}
|
||||
|
||||
Text [link](#link[linklink) text `code`. {MD051}
|
||||
Text [link](#link[link`link) text `code`. {MD051}
|
||||
|
||||
Text [link](#link[linklink) text `code`. {MD051}
|
||||
Text [link](#link]link`link) text `code`. {MD051}
|
||||
|
||||
Text [link](#link[linklink) text `code`. {MD051}
|
||||
Text [link](#link(link`link) text `code`. {MD038}
|
||||
|
||||
Text [`link`](xref:custom.link`1) text `code`.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
# Valid/Invalid Link Fragments
|
||||
|
||||
## Valid Fragments
|
||||
|
||||
[Valid](#validinvalid-link-fragments)
|
||||
|
||||
[Valid](#valid-fragments)
|
||||
|
||||
[Valid](#valid-h3-heading)
|
||||
|
||||
[Valid](#valid-heading-with-underscores-_)
|
||||
|
||||
[Valid](#valid-heading-with-quotes--and-double-quotes-)
|
||||
|
||||
[Valid](#-valid-heading-with-emoji)
|
||||
|
||||
[Valid](#valid-heading--with-emoji-2)
|
||||
|
||||
[Valid](#valid-closed-atx-heading)
|
||||
|
||||
[Valid](#valid-setex-heading)
|
||||
|
||||
### Valid H3 Heading
|
||||
|
||||
Text
|
||||
|
||||
### Valid Heading With Underscores _
|
||||
|
||||
Text
|
||||
|
||||
### Valid Heading With Quotes ' And Double Quotes "
|
||||
|
||||
Text
|
||||
|
||||
### 🚀 Valid Heading With Emoji
|
||||
|
||||
Text
|
||||
|
||||
### Valid Heading 👀 With Emoji 2
|
||||
|
||||
Text
|
||||
|
||||
<!-- markdownlint-disable-next-line MD003 -->
|
||||
### Valid Closed ATX Heading ###
|
||||
|
||||
Text
|
||||
|
||||
<!-- markdownlint-disable-next-line MD003 -->
|
||||
Valid Setex Heading
|
||||
----
|
||||
|
||||
Text
|
||||
|
||||
## Invalid Fragments
|
||||
|
||||
[Invalid](#invalid-fragments-not-exist) {MD051}
|
||||
Loading…
Add table
Add a link
Reference in a new issue