mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 22:40:13 +01:00
Add lint rules from eslint-plugin-unicorn.
This commit is contained in:
parent
0f4745efe3
commit
5ab938a6ab
11 changed files with 96 additions and 31 deletions
|
|
@ -154,7 +154,7 @@ function removeFrontMatter(content, frontMatter) {
|
|||
const contentMatched = frontMatterMatch[0];
|
||||
content = content.slice(contentMatched.length);
|
||||
frontMatterLines = contentMatched.split(helpers.newLineRe);
|
||||
if (frontMatterLines.length &&
|
||||
if ((frontMatterLines.length > 0) &&
|
||||
(frontMatterLines[frontMatterLines.length - 1] === "")) {
|
||||
frontMatterLines.length--;
|
||||
}
|
||||
|
|
@ -343,7 +343,8 @@ function getEnabledRulesPerLineNumber(
|
|||
...config,
|
||||
...json
|
||||
};
|
||||
} catch (ex) {
|
||||
// eslint-disable-next-line unicorn/prefer-optional-catch-binding
|
||||
} catch (error) {
|
||||
// Ignore parse errors for inline configuration
|
||||
}
|
||||
}
|
||||
|
|
@ -459,7 +460,7 @@ function lintContent(
|
|||
resultVersion,
|
||||
callback) {
|
||||
// Remove UTF-8 byte order marker (if present)
|
||||
content = content.replace(/^\ufeff/, "");
|
||||
content = content.replace(/^\uFEFF/, "");
|
||||
// Remove front matter
|
||||
const removeFrontMatterResult = removeFrontMatter(content, frontMatter);
|
||||
const frontMatterLines = removeFrontMatterResult.frontMatterLines;
|
||||
|
|
@ -582,17 +583,17 @@ function lintContent(
|
|||
if (handleRuleFailures) {
|
||||
try {
|
||||
rule.function(params, onError);
|
||||
} catch (ex) {
|
||||
} catch (error) {
|
||||
onError({
|
||||
"lineNumber": 1,
|
||||
"detail": `This rule threw an exception: ${ex.message}`
|
||||
"detail": `This rule threw an exception: ${error.message}`
|
||||
});
|
||||
}
|
||||
} else {
|
||||
rule.function(params, onError);
|
||||
}
|
||||
// Record any errors (significant performance benefit from length check)
|
||||
if (errors.length) {
|
||||
if (errors.length > 0) {
|
||||
errors.sort(lineNumberComparison);
|
||||
const filteredErrors = errors
|
||||
.filter((resultVersion === 3) ?
|
||||
|
|
@ -624,7 +625,7 @@ function lintContent(
|
|||
}
|
||||
return errorObject;
|
||||
});
|
||||
if (filteredErrors.length) {
|
||||
if (filteredErrors.length > 0) {
|
||||
if (resultVersion === 0) {
|
||||
result[ruleNameFriendly] = filteredErrors;
|
||||
} else {
|
||||
|
|
@ -636,9 +637,9 @@ function lintContent(
|
|||
// Run all rules
|
||||
try {
|
||||
ruleList.forEach(forRule);
|
||||
} catch (ex) {
|
||||
} catch (error) {
|
||||
cache.clear();
|
||||
return callback(ex);
|
||||
return callback(error);
|
||||
}
|
||||
cache.clear();
|
||||
return callback(null, result);
|
||||
|
|
@ -819,8 +820,8 @@ function parseConfiguration(name, content, parsers) {
|
|||
(parsers || [ JSON.parse ]).every((parser) => {
|
||||
try {
|
||||
config = parser(content);
|
||||
} catch (ex) {
|
||||
errors.push(ex.message);
|
||||
} catch (error) {
|
||||
errors.push(error.message);
|
||||
}
|
||||
return !config;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue