mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +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 {
|
||||
var lines = contents.split(/\r\n|\n/g);
|
||||
var result = {};
|
||||
Object.keys(rules).forEach(function forRule(name) {
|
||||
var rule = rules[name];
|
||||
var errors = rule(lines);
|
||||
rules.forEach(function forRule(rule) {
|
||||
var errors = rule.func(lines);
|
||||
if (errors.length) {
|
||||
errors.sort(numberComparison);
|
||||
result[name] = errors.filter(uniqueFilterForSorted);
|
||||
result[rule.name] = errors.filter(uniqueFilterForSorted);
|
||||
}
|
||||
});
|
||||
callback(null, result);
|
||||
|
|
|
|||
88
lib/rules.js
88
lib/rules.js
|
|
@ -9,48 +9,56 @@ function padAndTrim(lines) {
|
|||
"");
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
"MD031": function MD031(lines) {
|
||||
// Some parsers have trouble detecting fenced code blocks without
|
||||
// surrounding whitespace, so examine the lines directly.
|
||||
lines = padAndTrim(lines);
|
||||
var errors = [];
|
||||
var inCode = false;
|
||||
lines.forEach(function forLine(line, lineNum) {
|
||||
if (line.match(/^(```|~~~)/)) {
|
||||
inCode = !inCode;
|
||||
if ((inCode && lines[lineNum - 1].length) ||
|
||||
(!inCode && lines[lineNum + 1].length)) {
|
||||
errors.push(lineNum);
|
||||
module.exports = [
|
||||
{
|
||||
"name": "MD031",
|
||||
"desc": "Fenced code blocks should be surrounded by blank lines",
|
||||
"func": function MD031(lines) {
|
||||
// Some parsers have trouble detecting fenced code blocks without
|
||||
// surrounding whitespace, so examine the lines directly.
|
||||
lines = padAndTrim(lines);
|
||||
var errors = [];
|
||||
var inCode = false;
|
||||
lines.forEach(function forLine(line, lineNum) {
|
||||
if (line.match(/^(```|~~~)/)) {
|
||||
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
|
||||
// whitespace, so examine the lines directly.
|
||||
var errors = [];
|
||||
var inList = false;
|
||||
var inCode = false;
|
||||
var prevLine = "";
|
||||
lines.forEach(function forLine(line, lineNum) {
|
||||
if (!inCode) {
|
||||
var listMarker = line.trim().match(/^([\*\+\-]|(\d+\.))\s/);
|
||||
if (listMarker && !inList && !prevLine.match(/^($|\s)/)) {
|
||||
errors.push(lineNum + 1);
|
||||
} else if (!listMarker && inList && !line.match(/^($|\s)/)) {
|
||||
errors.push(lineNum);
|
||||
{
|
||||
"name": "MD032",
|
||||
"desc": "Lists should be surrounded by blank lines",
|
||||
"func": function MD032(lines) {
|
||||
// Some parsers have trouble detecting lists without surrounding
|
||||
// whitespace, so examine the lines directly.
|
||||
var errors = [];
|
||||
var inList = false;
|
||||
var inCode = false;
|
||||
var prevLine = "";
|
||||
lines.forEach(function forLine(line, lineNum) {
|
||||
if (!inCode) {
|
||||
var listMarker = line.trim().match(/^([\*\+\-]|(\d+\.))\s/);
|
||||
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;
|
||||
inList = false;
|
||||
}
|
||||
prevLine = line;
|
||||
});
|
||||
return errors;
|
||||
if (line.trim().match(/^(```|~~~)/)) {
|
||||
inCode = !inCode;
|
||||
inList = false;
|
||||
}
|
||||
prevLine = line;
|
||||
});
|
||||
return errors;
|
||||
}
|
||||
}
|
||||
};
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue