mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Add MD038, MD039 with tests.
This commit is contained in:
parent
b85e53a9c4
commit
7e431f4499
6 changed files with 98 additions and 11 deletions
|
|
@ -68,6 +68,8 @@ cases come directly from that project.
|
||||||
* **MD035** - Horizontal rule style
|
* **MD035** - Horizontal rule style
|
||||||
* **MD036** - Emphasis used instead of a header
|
* **MD036** - Emphasis used instead of a header
|
||||||
* **MD037** - Spaces inside emphasis markers
|
* **MD037** - Spaces inside emphasis markers
|
||||||
|
* **MD038** - Spaces inside code span elements
|
||||||
|
* **MD039** - Spaces inside link text
|
||||||
|
|
||||||
See [Rules.md](doc/Rules.md) for more details.
|
See [Rules.md](doc/Rules.md) for more details.
|
||||||
|
|
||||||
|
|
@ -78,7 +80,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
|
* **code** - MD014, MD031, MD038
|
||||||
* **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,
|
||||||
|
|
@ -87,12 +89,12 @@ See [Rules.md](doc/Rules.md) for more details.
|
||||||
* **html** - MD033
|
* **html** - MD033
|
||||||
* **indentation** - MD005, MD006, MD007, MD027
|
* **indentation** - MD005, MD006, MD007, MD027
|
||||||
* **line_length** - MD013
|
* **line_length** - MD013
|
||||||
* **links** - MD011, MD034
|
* **links** - MD011, MD034, MD039
|
||||||
* **ol** - MD029, MD030, MD032
|
* **ol** - MD029, MD030, MD032
|
||||||
* **spaces** - MD018, MD019, MD020, MD021, MD023
|
* **spaces** - MD018, MD019, MD020, MD021, MD023
|
||||||
* **ul** - MD004, MD005, MD006, MD007, MD030, MD032
|
* **ul** - MD004, MD005, MD006, MD007, MD030, MD032
|
||||||
* **url** - MD034
|
* **url** - MD034
|
||||||
* **whitespace** - MD009, MD010, MD012, MD027, MD028, MD030, MD037
|
* **whitespace** - MD009, MD010, MD012, MD027, MD028, MD030, MD037, MD038, MD039
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
|
|
|
||||||
29
doc/Rules.md
29
doc/Rules.md
|
|
@ -824,3 +824,32 @@ Rationale: Emphasis is only parsed as such when the asterisks/underscores
|
||||||
aren't completely surrounded by spaces. This rule attempts to detect where
|
aren't completely surrounded by spaces. This rule attempts to detect where
|
||||||
they were surrounded by spaces, but it appears that emphasized text was
|
they were surrounded by spaces, but it appears that emphasized text was
|
||||||
intended by the author.
|
intended by the author.
|
||||||
|
|
||||||
|
## MD038 - Spaces inside code span elements
|
||||||
|
|
||||||
|
Tags: whitespace, code
|
||||||
|
|
||||||
|
This rule is triggered on code span elements that have spaces right inside the
|
||||||
|
backticks:
|
||||||
|
|
||||||
|
` some text `
|
||||||
|
|
||||||
|
`some text `
|
||||||
|
|
||||||
|
` some text`
|
||||||
|
|
||||||
|
To fix this, remove the spaces inside the codespan markers:
|
||||||
|
|
||||||
|
`some text`
|
||||||
|
|
||||||
|
## MD039 - Spaces inside link text
|
||||||
|
|
||||||
|
Tags: whitespace, links
|
||||||
|
|
||||||
|
This rule is triggered on links that have spaces surrounding the link text:
|
||||||
|
|
||||||
|
[ a link ](http://www.example.com/)
|
||||||
|
|
||||||
|
To fix this, remove the spaces surrounding the link text:
|
||||||
|
|
||||||
|
[a link](http://www.example.com/)
|
||||||
|
|
|
||||||
51
lib/rules.js
51
lib/rules.js
|
|
@ -60,12 +60,14 @@ function forEachLine(params, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls the provided function for each text token
|
// Calls the provided function for each specified inline child token
|
||||||
function forEachText(params, callback) {
|
function forEachInlineChild(params, type, callback) {
|
||||||
filterTokens(params.tokens, "inline")
|
filterTokens(params.tokens, "inline")
|
||||||
.forEach(function forToken(token) {
|
.forEach(function forToken(token) {
|
||||||
filterTokens(token.children, "text")
|
filterTokens(token.children, type)
|
||||||
.forEach(callback);
|
.forEach(function forChild(child) {
|
||||||
|
callback(child, token);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,7 +277,7 @@ module.exports = [
|
||||||
"desc": "Reversed link syntax",
|
"desc": "Reversed link syntax",
|
||||||
"tags": [ "links" ],
|
"tags": [ "links" ],
|
||||||
"func": function MD011(params, errors) {
|
"func": function MD011(params, errors) {
|
||||||
forEachText(params, function forToken(token) {
|
forEachInlineChild(params, "text", function forToken(token) {
|
||||||
if (/\([^)]+\)\[[^\]]+\]/.test(token.content)) {
|
if (/\([^)]+\)\[[^\]]+\]/.test(token.content)) {
|
||||||
errors.push(token.lineNumber);
|
errors.push(token.lineNumber);
|
||||||
}
|
}
|
||||||
|
|
@ -706,12 +708,49 @@ module.exports = [
|
||||||
"desc": "Spaces inside emphasis markers",
|
"desc": "Spaces inside emphasis markers",
|
||||||
"tags": [ "whitespace", "emphasis" ],
|
"tags": [ "whitespace", "emphasis" ],
|
||||||
"func": function MD037(params, errors) {
|
"func": function MD037(params, errors) {
|
||||||
forEachText(params, function forToken(token) {
|
forEachInlineChild(params, "text", function forToken(token) {
|
||||||
if (/\s(\*\*?|__?)\s.+\1/.test(token.content) ||
|
if (/\s(\*\*?|__?)\s.+\1/.test(token.content) ||
|
||||||
/(\*\*?|__?).+\s\1\s/.test(token.content)) {
|
/(\*\*?|__?).+\s\1\s/.test(token.content)) {
|
||||||
errors.push(token.lineNumber);
|
errors.push(token.lineNumber);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "MD038",
|
||||||
|
"desc": "Spaces inside code span elements",
|
||||||
|
"tags": [ "whitespace", "code" ],
|
||||||
|
"func": function MD038(params, errors) {
|
||||||
|
forEachInlineChild(params, "code_inline",
|
||||||
|
function forToken(token, inline) {
|
||||||
|
if (inline.content.indexOf("`" + token.content + "`") === -1) {
|
||||||
|
errors.push(token.lineNumber);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "MD039",
|
||||||
|
"desc": "Spaces inside link text",
|
||||||
|
"tags": [ "whitespace", "links" ],
|
||||||
|
"func": function MD039(params, errors) {
|
||||||
|
filterTokens(params.tokens, "inline")
|
||||||
|
.forEach(function forToken(token) {
|
||||||
|
var inLink = false;
|
||||||
|
token.children.forEach(function forChild(child) {
|
||||||
|
if (child.type === "link_open") {
|
||||||
|
inLink = true;
|
||||||
|
} else if (child.type === "link_close") {
|
||||||
|
inLink = false;
|
||||||
|
} else if ((child.type === "text") &&
|
||||||
|
inLink &&
|
||||||
|
(child.content.trim().length !== child.content.length)) {
|
||||||
|
errors.push(child.lineNumber);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -498,7 +498,7 @@ module.exports.badFileSync = function badFileSync(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.readme = function readme(test) {
|
module.exports.readme = function readme(test) {
|
||||||
test.expect(88);
|
test.expect(92);
|
||||||
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(135);
|
test.expect(143);
|
||||||
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);
|
||||||
|
|
|
||||||
7
test/spaces_inside_codespan_elements.md
Normal file
7
test/spaces_inside_codespan_elements.md
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
`normal codespan element`
|
||||||
|
|
||||||
|
` codespan element with space inside left` {MD038}
|
||||||
|
|
||||||
|
`codespan element with space inside right ` {MD038}
|
||||||
|
|
||||||
|
` codespan element with spaces inside ` {MD038}
|
||||||
10
test/spaces_inside_link_text.md
Normal file
10
test/spaces_inside_link_text.md
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
[foo](http://bar/)
|
||||||
|
|
||||||
|
[foo ](http://bar/) {MD039}
|
||||||
|
|
||||||
|
[ foo](http://bar/) {MD039}
|
||||||
|
|
||||||
|
[ foo ](http://bar/) {MD039}
|
||||||
|
|
||||||
|
The following shouldn't break anything:
|
||||||
|
[](/images/Screenshot.png)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue