mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01: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)
|
token.content.split(shared.newLineRe)
|
||||||
.forEach(function forLine(line, offset) {
|
.forEach(function forLine(line, offset) {
|
||||||
if (/^(-+|=+)\s*$/.test(line)) {
|
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) {
|
module.exports.typeAllFiles = function typeAllFiles(test) {
|
||||||
// Simulates typing each test file to validate handling of partial input
|
// 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");
|
var files = fs.readdirSync("./test");
|
||||||
files.forEach(function forFile(file) {
|
files.forEach(function forFile(file) {
|
||||||
if (/\.md$/.test(file)) {
|
if (/\.md$/.test(file)) {
|
||||||
var content = fs.readFileSync(
|
var content = fs.readFileSync(
|
||||||
path.join("./test", file), shared.utf8Encoding);
|
path.join("./test", file), shared.utf8Encoding);
|
||||||
while (content) {
|
while (content) {
|
||||||
markdownlint.sync({
|
validate(file, content);
|
||||||
"strings": {
|
|
||||||
"content": content
|
|
||||||
}
|
|
||||||
});
|
|
||||||
content = content.slice(0, -1);
|
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