mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Add markdownlint-disable-file/markdownlint-enable-file inline comments (fixes #215).
This commit is contained in:
parent
c0f040e5c1
commit
a9251c533f
5 changed files with 85 additions and 27 deletions
|
|
@ -259,43 +259,55 @@ function getEnabledRulesPerLineNumber(
|
|||
effectiveConfig, aliasToRuleNames) {
|
||||
let enabledRules = {};
|
||||
const allRuleNames = [];
|
||||
ruleList.forEach(function forRule(rule) {
|
||||
ruleList.forEach((rule) => {
|
||||
const ruleName = rule.names[0].toUpperCase();
|
||||
allRuleNames.push(ruleName);
|
||||
enabledRules[ruleName] = !!effectiveConfig[ruleName];
|
||||
});
|
||||
let capturedRules = enabledRules;
|
||||
function forMatch(match) {
|
||||
function forMatch(match, byLine) {
|
||||
const action = match[1].toUpperCase();
|
||||
if (action === "CAPTURE") {
|
||||
capturedRules = { ...enabledRules };
|
||||
if (byLine) {
|
||||
capturedRules = { ...enabledRules };
|
||||
}
|
||||
} else if (action === "RESTORE") {
|
||||
enabledRules = { ...capturedRules };
|
||||
if (byLine) {
|
||||
enabledRules = { ...capturedRules };
|
||||
}
|
||||
} else {
|
||||
const enabled = (action === "ENABLE");
|
||||
const items = match[2] ?
|
||||
match[2].trim().toUpperCase().split(/\s+/) :
|
||||
allRuleNames;
|
||||
items.forEach(function forItem(nameUpper) {
|
||||
(aliasToRuleNames[nameUpper] || []).forEach(function forRule(ruleName) {
|
||||
enabledRules[ruleName] = enabled;
|
||||
// action in [ENABLE, DISABLE, ENABLE-FILE, DISABLE-FILE]
|
||||
const isfile = action.endsWith("-FILE");
|
||||
if ((byLine && !isfile) || (!byLine && isfile)) {
|
||||
const enabled = (action.startsWith("ENABLE"));
|
||||
const items = match[2] ?
|
||||
match[2].trim().toUpperCase().split(/\s+/) :
|
||||
allRuleNames;
|
||||
items.forEach((nameUpper) => {
|
||||
(aliasToRuleNames[nameUpper] || []).forEach((ruleName) => {
|
||||
enabledRules[ruleName] = enabled;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
const enabledRulesPerLineNumber = new Array(1 + frontMatterLines.length);
|
||||
lines.forEach(function forLine(line) {
|
||||
if (!noInlineConfig) {
|
||||
let match = helpers.inlineCommentRe.exec(line);
|
||||
if (match) {
|
||||
enabledRules = { ...enabledRules };
|
||||
while (match) {
|
||||
forMatch(match);
|
||||
match = helpers.inlineCommentRe.exec(line);
|
||||
[ false, true ].forEach((byLine) => {
|
||||
lines.forEach((line) => {
|
||||
if (!noInlineConfig) {
|
||||
let match = helpers.inlineCommentRe.exec(line);
|
||||
if (match) {
|
||||
enabledRules = { ...enabledRules };
|
||||
while (match) {
|
||||
forMatch(match, byLine);
|
||||
match = helpers.inlineCommentRe.exec(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
enabledRulesPerLineNumber.push(enabledRules);
|
||||
if (byLine) {
|
||||
enabledRulesPerLineNumber.push(enabledRules);
|
||||
}
|
||||
});
|
||||
});
|
||||
return enabledRulesPerLineNumber;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue