mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 05:50:13 +01:00
Hide the content of inline configuration HTML comments from the linting process to avoid false positives.
This commit is contained in:
parent
535aa1a2ee
commit
bbec8c5c1e
7 changed files with 80 additions and 40 deletions
|
|
@ -174,16 +174,10 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
|
||||||
!content.endsWith("-") && !content.includes("--"));
|
!content.endsWith("-") && !content.includes("--"));
|
||||||
// If a valid block/inline comment...
|
// If a valid block/inline comment...
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
const inlineCommentIndex = text
|
text =
|
||||||
.slice(i, j + htmlCommentEnd.length)
|
text.slice(0, i + htmlCommentBegin.length) +
|
||||||
.search(inlineCommentStartRe);
|
content.replace(/[^\r\n]/g, ".") +
|
||||||
// If not a markdownlint inline directive...
|
text.slice(j);
|
||||||
if (inlineCommentIndex !== 0) {
|
|
||||||
text =
|
|
||||||
text.slice(0, i + htmlCommentBegin.length) +
|
|
||||||
content.replace(/[^\r\n]/g, ".") +
|
|
||||||
text.slice(j);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1701,15 +1695,16 @@ function lintContent(ruleList, name, content, md, config, frontMatter, handleRul
|
||||||
content = content.replace(/^\uFEFF/, "");
|
content = content.replace(/^\uFEFF/, "");
|
||||||
// Remove front matter
|
// Remove front matter
|
||||||
const removeFrontMatterResult = removeFrontMatter(content, frontMatter);
|
const removeFrontMatterResult = removeFrontMatter(content, frontMatter);
|
||||||
const frontMatterLines = removeFrontMatterResult.frontMatterLines;
|
const { frontMatterLines } = removeFrontMatterResult;
|
||||||
// Ignore the content of HTML comments
|
content = removeFrontMatterResult.content;
|
||||||
content = helpers.clearHtmlCommentText(removeFrontMatterResult.content);
|
// Get enabled rules per line (with HTML comments present)
|
||||||
|
const { effectiveConfig, enabledRulesPerLineNumber } = getEnabledRulesPerLineNumber(ruleList, content.split(helpers.newLineRe), frontMatterLines, noInlineConfig, config, mapAliasToRuleNames(ruleList));
|
||||||
|
// Hide the content of HTML comments from rules, etc.
|
||||||
|
content = helpers.clearHtmlCommentText(content);
|
||||||
// Parse content into tokens and lines
|
// Parse content into tokens and lines
|
||||||
const tokens = md.parse(content, {});
|
const tokens = md.parse(content, {});
|
||||||
const lines = content.split(helpers.newLineRe);
|
const lines = content.split(helpers.newLineRe);
|
||||||
annotateTokens(tokens, lines);
|
annotateTokens(tokens, lines);
|
||||||
const aliasToRuleNames = mapAliasToRuleNames(ruleList);
|
|
||||||
const { effectiveConfig, enabledRulesPerLineNumber } = getEnabledRulesPerLineNumber(ruleList, lines, frontMatterLines, noInlineConfig, config, aliasToRuleNames);
|
|
||||||
// Create parameters for rules
|
// Create parameters for rules
|
||||||
const paramsBase = helpers.deepFreeze({
|
const paramsBase = helpers.deepFreeze({
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
|
|
@ -161,16 +161,10 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
|
||||||
!content.endsWith("-") && !content.includes("--"));
|
!content.endsWith("-") && !content.includes("--"));
|
||||||
// If a valid block/inline comment...
|
// If a valid block/inline comment...
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
const inlineCommentIndex = text
|
text =
|
||||||
.slice(i, j + htmlCommentEnd.length)
|
text.slice(0, i + htmlCommentBegin.length) +
|
||||||
.search(inlineCommentStartRe);
|
content.replace(/[^\r\n]/g, ".") +
|
||||||
// If not a markdownlint inline directive...
|
text.slice(j);
|
||||||
if (inlineCommentIndex !== 0) {
|
|
||||||
text =
|
|
||||||
text.slice(0, i + htmlCommentBegin.length) +
|
|
||||||
content.replace(/[^\r\n]/g, ".") +
|
|
||||||
text.slice(j);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -474,23 +474,24 @@ function lintContent(
|
||||||
content = content.replace(/^\uFEFF/, "");
|
content = content.replace(/^\uFEFF/, "");
|
||||||
// Remove front matter
|
// Remove front matter
|
||||||
const removeFrontMatterResult = removeFrontMatter(content, frontMatter);
|
const removeFrontMatterResult = removeFrontMatter(content, frontMatter);
|
||||||
const frontMatterLines = removeFrontMatterResult.frontMatterLines;
|
const { frontMatterLines } = removeFrontMatterResult;
|
||||||
// Ignore the content of HTML comments
|
content = removeFrontMatterResult.content;
|
||||||
content = helpers.clearHtmlCommentText(removeFrontMatterResult.content);
|
// Get enabled rules per line (with HTML comments present)
|
||||||
|
const { effectiveConfig, enabledRulesPerLineNumber } =
|
||||||
|
getEnabledRulesPerLineNumber(
|
||||||
|
ruleList,
|
||||||
|
content.split(helpers.newLineRe),
|
||||||
|
frontMatterLines,
|
||||||
|
noInlineConfig,
|
||||||
|
config,
|
||||||
|
mapAliasToRuleNames(ruleList)
|
||||||
|
);
|
||||||
|
// Hide the content of HTML comments from rules, etc.
|
||||||
|
content = helpers.clearHtmlCommentText(content);
|
||||||
// Parse content into tokens and lines
|
// Parse content into tokens and lines
|
||||||
const tokens = md.parse(content, {});
|
const tokens = md.parse(content, {});
|
||||||
const lines = content.split(helpers.newLineRe);
|
const lines = content.split(helpers.newLineRe);
|
||||||
annotateTokens(tokens, lines);
|
annotateTokens(tokens, lines);
|
||||||
const aliasToRuleNames = mapAliasToRuleNames(ruleList);
|
|
||||||
const { effectiveConfig, enabledRulesPerLineNumber } =
|
|
||||||
getEnabledRulesPerLineNumber(
|
|
||||||
ruleList,
|
|
||||||
lines,
|
|
||||||
frontMatterLines,
|
|
||||||
noInlineConfig,
|
|
||||||
config,
|
|
||||||
aliasToRuleNames
|
|
||||||
);
|
|
||||||
// Create parameters for rules
|
// Create parameters for rules
|
||||||
const paramsBase = helpers.deepFreeze({
|
const paramsBase = helpers.deepFreeze({
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
10
test/inline-configure-file-violations.md
Normal file
10
test/inline-configure-file-violations.md
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Inline Configure File Violations
|
||||||
|
|
||||||
|
Emphasis * with * spaces {MD037}
|
||||||
|
|
||||||
|
Trailing spaces:
|
||||||
|
|
||||||
|
<!-- markdownlint-configure-file {
|
||||||
|
"comment": "emphasis * with * spaces",
|
||||||
|
"no-trailing-spaces": false
|
||||||
|
} -->
|
||||||
|
|
@ -155,9 +155,9 @@ test("clearHtmlCommentTextEmbedded", (t) => {
|
||||||
];
|
];
|
||||||
const embeddedResult = [
|
const embeddedResult = [
|
||||||
"text<!--....-->text",
|
"text<!--....-->text",
|
||||||
"<!-- markdownlint-disable MD010 -->",
|
"<!--............................-->",
|
||||||
"text<!--....-->text",
|
"text<!--....-->text",
|
||||||
"text<!-- markdownlint-disable MD010 -->text",
|
"text<!--............................-->text",
|
||||||
"text<!--....-->text"
|
"text<!--....-->text"
|
||||||
];
|
];
|
||||||
const actual = helpers.clearHtmlCommentText(embeddedComments.join("\n"));
|
const actual = helpers.clearHtmlCommentText(embeddedComments.join("\n"));
|
||||||
|
|
|
||||||
|
|
@ -17397,6 +17397,46 @@ Generated by [AVA](https://avajs.dev).
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## inline-configure-file-violations.md
|
||||||
|
|
||||||
|
> Snapshot 1
|
||||||
|
|
||||||
|
{
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
errorContext: '* with *',
|
||||||
|
errorDetail: null,
|
||||||
|
errorRange: [
|
||||||
|
10,
|
||||||
|
8,
|
||||||
|
],
|
||||||
|
fixInfo: {
|
||||||
|
deleteCount: 8,
|
||||||
|
editColumn: 10,
|
||||||
|
insertText: '*with*',
|
||||||
|
},
|
||||||
|
lineNumber: 3,
|
||||||
|
ruleDescription: 'Spaces inside emphasis markers',
|
||||||
|
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md037',
|
||||||
|
ruleNames: [
|
||||||
|
'MD037',
|
||||||
|
'no-space-in-emphasis',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
fixed: `# Inline Configure File Violations␊
|
||||||
|
␊
|
||||||
|
Emphasis *with* spaces {MD037}␊
|
||||||
|
␊
|
||||||
|
Trailing spaces: ␊
|
||||||
|
␊
|
||||||
|
<!-- markdownlint-configure-file {␊
|
||||||
|
"comment": "emphasis * with * spaces",␊
|
||||||
|
"no-trailing-spaces": false␊
|
||||||
|
} -->␊
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
## inline-disable-enable-file.md
|
## inline-disable-enable-file.md
|
||||||
|
|
||||||
> Snapshot 1
|
> Snapshot 1
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue