Format results via toString, add test to verify.

This commit is contained in:
David Anson 2015-03-13 09:13:07 -07:00
parent f6d0986cc5
commit d3e9f83e7c
3 changed files with 64 additions and 2 deletions

View file

@ -126,7 +126,7 @@
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"max-depth": [2, 4],
"max-len": [2, 80, 2],
"max-nested-callbacks": [2, 2],
"max-nested-callbacks": [2, 3],
"max-params": [2, 4],
"max-statements": [0, 10],
"new-cap": 2,

View file

@ -5,6 +5,30 @@ var md = require("markdown-it")();
var rules = require("./rules");
var shared = require("./shared");
var ruleToDescription = {};
rules.forEach(function forRule(rule) {
ruleToDescription[rule.name] = rule.desc;
});
function Results() { }
Results.prototype.toString = function resultsToString() {
var self = this;
var results = [];
Object.keys(self).forEach(function forFile(file) {
var fileResults = self[file];
Object.keys(fileResults).forEach(function forRule(rule) {
var ruleResults = fileResults[rule];
ruleResults.forEach(function forLine(lineNumber) {
var result =
file + ": " + lineNumber + ": " +
rule + " " + ruleToDescription[rule];
results.push(result);
});
});
});
return results.join("\n");
};
function numberComparison(a, b) {
return a - b;
}
@ -55,7 +79,7 @@ module.exports = function markdownlint(options, callback) {
callback = callback || function noop() {};
var files = options.files || [];
var config = options.config || { "default": true };
var results = {};
var results = new Results();
function lintFiles() {
var file = files.shift();
if (file) {

View file

@ -80,6 +80,44 @@ module.exports.projectFiles = function projectFiles(test) {
});
};
module.exports.resultFormatting = function resultFormatting(test) {
test.expect(3);
var options = {
"files": [
"./test/atx_header_spacing.md",
"./test/first_header_bad_atx.md"
]
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
var expectedResult = {
"./test/atx_header_spacing.md": {
"MD002": [ 3 ],
"MD018": [ 1 ],
"MD019": [ 3, 5 ]
},
"./test/first_header_bad_atx.md": {
"MD002": [ 1 ]
}
};
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
var actualMessage = actualResult.toString();
var expectedMessage =
"./test/atx_header_spacing.md: 3: MD002" +
" First header should be a h1 header\n" +
"./test/atx_header_spacing.md: 1: MD018" +
" No space after hash on atx style header\n" +
"./test/atx_header_spacing.md: 3: MD019" +
" Multiple spaces after hash on atx style header\n" +
"./test/atx_header_spacing.md: 5: MD019" +
" Multiple spaces after hash on atx style header\n" +
"./test/first_header_bad_atx.md: 1: MD002" +
" First header should be a h1 header";
test.equal(actualMessage, expectedMessage, "Incorrect message.");
test.done();
});
};
module.exports.missingOptions = function missingOptions(test) {
test.expect(2);
markdownlint(null, function callback(err, result) {