mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Add code_blocks parameter to MD010 to ignore hard tabs in code blocks (fixes #31).
This commit is contained in:
parent
c2982e2972
commit
a2df7742c6
6 changed files with 87 additions and 3 deletions
|
|
@ -258,6 +258,8 @@ Tags: whitespace, hard_tab
|
||||||
|
|
||||||
Aliases: no-hard-tabs
|
Aliases: no-hard-tabs
|
||||||
|
|
||||||
|
Parameters: code_blocks (boolean; default true)
|
||||||
|
|
||||||
This rule is triggered by any lines that contain hard tab characters instead
|
This rule is triggered by any lines that contain hard tab characters instead
|
||||||
of using spaces for indentation. To fix this, replace any hard tab characters
|
of using spaces for indentation. To fix this, replace any hard tab characters
|
||||||
with spaces instead.
|
with spaces instead.
|
||||||
|
|
@ -274,6 +276,10 @@ Corrected example:
|
||||||
|
|
||||||
* Spaces used to indent the list item instead
|
* Spaces used to indent the list item instead
|
||||||
|
|
||||||
|
You have the option to exclude this rule for code blocks. To do so, set the
|
||||||
|
`code_blocks` parameter to `false`. Code blocks are included by default since
|
||||||
|
handling of tabs by tools is often inconsistent (ex: using 4 vs. 8 spaces).
|
||||||
|
|
||||||
## MD011 - Reversed link syntax
|
## MD011 - Reversed link syntax
|
||||||
|
|
||||||
Tags: links
|
Tags: links
|
||||||
|
|
|
||||||
|
|
@ -328,8 +328,10 @@ module.exports = [
|
||||||
"tags": [ "whitespace", "hard_tab" ],
|
"tags": [ "whitespace", "hard_tab" ],
|
||||||
"aliases": [ "no-hard-tabs" ],
|
"aliases": [ "no-hard-tabs" ],
|
||||||
"func": function MD010(params, errors) {
|
"func": function MD010(params, errors) {
|
||||||
params.lines.forEach(function forLine(line, lineIndex) {
|
var codeBlocks = params.options.code_blocks;
|
||||||
if (/\t/.test(line)) {
|
var includeCodeBlocks = (codeBlocks === undefined) ? true : !!codeBlocks;
|
||||||
|
forEachLine(params, function forLine(line, lineIndex, inCode) {
|
||||||
|
if (/\t/.test(line) && (!inCode || includeCodeBlocks)) {
|
||||||
errors.push(lineIndex + 1);
|
errors.push(lineIndex + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
6
test/code-block-with-tabs-allowed.json
Normal file
6
test/code-block-with-tabs-allowed.json
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD010": {
|
||||||
|
"code_blocks": false
|
||||||
|
}
|
||||||
|
}
|
||||||
35
test/code-block-with-tabs-allowed.md
Normal file
35
test/code-block-with-tabs-allowed.md
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Heading
|
||||||
|
|
||||||
|
```js
|
||||||
|
if (true) {
|
||||||
|
console.log("true");
|
||||||
|
if (false) {
|
||||||
|
console.log("false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
if (true) {
|
||||||
|
console.log("true");
|
||||||
|
if (false) {
|
||||||
|
console.log("false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
console.log("true");
|
||||||
|
if (false) {
|
||||||
|
console.log("false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
console.log("true");
|
||||||
|
if (false) {
|
||||||
|
console.log("false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Line with hard tab. {MD010}
|
||||||
35
test/code-block-with-tabs.md
Normal file
35
test/code-block-with-tabs.md
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Heading
|
||||||
|
|
||||||
|
```js
|
||||||
|
if (true) {
|
||||||
|
console.log("true");
|
||||||
|
if (false) {
|
||||||
|
console.log("false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
if (true) {
|
||||||
|
console.log("true"); // {MD010}
|
||||||
|
if (false) { // {MD010}
|
||||||
|
console.log("false"); // {MD010}
|
||||||
|
} // {MD010}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
console.log("true");
|
||||||
|
if (false) {
|
||||||
|
console.log("false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) { // {MD010}
|
||||||
|
console.log("true"); // {MD010}
|
||||||
|
if (false) { // {MD010}
|
||||||
|
console.log("false"); // {MD010}
|
||||||
|
} // {MD010}
|
||||||
|
} // {MD010}
|
||||||
|
|
||||||
|
Line with hard tab. {MD010}
|
||||||
|
|
@ -857,7 +857,7 @@ module.exports.readme = function readme(test) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.doc = function doc(test) {
|
module.exports.doc = function doc(test) {
|
||||||
test.expect(293);
|
test.expect(294);
|
||||||
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