Hook up ESLint, fix warnings (including conversion to async I/O).

This commit is contained in:
David Anson 2015-02-24 18:40:37 -08:00
parent d16e1cafc1
commit 160146ac3a
5 changed files with 230 additions and 41 deletions

View file

@ -5,31 +5,40 @@ var path = require("path");
var markdownlint = require("../lib/markdownlint");
function createTestForFile(file) {
return function(test) {
test.expect(1);
var contents = fs.readFileSync(file, { encoding: "utf8" });
var lines = contents.split(/\r\n|\n/g);
var results = {};
lines.forEach(function(line, lineNum) {
var match = line.match(/\{(MD\d+)(?::(\d+))?\}/);
if (match) {
var rule = match[1];
var lines = results[rule] || [];
lines.push(lineNum + 1);
results[rule] = lines;
}
});
var actual = markdownlint({
files: [ file ]
});
var expected = {};
expected[file] = results;
test.deepEqual(actual, expected, "Line numbers are not correct.");
test.done();
return function testForFile(test) {
test.expect(3);
fs.readFile(
file,
{ "encoding": "utf8" },
function readFileCallback(err, contents) {
test.ifError(err);
var lines = contents.split(/\r\n|\n/g);
var results = {};
lines.forEach(function forLine(line, lineNum) {
var match = line.match(/\{(MD\d+)(?::(\d+))?\}/);
if (match) {
var rule = match[1];
var errors = results[rule] || [];
errors.push(lineNum + 1);
results[rule] = errors;
}
});
markdownlint({
"files": [ file ]
}, function markdownlintCallback(errr, actual) {
test.ifError(errr);
var expected = {};
expected[file] = results;
test.deepEqual(actual, expected, "Line numbers are not correct.");
test.done();
});
});
};
}
fs.readdirSync(__dirname).forEach(function(file) {
/* eslint-disable no-sync, for synchronous test method creation */
fs.readdirSync(__dirname).forEach(function forFile(file) {
/* eslint-enable no-sync */
if (file.match(/\.md$/)) {
module.exports[file] = createTestForFile(path.join(__dirname, file));
}