mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add MD003 with tests, add JSON config for rules.
This commit is contained in:
parent
75b63a43ab
commit
a2d42b6208
14 changed files with 266 additions and 36 deletions
|
|
@ -4,34 +4,50 @@ var fs = require("fs");
|
|||
var path = require("path");
|
||||
var markdownlint = require("../lib/markdownlint");
|
||||
|
||||
var encodingUtf8 = { "encoding": "utf8" };
|
||||
|
||||
function createTestForFile(file) {
|
||||
return function testForFile(test) {
|
||||
test.expect(3);
|
||||
fs.readFile(
|
||||
file,
|
||||
{ "encoding": "utf8" },
|
||||
function readFileCallback(err, contents) {
|
||||
test.expect(4);
|
||||
fs.readFile(file, encodingUtf8, function readFileCallback(err, contents) {
|
||||
test.ifError(err);
|
||||
var lines = contents.split(/\r\n|\r|\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;
|
||||
function lintFile(config) {
|
||||
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 ],
|
||||
"config": config
|
||||
}, function markdownlintCallback(errr, actual) {
|
||||
test.ifError(errr);
|
||||
var expected = {};
|
||||
expected[file] = results;
|
||||
test.deepEqual(actual, expected, "Line numbers are not correct.");
|
||||
test.done();
|
||||
});
|
||||
}
|
||||
var configFile = file.replace(/\.md$/, ".json");
|
||||
fs.stat(configFile, function statCallback(errr /*, stats*/) {
|
||||
if (errr) {
|
||||
test.ok(true, "Replacement for ifError of readFile");
|
||||
lintFile();
|
||||
} else {
|
||||
fs.readFile(configFile, encodingUtf8,
|
||||
function readFile(errrr, configContents) {
|
||||
test.ifError(errrr);
|
||||
var config = JSON.parse(configContents);
|
||||
lintFile(config);
|
||||
});
|
||||
}
|
||||
});
|
||||
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();
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue