Add MD040 with tests.

This commit is contained in:
David Anson 2015-04-16 09:13:56 -07:00
parent 7e431f4499
commit 5d6d9d2b3b
10 changed files with 54 additions and 7 deletions

View file

@ -70,6 +70,7 @@ cases come directly from that project.
* **MD037** - Spaces inside emphasis markers
* **MD038** - Spaces inside code span elements
* **MD039** - Spaces inside link text
* **MD040** - Fenced code blocks should have a language specified
See [Rules.md](doc/Rules.md) for more details.
@ -80,7 +81,7 @@ See [Rules.md](doc/Rules.md) for more details.
* **blank_lines** - MD012, MD022, MD031, MD032
* **blockquote** - MD027, MD028
* **bullet** - MD004, MD005, MD006, MD007, MD032
* **code** - MD014, MD031, MD038
* **code** - MD014, MD031, MD038, MD040
* **emphasis** - MD036, MD037
* **hard_tab** - MD010
* **headers** - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022, MD023,
@ -88,6 +89,7 @@ See [Rules.md](doc/Rules.md) for more details.
* **hr** - MD035
* **html** - MD033
* **indentation** - MD005, MD006, MD007, MD027
* **language** - MD040
* **line_length** - MD013
* **links** - MD011, MD034, MD039
* **ol** - MD029, MD030, MD032

View file

@ -853,3 +853,22 @@ This rule is triggered on links that have spaces surrounding the link text:
To fix this, remove the spaces surrounding the link text:
[a link](http://www.example.com/)
## MD040 - Fenced code blocks should have a language specified
Tags: code, language
This rule is triggered when fenced code blocks are used, but a language isn't
specified:
```
#!/bin/bash
echo Hello world
```
To fix this, add a language specifier to the code block:
```bash
#!/bin/bash
echo Hello world
```

View file

@ -752,5 +752,19 @@ module.exports = [
});
});
}
},
{
"name": "MD040",
"desc": "Fenced code blocks should have a language specified",
"tags": [ "code", "language" ],
"func": function MD040(params, errors) {
filterTokens(params.tokens, "fence")
.forEach(function forToken(token) {
if (!token.info.trim()) {
errors.push(token.lineNumber);
}
});
}
}
];

View file

@ -7,5 +7,6 @@
"MD006": false,
"MD007": false,
"MD033": false,
"MD034": false
"MD034": false,
"MD040": false
}

View file

@ -46,6 +46,6 @@ Note: Can not break MD025 and MD002 in the same file
1. list
2. list {MD029}
```
```js
``` {MD031}
* list {MD032}

View file

@ -29,5 +29,5 @@ The following code block doesn't have any dollar signs, and shouldn't fire:
The following (fenced) code block doesn't have any content at all, and
shouldn't fire:
```
```bash
```

View file

@ -19,3 +19,9 @@ echo "World"
~~~
None of the above should trigger any heading related rules.
```
Code block without a language specifier
```
{MD040:23}

View file

@ -0,0 +1,4 @@
{
"default": true,
"MD040": false
}

View file

@ -1,5 +1,6 @@
{
"default": true,
"MD004": false,
"MD029": false
"MD029": false,
"MD040": false
}

View file

@ -498,7 +498,7 @@ module.exports.badFileSync = function badFileSync(test) {
};
module.exports.readme = function readme(test) {
test.expect(92);
test.expect(95);
var tagToRules = {};
rules.forEach(function forRule(rule) {
rule.tags.forEach(function forTag(tag) {
@ -555,7 +555,7 @@ module.exports.readme = function readme(test) {
};
module.exports.doc = function doc(test) {
test.expect(143);
test.expect(147);
fs.readFile("doc/Rules.md", shared.utf8Encoding,
function readFile(err, contents) {
test.ifError(err);