mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Hook up ESLint, fix warnings (including conversion to async I/O).
This commit is contained in:
parent
d16e1cafc1
commit
160146ac3a
5 changed files with 230 additions and 41 deletions
|
|
@ -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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue