mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Add MD040 with tests.
This commit is contained in:
parent
7e431f4499
commit
5d6d9d2b3b
10 changed files with 54 additions and 7 deletions
|
@ -70,6 +70,7 @@ cases come directly from that project.
|
||||||
* **MD037** - Spaces inside emphasis markers
|
* **MD037** - Spaces inside emphasis markers
|
||||||
* **MD038** - Spaces inside code span elements
|
* **MD038** - Spaces inside code span elements
|
||||||
* **MD039** - Spaces inside link text
|
* **MD039** - Spaces inside link text
|
||||||
|
* **MD040** - Fenced code blocks should have a language specified
|
||||||
|
|
||||||
See [Rules.md](doc/Rules.md) for more details.
|
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
|
* **blank_lines** - MD012, MD022, MD031, MD032
|
||||||
* **blockquote** - MD027, MD028
|
* **blockquote** - MD027, MD028
|
||||||
* **bullet** - MD004, MD005, MD006, MD007, MD032
|
* **bullet** - MD004, MD005, MD006, MD007, MD032
|
||||||
* **code** - MD014, MD031, MD038
|
* **code** - MD014, MD031, MD038, MD040
|
||||||
* **emphasis** - MD036, MD037
|
* **emphasis** - MD036, MD037
|
||||||
* **hard_tab** - MD010
|
* **hard_tab** - MD010
|
||||||
* **headers** - MD001, MD002, MD003, MD018, MD019, MD020, MD021, MD022, MD023,
|
* **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
|
* **hr** - MD035
|
||||||
* **html** - MD033
|
* **html** - MD033
|
||||||
* **indentation** - MD005, MD006, MD007, MD027
|
* **indentation** - MD005, MD006, MD007, MD027
|
||||||
|
* **language** - MD040
|
||||||
* **line_length** - MD013
|
* **line_length** - MD013
|
||||||
* **links** - MD011, MD034, MD039
|
* **links** - MD011, MD034, MD039
|
||||||
* **ol** - MD029, MD030, MD032
|
* **ol** - MD029, MD030, MD032
|
||||||
|
|
19
doc/Rules.md
19
doc/Rules.md
|
@ -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:
|
To fix this, remove the spaces surrounding the link text:
|
||||||
|
|
||||||
[a link](http://www.example.com/)
|
[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
|
||||||
|
```
|
||||||
|
|
14
lib/rules.js
14
lib/rules.js
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -7,5 +7,6 @@
|
||||||
"MD006": false,
|
"MD006": false,
|
||||||
"MD007": false,
|
"MD007": false,
|
||||||
"MD033": false,
|
"MD033": false,
|
||||||
"MD034": false
|
"MD034": false,
|
||||||
|
"MD040": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,6 @@ Note: Can not break MD025 and MD002 in the same file
|
||||||
1. list
|
1. list
|
||||||
2. list {MD029}
|
2. list {MD029}
|
||||||
|
|
||||||
```
|
```js
|
||||||
``` {MD031}
|
``` {MD031}
|
||||||
* list {MD032}
|
* list {MD032}
|
||||||
|
|
|
@ -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
|
The following (fenced) code block doesn't have any content at all, and
|
||||||
shouldn't fire:
|
shouldn't fire:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
```
|
```
|
||||||
|
|
|
@ -19,3 +19,9 @@ echo "World"
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
None of the above should trigger any heading related rules.
|
None of the above should trigger any heading related rules.
|
||||||
|
|
||||||
|
```
|
||||||
|
Code block without a language specifier
|
||||||
|
```
|
||||||
|
|
||||||
|
{MD040:23}
|
||||||
|
|
4
test/fenced_code_without_blank_lines.json
Normal file
4
test/fenced_code_without_blank_lines.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD040": false
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"default": true,
|
"default": true,
|
||||||
"MD004": false,
|
"MD004": false,
|
||||||
"MD029": false
|
"MD029": false,
|
||||||
|
"MD040": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -498,7 +498,7 @@ module.exports.badFileSync = function badFileSync(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.readme = function readme(test) {
|
module.exports.readme = function readme(test) {
|
||||||
test.expect(92);
|
test.expect(95);
|
||||||
var tagToRules = {};
|
var tagToRules = {};
|
||||||
rules.forEach(function forRule(rule) {
|
rules.forEach(function forRule(rule) {
|
||||||
rule.tags.forEach(function forTag(tag) {
|
rule.tags.forEach(function forTag(tag) {
|
||||||
|
@ -555,7 +555,7 @@ module.exports.readme = function readme(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.doc = function doc(test) {
|
module.exports.doc = function doc(test) {
|
||||||
test.expect(143);
|
test.expect(147);
|
||||||
fs.readFile("doc/Rules.md", shared.utf8Encoding,
|
fs.readFile("doc/Rules.md", shared.utf8Encoding,
|
||||||
function readFile(err, contents) {
|
function readFile(err, contents) {
|
||||||
test.ifError(err);
|
test.ifError(err);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue