Fix bug in MD022 where it could report errors on line 0, add tests.

This commit is contained in:
David Anson 2015-09-07 14:04:28 -07:00
parent bb0d8a36b3
commit c98660c492
3 changed files with 21 additions and 6 deletions

View file

@ -428,7 +428,10 @@ module.exports = [
token.content.split(shared.newLineRe)
.forEach(function forLine(line, offset) {
if (/^(-+|=+)\s*$/.test(line)) {
errors.push(token.map[0] + offset);
var seTextLineNumber = token.map[0] + offset;
if (seTextLineNumber > 0) {
errors.push(seTextLineNumber);
}
}
});
}

View file

@ -733,17 +733,28 @@ module.exports.doc = function doc(test) {
module.exports.typeAllFiles = function typeAllFiles(test) {
// Simulates typing each test file to validate handling of partial input
function validate(file, content) {
var results = markdownlint.sync({
"strings": {
"content": content
}
});
var contentLineCount = content.split(shared.newLineRe).length;
Object.keys(results.content).forEach(function forKey(ruleName) {
results.content[ruleName].forEach(function forLine(line) {
test.ok((line >= 1) && (line <= contentLineCount),
"Line number out of range: " + line +
" (" + file + ", " + content.length + ", " + ruleName + ")");
});
});
}
var files = fs.readdirSync("./test");
files.forEach(function forFile(file) {
if (/\.md$/.test(file)) {
var content = fs.readFileSync(
path.join("./test", file), shared.utf8Encoding);
while (content) {
markdownlint.sync({
"strings": {
"content": content
}
});
validate(file, content);
content = content.slice(0, -1);
}
}

View file

@ -0,0 +1 @@
--