mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Add options.handleRuleFailures for custom rule exceptions.
This commit is contained in:
parent
0e5c44617f
commit
0f72bf054b
4 changed files with 232 additions and 67 deletions
|
|
@ -301,6 +301,7 @@ function lintContent(
|
|||
md,
|
||||
config,
|
||||
frontMatter,
|
||||
handleRuleFailures,
|
||||
noInlineConfig,
|
||||
resultVersion,
|
||||
callback) {
|
||||
|
|
@ -376,7 +377,18 @@ function lintContent(
|
|||
});
|
||||
}
|
||||
// Call (possibly external) rule function
|
||||
rule.function(params, onError);
|
||||
if (handleRuleFailures) {
|
||||
try {
|
||||
rule.function(params, onError);
|
||||
} catch (ex) {
|
||||
onError({
|
||||
"lineNumber": 1,
|
||||
"detail": `This rule threw an exception: ${ex.message}`
|
||||
});
|
||||
}
|
||||
} else {
|
||||
rule.function(params, onError);
|
||||
}
|
||||
// Record any errors (significant performance benefit from length check)
|
||||
if (errors.length) {
|
||||
errors.sort(lineNumberComparison);
|
||||
|
|
@ -432,6 +444,7 @@ function lintFile(
|
|||
md,
|
||||
config,
|
||||
frontMatter,
|
||||
handleRuleFailures,
|
||||
noInlineConfig,
|
||||
resultVersion,
|
||||
synchronous,
|
||||
|
|
@ -441,7 +454,7 @@ function lintFile(
|
|||
return callback(err);
|
||||
}
|
||||
return lintContent(ruleList, file, content, md, config, frontMatter,
|
||||
noInlineConfig, resultVersion, callback);
|
||||
handleRuleFailures, noInlineConfig, resultVersion, callback);
|
||||
}
|
||||
// Make a/synchronous call to read file
|
||||
if (synchronous) {
|
||||
|
|
@ -472,6 +485,7 @@ function lintInput(options, synchronous, callback) {
|
|||
const config = options.config || { "default": true };
|
||||
const frontMatter = (options.frontMatter === undefined) ?
|
||||
helpers.frontMatterRe : options.frontMatter;
|
||||
const handleRuleFailures = !!options.handleRuleFailures;
|
||||
const noInlineConfig = !!options.noInlineConfig;
|
||||
const resultVersion = (options.resultVersion === undefined) ?
|
||||
2 : options.resultVersion;
|
||||
|
|
@ -504,6 +518,7 @@ function lintInput(options, synchronous, callback) {
|
|||
md,
|
||||
config,
|
||||
frontMatter,
|
||||
handleRuleFailures,
|
||||
noInlineConfig,
|
||||
resultVersion,
|
||||
lintNextItemCallback);
|
||||
|
|
@ -515,6 +530,7 @@ function lintInput(options, synchronous, callback) {
|
|||
md,
|
||||
config,
|
||||
frontMatter,
|
||||
handleRuleFailures,
|
||||
noInlineConfig,
|
||||
resultVersion,
|
||||
synchronous,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue