Make resultVersion 3 (report multiple errors per line, include fixInfo) the default.

This commit is contained in:
David Anson 2022-04-21 21:30:56 -07:00
parent 9b3fd3d16b
commit 9310713da1
9 changed files with 44 additions and 31 deletions

View file

@ -522,12 +522,12 @@ as any additional detail or context that is available. *This is deprecated.*
Passing a `resultVersion` of `2` corresponds to a detailed format where each error
includes information about the line number, rule names, description, as well as any
additional detail or context that is available. *This is the default.*
additional detail or context that is available. *This is deprecated.*
Passing a `resultVersion` of `3` corresponds to the detailed version `2` format
with additional information about how to fix automatically-fixable errors. In this
mode, all errors that occur on each line are reported (other versions report only
the first error for each rule).
the first error for each rule). *This is the default.*
##### options.markdownItPlugins

View file

@ -52,8 +52,7 @@
"config": {
"MD013": false
},
"handleRuleFailures": true,
"resultVersion": 3
"handleRuleFailures": true
};
allLintErrors = window.markdownlint.sync(options).content;
violations.innerHTML = allLintErrors.map(function mapResult(result) {

View file

@ -1808,7 +1808,7 @@ function lintInput(options, synchronous, callback) {
var handleRuleFailures = !!options.handleRuleFailures;
var noInlineConfig = !!options.noInlineConfig;
var resultVersion = (options.resultVersion === undefined) ?
2 : options.resultVersion;
3 : options.resultVersion;
var md = markdownIt({ "html": true });
var markdownItPlugins = options.markdownItPlugins || [];
markdownItPlugins.forEach(function forPlugin(plugin) {

View file

@ -92,7 +92,6 @@ options = {
"frontMatter": /---/,
"handleRuleFailures": false,
"noInlineConfig": false,
"resultVersion": 3,
"markdownItPlugins": [ [ require("markdown-it-sub") ] ]
};

View file

@ -773,7 +773,7 @@ function lintInput(options, synchronous, callback) {
const handleRuleFailures = !!options.handleRuleFailures;
const noInlineConfig = !!options.noInlineConfig;
const resultVersion = (options.resultVersion === undefined) ?
2 : options.resultVersion;
3 : options.resultVersion;
const md = markdownIt({ "html": true });
const markdownItPlugins = options.markdownItPlugins || [];
markdownItPlugins.forEach(function forPlugin(plugin) {

View file

@ -901,7 +901,8 @@ test.cb("customRulesOnErrorLazy", (t) => {
"ruleInformation": null,
"errorDetail": null,
"errorContext": null,
"errorRange": [ 1, 1 ]
"errorRange": [ 1, 1 ],
"fixInfo": null
}
]
};
@ -943,8 +944,7 @@ test.cb("customRulesOnErrorModified", (t) => {
],
"strings": {
"string": "# Heading\n"
},
"resultVersion": 3
}
};
markdownlint(options, function callback(err, actualResult) {
t.falsy(err);
@ -1002,7 +1002,8 @@ test.cb("customRulesOnErrorInvalidHandled", (t) => {
"errorDetail": "This rule threw an exception: " +
"Property 'lineNumber' of onError parameter is incorrect.",
"errorContext": null,
"errorRange": null
"errorRange": null,
"fixInfo": null
}
]
};
@ -1042,7 +1043,8 @@ test("customRulesOnErrorInvalidHandledSync", (t) => {
"errorDetail": "This rule threw an exception: " +
"Property 'lineNumber' of onError parameter is incorrect.",
"errorContext": null,
"errorRange": null
"errorRange": null,
"fixInfo": null
}
]
};
@ -1125,7 +1127,8 @@ test.cb("customRulesLintJavaScript", (t) => {
"ruleInformation": null,
"errorDetail": "Unexpected var, use let or const instead.",
"errorContext": "var x = 0;",
"errorRange": null
"errorRange": null,
"fixInfo": null
},
{
"lineNumber": 12,
@ -1134,7 +1137,8 @@ test.cb("customRulesLintJavaScript", (t) => {
"ruleInformation": null,
"errorDetail": "Unexpected console statement.",
"errorContext": "console.log(x);",
"errorRange": null
"errorRange": null,
"fixInfo": null
}
]
};
@ -1160,7 +1164,8 @@ test.cb("customRulesValidateJson", (t) => {
"ruleInformation": null,
"errorDetail": "Unexpected end of JSON input",
"errorContext": null,
"errorRange": null
"errorRange": null,
"fixInfo": null
}
]
};
@ -1312,7 +1317,11 @@ test("customRulesAsyncReadFiles", (t) => {
"ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md047`,
"errorDetail": null,
"errorContext": null,
"errorRange": [ 9, 1 ]
"errorRange": [ 9, 1 ],
"fixInfo": {
"editColumn": 10,
"insertText": "\n"
}
},
{
"lineNumber": 1,
@ -1321,7 +1330,8 @@ test("customRulesAsyncReadFiles", (t) => {
"ruleInformation": "https://example.com/asyncRule1",
"errorDetail": "detail1",
"errorContext": "context1",
"errorRange": [ 2, 3 ]
"errorRange": [ 2, 3 ],
"fixInfo": null
},
{
"lineNumber": 1,
@ -1330,7 +1340,8 @@ test("customRulesAsyncReadFiles", (t) => {
"ruleInformation": null,
"errorDetail": "detail2",
"errorContext": "context2",
"errorRange": null
"errorRange": null,
"fixInfo": null
}
]
};
@ -1377,7 +1388,8 @@ test("customRulesAsyncIgnoresSyncReturn", (t) => {
"ruleInformation": "https://example.com/asyncRule",
"errorDetail": null,
"errorContext": null,
"errorRange": null
"errorRange": null,
"fixInfo": null
},
{
"lineNumber": 1,
@ -1386,7 +1398,11 @@ test("customRulesAsyncIgnoresSyncReturn", (t) => {
"ruleInformation": `${homepage}/blob/v${version}/doc/Rules.md#md047`,
"errorDetail": null,
"errorContext": null,
"errorRange": [ 9, 1 ]
"errorRange": [ 9, 1 ],
"fixInfo": {
"editColumn": 10,
"insertText": "\n"
}
}
]
};
@ -1440,7 +1456,8 @@ const stringScenarios = [
"ruleInformation": null,
"errorDetail": `This rule threw an exception: ${errorMessage}`,
"errorContext": null,
"errorRange": null
"errorRange": null,
"fixInfo": null
}
]
};
@ -1604,7 +1621,8 @@ const stringScenarios = [
"ruleInformation": null,
"errorDetail": `This rule threw an exception: ${errorMessage}`,
"errorContext": null,
"errorRange": null
"errorRange": null,
"fixInfo": null
}
]
};

View file

@ -39,8 +39,7 @@ async function lintTestRepo(t, globPatterns, configPath, ignoreRes) {
console.log(`${t.title}: Linting ${files.length} files...`);
return markdownlintPromise({
files,
config,
"resultVersion": 3
config
// }).then((results) => {
// // Cross-check MD051/link-fragments results with markdown-link-check
// const resultFiles = [];

View file

@ -255,7 +255,8 @@ test.cb("resultFormattingV2", (t) => {
"config": {
"MD002": true,
"MD041": false
}
},
"resultVersion": 2
};
markdownlint(options, function callback(err, actualResult) {
t.falsy(err);

View file

@ -44,8 +44,7 @@ function createTestForFile(file) {
function lintWithConfig() {
return markdownlintPromise({
"files": [ file ],
config,
"resultVersion": 3
config
});
})
.then(
@ -54,8 +53,7 @@ function createTestForFile(file) {
Promise.all([
markdownlintPromise({
"files": [ file ],
config,
"resultVersion": 3
config
}),
fs.promises.readFile(file, "utf8"),
fs.promises.readFile(fixedFile, "utf8")
@ -148,8 +146,7 @@ function createTestForFile(file) {
"strings": {
"input": corrections
},
config,
"resultVersion": 3
config
});
})
.then(