mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Add MD014 with tests.
This commit is contained in:
parent
434c7f388c
commit
62314e61b1
4 changed files with 55 additions and 3 deletions
|
|
@ -18,7 +18,7 @@ function lintFile(file, config, callback) {
|
||||||
callback(err);
|
callback(err);
|
||||||
} else {
|
} else {
|
||||||
var tokens = md.parse(contents, {});
|
var tokens = md.parse(contents, {});
|
||||||
var lines = contents.split(/\r\n|\r|\n/g);
|
var lines = contents.split(/\r\n|\r|\n/);
|
||||||
tokens.forEach(function forToken(token) {
|
tokens.forEach(function forToken(token) {
|
||||||
if (token.lines) {
|
if (token.lines) {
|
||||||
token.line = lines[token.lines[0]];
|
token.line = lines[token.lines[0]];
|
||||||
|
|
|
||||||
21
lib/rules.js
21
lib/rules.js
|
|
@ -216,7 +216,7 @@ module.exports = [
|
||||||
var exclusions = [];
|
var exclusions = [];
|
||||||
filterTokens(params.tokens, "code_block", "fence")
|
filterTokens(params.tokens, "code_block", "fence")
|
||||||
.forEach(function forToken(token) {
|
.forEach(function forToken(token) {
|
||||||
for (var i = token.lines[0] ; i < token.lines[1] ; i++) {
|
for (var i = token.lines[0]; i < token.lines[1]; i++) {
|
||||||
exclusions.push(i);
|
exclusions.push(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -246,6 +246,25 @@ module.exports = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "MD014",
|
||||||
|
"desc": "Dollar signs used before commands without showing output",
|
||||||
|
"func": function MD014(params, errors) {
|
||||||
|
filterTokens(params.tokens, "code_block", "fence")
|
||||||
|
.forEach(function forToken(token) {
|
||||||
|
if (token.content && token.content
|
||||||
|
.split(/\r\n|\r|\n/)
|
||||||
|
.filter(function filterLine(line) {
|
||||||
|
return line;
|
||||||
|
}).every(function forLine(line) {
|
||||||
|
return /^\$\s/.test(line);
|
||||||
|
})) {
|
||||||
|
errors.push(token.lines[0] + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "MD028",
|
"name": "MD028",
|
||||||
"desc": "Blank line inside blockquote",
|
"desc": "Blank line inside blockquote",
|
||||||
|
|
|
||||||
33
test/code_block_dollar.md
Normal file
33
test/code_block_dollar.md
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
The following code block shouldn't have $ before the commands:
|
||||||
|
|
||||||
|
$ ls {MD014}
|
||||||
|
$ less foo
|
||||||
|
|
||||||
|
$ cat bar
|
||||||
|
|
||||||
|
However the following code block shows output, and $ can be used to
|
||||||
|
distinguish between command and output:
|
||||||
|
|
||||||
|
$ ls
|
||||||
|
foo bar
|
||||||
|
$ less foo
|
||||||
|
Hello world
|
||||||
|
|
||||||
|
$ cat bar
|
||||||
|
baz
|
||||||
|
|
||||||
|
The following code block uses variable names, and likewise shouldn't fire:
|
||||||
|
|
||||||
|
$foo = 'bar';
|
||||||
|
$baz = 'qux';
|
||||||
|
|
||||||
|
The following code block doesn't have any dollar signs, and shouldn't fire:
|
||||||
|
|
||||||
|
ls foo
|
||||||
|
cat bar
|
||||||
|
|
||||||
|
The following (fenced) code block doesn't have any content at all, and
|
||||||
|
shouldn't fire:
|
||||||
|
|
||||||
|
```
|
||||||
|
```
|
||||||
|
|
@ -31,7 +31,7 @@ function createTestForFile(file) {
|
||||||
var expectedPromise = Q.nfcall(fs.readFile, file, { "encoding": "utf8" })
|
var expectedPromise = Q.nfcall(fs.readFile, file, { "encoding": "utf8" })
|
||||||
.then(
|
.then(
|
||||||
function fileContents(contents) {
|
function fileContents(contents) {
|
||||||
var lines = contents.split(/\r\n|\r|\n/g);
|
var lines = contents.split(/\r\n|\r|\n/);
|
||||||
var results = {};
|
var results = {};
|
||||||
lines.forEach(function forLine(line, lineNum) {
|
lines.forEach(function forLine(line, lineNum) {
|
||||||
var regex = /\{(MD\d+)(?::(\d+))?\}/g;
|
var regex = /\{(MD\d+)(?::(\d+))?\}/g;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue