mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Fix bug in MD022 where it could report errors on line 0, add tests.
This commit is contained in:
parent
bb0d8a36b3
commit
c98660c492
3 changed files with 21 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
1
test/md022-line-number-out-of-range.md
Normal file
1
test/md022-line-number-out-of-range.md
Normal file
|
@ -0,0 +1 @@
|
|||
--
|
Loading…
Add table
Add a link
Reference in a new issue