mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Change export of rules to include description.
This commit is contained in:
parent
aef1524308
commit
5d35b8dfea
2 changed files with 51 additions and 44 deletions
|
|
@ -18,12 +18,11 @@ function lintFile(file, options, callback) {
|
||||||
} else {
|
} else {
|
||||||
var lines = contents.split(/\r\n|\n/g);
|
var lines = contents.split(/\r\n|\n/g);
|
||||||
var result = {};
|
var result = {};
|
||||||
Object.keys(rules).forEach(function forRule(name) {
|
rules.forEach(function forRule(rule) {
|
||||||
var rule = rules[name];
|
var errors = rule.func(lines);
|
||||||
var errors = rule(lines);
|
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
errors.sort(numberComparison);
|
errors.sort(numberComparison);
|
||||||
result[name] = errors.filter(uniqueFilterForSorted);
|
result[rule.name] = errors.filter(uniqueFilterForSorted);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
callback(null, result);
|
callback(null, result);
|
||||||
|
|
|
||||||
88
lib/rules.js
88
lib/rules.js
|
|
@ -9,48 +9,56 @@ function padAndTrim(lines) {
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = [
|
||||||
"MD031": function MD031(lines) {
|
{
|
||||||
// Some parsers have trouble detecting fenced code blocks without
|
"name": "MD031",
|
||||||
// surrounding whitespace, so examine the lines directly.
|
"desc": "Fenced code blocks should be surrounded by blank lines",
|
||||||
lines = padAndTrim(lines);
|
"func": function MD031(lines) {
|
||||||
var errors = [];
|
// Some parsers have trouble detecting fenced code blocks without
|
||||||
var inCode = false;
|
// surrounding whitespace, so examine the lines directly.
|
||||||
lines.forEach(function forLine(line, lineNum) {
|
lines = padAndTrim(lines);
|
||||||
if (line.match(/^(```|~~~)/)) {
|
var errors = [];
|
||||||
inCode = !inCode;
|
var inCode = false;
|
||||||
if ((inCode && lines[lineNum - 1].length) ||
|
lines.forEach(function forLine(line, lineNum) {
|
||||||
(!inCode && lines[lineNum + 1].length)) {
|
if (line.match(/^(```|~~~)/)) {
|
||||||
errors.push(lineNum);
|
inCode = !inCode;
|
||||||
|
if ((inCode && lines[lineNum - 1].length) ||
|
||||||
|
(!inCode && lines[lineNum + 1].length)) {
|
||||||
|
errors.push(lineNum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
return errors;
|
||||||
return errors;
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"MD032": function MD032(lines) {
|
{
|
||||||
// Some parsers have trouble detecting lists without surrounding
|
"name": "MD032",
|
||||||
// whitespace, so examine the lines directly.
|
"desc": "Lists should be surrounded by blank lines",
|
||||||
var errors = [];
|
"func": function MD032(lines) {
|
||||||
var inList = false;
|
// Some parsers have trouble detecting lists without surrounding
|
||||||
var inCode = false;
|
// whitespace, so examine the lines directly.
|
||||||
var prevLine = "";
|
var errors = [];
|
||||||
lines.forEach(function forLine(line, lineNum) {
|
var inList = false;
|
||||||
if (!inCode) {
|
var inCode = false;
|
||||||
var listMarker = line.trim().match(/^([\*\+\-]|(\d+\.))\s/);
|
var prevLine = "";
|
||||||
if (listMarker && !inList && !prevLine.match(/^($|\s)/)) {
|
lines.forEach(function forLine(line, lineNum) {
|
||||||
errors.push(lineNum + 1);
|
if (!inCode) {
|
||||||
} else if (!listMarker && inList && !line.match(/^($|\s)/)) {
|
var listMarker = line.trim().match(/^([\*\+\-]|(\d+\.))\s/);
|
||||||
errors.push(lineNum);
|
if (listMarker && !inList && !prevLine.match(/^($|\s)/)) {
|
||||||
|
errors.push(lineNum + 1);
|
||||||
|
} else if (!listMarker && inList && !line.match(/^($|\s)/)) {
|
||||||
|
errors.push(lineNum);
|
||||||
|
}
|
||||||
|
inList = listMarker;
|
||||||
}
|
}
|
||||||
inList = listMarker;
|
if (line.trim().match(/^(```|~~~)/)) {
|
||||||
}
|
inCode = !inCode;
|
||||||
if (line.trim().match(/^(```|~~~)/)) {
|
inList = false;
|
||||||
inCode = !inCode;
|
}
|
||||||
inList = false;
|
prevLine = line;
|
||||||
}
|
});
|
||||||
prevLine = line;
|
return errors;
|
||||||
});
|
}
|
||||||
return errors;
|
|
||||||
}
|
}
|
||||||
};
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue