Change default value of options.resultVersion to 1 (breaking change).

This commit is contained in:
David Anson 2017-07-05 21:53:21 -07:00
parent 5bea80f5cd
commit 8c34383f80
6 changed files with 116 additions and 142 deletions

View file

@ -337,11 +337,11 @@ Specifies which version of the `result` object to return (see the "Usage" sectio
below for examples).
Passing a `resultVersion` of `0` corresponds to the original, simple format where
each error is identified by rule name and line number. This is the default.
each error is identified by rule name and line number. This is deprecated.
Passing a `resultVersion` of `1` corresponds to a more detailed format where each
error includes information about the line number, rule name, alias, description,
as well as any additional detail or context that is available.
Passing a `resultVersion` of `1` corresponds to a detailed format where each error
includes information about the line number, rule name, alias, description, as well
as any additional detail or context that is available. This is the default.
#### callback
@ -437,31 +437,21 @@ markdownlint(options, function callback(err, result) {
Output:
```text
bad.string: 3: MD010 Hard tabs
bad.string: 1: MD018 No space after hash on atx style header
bad.string: 3: MD018 No space after hash on atx style header
bad.md: 3: MD010 Hard tabs
bad.md: 1: MD018 No space after hash on atx style header
bad.md: 3: MD018 No space after hash on atx style header
bad.string: 3: MD010/no-hard-tabs Hard tabs [Column: 19]
bad.string: 1: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#bad.string"]
bad.string: 3: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#This string fails some rules."]
bad.string: 1: MD041/first-line-h1 First line in file should be a top level header [Context: "#bad.string"]
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#bad.md"]
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#This file fails some rules."]
bad.md: 1: MD041/first-line-h1 First line in file should be a top level header [Context: "#bad.md"]
```
Or invoke `markdownlint.sync` for a synchronous call and/or pass `true` to `toString`
to use rule aliases instead of names:
Or invoke `markdownlint.sync` for a synchronous call:
```js
var result = markdownlint.sync(options);
console.log(result.toString(true));
```
Output:
```text
bad.string: 3: no-hard-tabs Hard tabs
bad.string: 1: no-missing-space-atx No space after hash on atx style header
bad.string: 3: no-missing-space-atx No space after hash on atx style header
bad.md: 3: no-hard-tabs Hard tabs
bad.md: 1: no-missing-space-atx No space after hash on atx style header
bad.md: 3: no-missing-space-atx No space after hash on atx style header
console.log(result.toString());
```
To examine the `result` object directly:
@ -469,45 +459,13 @@ To examine the `result` object directly:
```js
markdownlint(options, function callback(err, result) {
if (!err) {
console.dir(result, { "colors": true });
console.dir(result, { "colors": true, "depth": null });
}
});
```
Output:
```json
{
"good.md": {},
"bad.md": {
"MD010": [ 3 ],
"MD018": [ 1, 3 ]
}
}
```
For more detailed error reporting, set `options.resultVersion` to `1`:
```js
var options = {
"files": [ "good.md", "bad.md" ],
"resultVersion": 1
};
```
With that, the output of `result.toString` looks like:
```text
bad.string: 3: MD010/no-hard-tabs Hard tabs [Column: 19]
bad.string: 1: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#bad.string"]
bad.string: 3: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#This string fails some rules."]
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#bad.md"]
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#This file fails some rules."]
```
And the `result` object becomes:
```json
{
"good.md": [],
@ -532,7 +490,14 @@ And the `result` object becomes:
"ruleDescription": "No space after hash on atx style header",
"errorDetail": null,
"errorContext": "#This file fails\tsome rules.",
"errorRange": [ 1, 2 ] }
"errorRange": [ 1, 2 ] },
{ "lineNumber": 1,
"ruleName": "MD041",
"ruleAlias": "first-line-h1",
"ruleDescription": "First line in file should be a top level header",
"errorDetail": null,
"errorContext": "#bad.md",
"errorRange": null }
]
}
```
@ -564,9 +529,10 @@ Output:
```text
[00:00:00] Starting 'markdownlint'...
bad.md: 3: MD010 Hard tabs
bad.md: 1: MD018 No space after hash on atx style header
bad.md: 3: MD018 No space after hash on atx style header
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#bad.md"]
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#This file fails some rules."]
bad.md: 1: MD041/first-line-h1 First line in file should be a top level header [Context: "#bad.md"]
[00:00:00] Finished 'markdownlint' after 10 ms
```
@ -604,9 +570,10 @@ Output:
```text
Running "markdownlint:example" (markdownlint) task
Warning:
bad.md: 3: MD010 Hard tabs
bad.md: 1: MD018 No space after hash on atx style header
bad.md: 3: MD018 No space after hash on atx style header
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#bad.md"]
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style header [Context: "#This file fails some rules."]
bad.md: 1: MD041/first-line-h1 First line in file should be a top level header [Context: "#bad.md"]
Use --force to continue.
```

View file

@ -47,8 +47,7 @@
},
"config": {
"MD013": false
},
"resultVersion": 1
}
};
var results = window.markdownlint.sync(options);
violations.innerHTML = results.content.map(function mapResult(result) {

View file

@ -10,28 +10,20 @@ var options = {
}
};
// Uses result.toString for pretty formatting
// Makes a synchronous call, using result.toString for pretty formatting
var result = markdownlint.sync(options);
console.log(result.toString());
// Makes an asynchronous call
markdownlint(options, function callback(err, result) {
if (!err) {
console.log(result.toString());
}
});
// Examines the result object directly
// Displays the result object directly
markdownlint(options, function callback(err, result) {
if (!err) {
console.dir(result, { "colors": true, "depth": null });
}
});
// Again, using resultVersion 1 for more detail
options.resultVersion = 1;
markdownlint(options, function callback(err, result) {
if (!err) {
console.dir(result, { "colors": true, "depth": null });
}
});
// Make a synchronous call, passing true to toString()
var result = markdownlint.sync(options);
console.log(result.toString(true));

View file

@ -213,7 +213,7 @@ function lintContent(
"frontMatterLines": frontMatterLines
};
// Run each rule
var result = (resultVersion === 1) ? [] : {};
var result = (resultVersion === 0) ? {} : [];
rules.forEach(function forRule(rule) {
// Configure rule
params.options = mergedRules[rule.name];
@ -258,42 +258,42 @@ function lintContent(
return enabledRulesPerLineNumber[error.lineNumber][rule.name];
})
.map(function formatResults(error) {
if (resultVersion === 1) {
var range = null;
var regexp = rule.regexp;
if (regexp) {
if (typeof regexp === "function") {
regexp = regexp(params.options);
}
var lineIndex = error.lineNumber - frontMatterLines.length - 1;
var match = lines[lineIndex].match(regexp);
if (match) {
var column = match.index + 1;
var length = match[0].length;
if (match[2]) {
column += match[1].length;
length -= match[1].length;
}
range = [ column, length ];
}
}
return {
"lineNumber": error.lineNumber,
"ruleName": rule.name,
"ruleAlias": rule.aliases[0],
"ruleDescription": rule.desc,
"errorDetail": error.detail,
"errorContext": error.context,
"errorRange": range
};
if (resultVersion === 0) {
return error.lineNumber;
}
return error.lineNumber;
var range = null;
var regexp = rule.regexp;
if (regexp) {
if (typeof regexp === "function") {
regexp = regexp(params.options);
}
var lineIndex = error.lineNumber - frontMatterLines.length - 1;
var match = lines[lineIndex].match(regexp);
if (match) {
var column = match.index + 1;
var length = match[0].length;
if (match[2]) {
column += match[1].length;
length -= match[1].length;
}
range = [ column, length ];
}
}
return {
"lineNumber": error.lineNumber,
"ruleName": rule.name,
"ruleAlias": rule.aliases[0],
"ruleDescription": rule.desc,
"errorDetail": error.detail,
"errorContext": error.context,
"errorRange": range
};
});
if (filteredErrors.length) {
if (resultVersion === 1) {
result.push.apply(result, filteredErrors);
} else {
if (resultVersion === 0) {
result[rule.name] = filteredErrors;
} else {
result.push.apply(result, filteredErrors);
}
}
}
@ -356,7 +356,8 @@ function markdownlint(options, callback) {
var frontMatter = (options.frontMatter === undefined) ?
shared.frontMatterRe : options.frontMatter;
var noInlineConfig = !!options.noInlineConfig;
var resultVersion = options.resultVersion || 0;
var resultVersion = (options.resultVersion === undefined) ?
1 : options.resultVersion;
var synchronous = (callback === markdownlintSynchronousCallback);
var results = new Results();
// Helper to lint the next file in the array

View file

@ -12,7 +12,8 @@ module.exports.typeTestFiles = function typeTestFiles(test) {
var results = markdownlint.sync({
"strings": {
"content": content
}
},
"resultVersion": 0
});
var contentLineCount = content.split(shared.newLineRe).length;
Object.keys(results.content).forEach(function forKey(ruleName) {

View file

@ -91,7 +91,7 @@ module.exports.projectFiles = function projectFiles(test) {
};
markdownlint(options, function callback(err, actual) {
test.ifError(err);
var expected = { "README.md": {} };
var expected = { "README.md": [] };
test.deepEqual(actual, expected, "Issue(s) with project files.");
test.done();
});
@ -104,7 +104,8 @@ module.exports.resultFormattingV0 = function resultFormattingV0(test) {
"./test/atx_header_spacing.md",
"./test/first_header_bad_atx.md"
],
"config": defaultConfig
"config": defaultConfig,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -211,8 +212,7 @@ module.exports.resultFormattingV1 = function resultFormattingV1(test) {
"./test/atx_header_spacing.md",
"./test/first_header_bad_atx.md"
],
"config": defaultConfig,
"resultVersion": 1
"config": defaultConfig
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -334,7 +334,8 @@ module.exports.stringInputLineEndings = function stringInputLineEndings(test) {
"crlf": "One\r\nTwo\r\n#Three",
"mixed": "One\rTwo\n#Three"
},
"config": defaultConfig
"config": defaultConfig,
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -364,9 +365,9 @@ module.exports.inputOnlyNewline = function inputOnlyNewline(test) {
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
var expectedResult = {
"cr": {},
"lf": {},
"crlf": {}
"cr": [],
"lf": [],
"crlf": []
};
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
test.done();
@ -382,7 +383,8 @@ module.exports.defaultTrue = function defaultTrue(test) {
],
"config": {
"default": true
}
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -412,7 +414,8 @@ module.exports.defaultFalse = function defaultFalse(test) {
],
"config": {
"default": false
}
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -432,7 +435,8 @@ module.exports.defaultUndefined = function defaultUndefined(test) {
"./test/atx_header_spacing.md",
"./test/first_header_bad_atx.md"
],
"config": {}
"config": {},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -465,7 +469,8 @@ module.exports.disableRules = function disableRules(test) {
"default": true,
"MD019": false,
"first-line-h1": false
}
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -491,7 +496,8 @@ module.exports.enableRules = function enableRules(test) {
"MD002": true,
"default": false,
"no-multiple-space-atx": true
}
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -520,7 +526,8 @@ module.exports.enableRulesMixedCase = function enableRulesMixedCase(test) {
"Md002": true,
"DeFaUlT": false,
"nO-mUlTiPlE-sPaCe-AtX": true
}
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -548,7 +555,8 @@ module.exports.disableTag = function disableTag(test) {
"config": {
"default": true,
"spaces": false
}
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -578,7 +586,8 @@ module.exports.enableTag = function enableTag(test) {
"default": false,
"spaces": true,
"notatag": true
}
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -605,7 +614,8 @@ module.exports.enableTagMixedCase = function enableTagMixedCase(test) {
"DeFaUlT": false,
"SpAcEs": true,
"NoTaTaG": true
}
},
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -636,7 +646,8 @@ module.exports.styleAll = function styleAll(test) {
test.expect(2);
var options = {
"files": [ "./test/break-all-the-rules.md" ],
"config": require("../style/all.json")
"config": require("../style/all.json"),
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -690,7 +701,8 @@ module.exports.styleRelaxed = function styleRelaxed(test) {
test.expect(2);
var options = {
"files": [ "./test/break-all-the-rules.md" ],
"config": require("../style/relaxed.json")
"config": require("../style/relaxed.json"),
"resultVersion": 0
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
@ -734,7 +746,8 @@ module.exports.nullFrontMatter = function nullFrontMatter(test) {
"config": {
"default": false,
"MD010": true
}
},
"resultVersion": 0
}, function callback(err, result) {
test.ifError(err);
var expectedResult = {
@ -759,7 +772,7 @@ module.exports.customFrontMatter = function customFrontMatter(test) {
}, function callback(err, result) {
test.ifError(err);
var expectedResult = {
"content": {}
"content": []
};
test.deepEqual(result, expectedResult, "Did not get empty results.");
test.done();
@ -784,7 +797,8 @@ module.exports.noInlineConfig = function noInlineConfig(test) {
"\tTab"
].join("\n")
},
"noInlineConfig": true
"noInlineConfig": true,
"resultVersion": 0
}, function callback(err, result) {
test.ifError(err);
var expectedResult = {
@ -840,7 +854,7 @@ module.exports.readmeHeaders = function readmeHeaders(test) {
}
}, function callback(err, result) {
test.ifError(err);
var expected = { "README.md": {} };
var expected = { "README.md": [] };
test.deepEqual(result, expected, "Unexpected issues.");
test.done();
});
@ -871,7 +885,7 @@ module.exports.filesArrayAsString = function filesArrayAsString(test) {
}
}, function callback(err, actual) {
test.ifError(err);
var expected = { "README.md": {} };
var expected = { "README.md": [] };
test.deepEqual(actual, expected, "Unexpected issues.");
test.done();
});
@ -941,9 +955,9 @@ module.exports.missingStringValue = function missingStringValue(test) {
}, function callback(err, result) {
test.ifError(err);
var expectedResult = {
"undefined": {},
"null": {},
"empty": {}
"undefined": [],
"null": [],
"empty": []
};
test.deepEqual(result, expectedResult, "Did not get empty results.");
test.done();