mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Update MD013/line-length to support stern parameter (fixes #256).
This commit is contained in:
parent
11ea2ad5f1
commit
de86a26e4e
6 changed files with 101 additions and 5 deletions
20
doc/Rules.md
20
doc/Rules.md
|
|
@ -474,7 +474,7 @@ Tags: line_length
|
||||||
|
|
||||||
Aliases: line-length
|
Aliases: line-length
|
||||||
|
|
||||||
Parameters: line_length, heading_line_length, code_block_line_length, code_blocks, tables, headings, headers, strict (number; default 80, boolean; default true)
|
Parameters: line_length, heading_line_length, code_block_line_length, code_blocks, tables, headings, headers, strict, stern (number; default 80 for *_length, boolean; default true (except strict/stern which default false))
|
||||||
|
|
||||||
> If `headings` is not provided, `headers` (deprecated) will be used.
|
> If `headings` is not provided, `headers` (deprecated) will be used.
|
||||||
|
|
||||||
|
|
@ -484,10 +484,24 @@ up into multiple lines. To set a different maximum length for headings, use
|
||||||
`heading_line_length`. To set a different maximum length for code blocks, use
|
`heading_line_length`. To set a different maximum length for code blocks, use
|
||||||
`code_block_line_length`
|
`code_block_line_length`
|
||||||
|
|
||||||
This rule has an exception where there is no whitespace beyond the configured
|
This rule has an exception when there is no whitespace beyond the configured
|
||||||
line length. This allows you to still include items such as long URLs without
|
line length. This allows you to still include items such as long URLs without
|
||||||
being forced to break them in the middle. To disable this exception, set the
|
being forced to break them in the middle. To disable this exception, set the
|
||||||
`strict` parameter to `true`.
|
`strict` parameter to `true` to report an issue when any line is too long.
|
||||||
|
To warn for lines that are too long and could be fixed but allow lines without
|
||||||
|
spaces, set the `stern` parameter to `true`.
|
||||||
|
|
||||||
|
For example (assuming normal behavior):
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
IF THIS LINE IS THE MAXIMUM LENGTH
|
||||||
|
This line is okay because there are-no-spaces-beyond-that-length
|
||||||
|
And this line is a violation because there are
|
||||||
|
This-line-is-also-okay-because-there-are-no-spaces
|
||||||
|
```
|
||||||
|
|
||||||
|
In `strict` or `stern` modes, the two middle lines above are a violation. The
|
||||||
|
third line is a violation in `strict` mode, but allowed in `stern` mode.
|
||||||
|
|
||||||
You have the option to exclude this rule for code blocks, tables, or headings.
|
You have the option to exclude this rule for code blocks, tables, or headings.
|
||||||
To do so, set the `code_blocks`, `tables`, or `headings` parameter(s) to false.
|
To do so, set the `code_blocks`, `tables`, or `headings` parameter(s) to false.
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ const longLineRePostfixRelaxed = "}.*\\s.*$";
|
||||||
const longLineRePostfixStrict = "}.+$";
|
const longLineRePostfixStrict = "}.+$";
|
||||||
const labelRe = /^\s*\[.*[^\\]]:/;
|
const labelRe = /^\s*\[.*[^\\]]:/;
|
||||||
const linkOrImageOnlyLineRe = /^[es]*(lT?L|I)[ES]*$/;
|
const linkOrImageOnlyLineRe = /^[es]*(lT?L|I)[ES]*$/;
|
||||||
|
const sternModeRe = /^([#>\s]*\s)?\S*$/;
|
||||||
const tokenTypeMap = {
|
const tokenTypeMap = {
|
||||||
"em_open": "e",
|
"em_open": "e",
|
||||||
"em_close": "E",
|
"em_close": "E",
|
||||||
|
|
@ -33,8 +34,9 @@ module.exports = {
|
||||||
const codeLineLength =
|
const codeLineLength =
|
||||||
Number(params.config.code_block_line_length || lineLength);
|
Number(params.config.code_block_line_length || lineLength);
|
||||||
const strict = !!params.config.strict;
|
const strict = !!params.config.strict;
|
||||||
|
const stern = !!params.config.stern;
|
||||||
const longLineRePostfix =
|
const longLineRePostfix =
|
||||||
strict ? longLineRePostfixStrict : longLineRePostfixRelaxed;
|
(strict || stern) ? longLineRePostfixStrict : longLineRePostfixRelaxed;
|
||||||
const longLineRe =
|
const longLineRe =
|
||||||
new RegExp(longLineRePrefix + lineLength + longLineRePostfix);
|
new RegExp(longLineRePrefix + lineLength + longLineRePostfix);
|
||||||
const longHeadingLineRe =
|
const longHeadingLineRe =
|
||||||
|
|
@ -79,7 +81,8 @@ module.exports = {
|
||||||
(includeTables || !inTable) &&
|
(includeTables || !inTable) &&
|
||||||
(includeHeadings || !isHeading) &&
|
(includeHeadings || !isHeading) &&
|
||||||
(strict ||
|
(strict ||
|
||||||
(!includesSorted(linkOnlyLineNumbers, lineNumber) &&
|
(!(stern && sternModeRe.test(line)) &&
|
||||||
|
!includesSorted(linkOnlyLineNumbers, lineNumber) &&
|
||||||
!labelRe.test(line))) &&
|
!labelRe.test(line))) &&
|
||||||
lengthRe.test(line)) {
|
lengthRe.test(line)) {
|
||||||
addErrorDetailIf(
|
addErrorDetailIf(
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,11 @@ rules.forEach(function forRule(rule) {
|
||||||
"description": "Strict length checking",
|
"description": "Strict length checking",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"stern": {
|
||||||
|
"description": "Stern length checking",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -433,6 +433,11 @@
|
||||||
"description": "Strict length checking",
|
"description": "Strict length checking",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"stern": {
|
||||||
|
"description": "Stern length checking",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
@ -484,6 +489,11 @@
|
||||||
"description": "Strict length checking",
|
"description": "Strict length checking",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
},
|
||||||
|
"stern": {
|
||||||
|
"description": "Stern length checking",
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
|
||||||
8
test/long-lines-stern.json
Normal file
8
test/long-lines-stern.json
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"default": true,
|
||||||
|
"MD013": {
|
||||||
|
"stern": true,
|
||||||
|
"heading_line_length": 30,
|
||||||
|
"code_block_line_length": 20
|
||||||
|
}
|
||||||
|
}
|
||||||
56
test/long-lines-stern.md
Normal file
56
test/long-lines-stern.md
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
# Long Lines Stern
|
||||||
|
|
||||||
|
12345678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||||
|
|
||||||
|
This line is too long. text text text text text text text text text text text text
|
||||||
|
|
||||||
|
This line is barely too long. text text text text text text text text text text t
|
||||||
|
|
||||||
|
This line is just okay. text text text text text text text text text text text t
|
||||||
|
|
||||||
|
This line is not a problem. text text text text text text text text text text t
|
||||||
|
|
||||||
|
This line is too long. texttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
|
||||||
|
|
||||||
|
ThisLineIsOkaytexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttexttext
|
||||||
|
|
||||||
|
## This heading is way too long
|
||||||
|
|
||||||
|
## This heading is long but ok
|
||||||
|
|
||||||
|
## This heading is short + ok
|
||||||
|
|
||||||
|
## ThisTooLongHeadingIsOkaytext
|
||||||
|
|
||||||
|
```text
|
||||||
|
This code is too long
|
||||||
|
This code is a-okay.
|
||||||
|
This code is short.
|
||||||
|
ThisTooLongCodeIsOkay.
|
||||||
|
```
|
||||||
|
|
||||||
|
* This list item line is too long. text text text text text text text text text text
|
||||||
|
* This list item line is okay. text text text text text text text text text
|
||||||
|
This list item line is okay. text text text text text text text text text
|
||||||
|
This list item line is too long. text text text text text text text text text text
|
||||||
|
ThisTooLongListItemLineIsOkaytexttexttexttexttexttexttexttexttexttexttexttexttext
|
||||||
|
|
||||||
|
> This blockquote line is too long. text text text text text text text text text text
|
||||||
|
> This blockquote line is okay. text text text text text text text text text
|
||||||
|
> ThisTooLongBlockquoteLineIsOkaytexttexttexttexttexttexttexttexttexttexttexttexttext
|
||||||
|
>
|
||||||
|
> > This double blockquote line is too long. text text text text text text text text
|
||||||
|
> > This double blockquote line is okay. text text text text text text text
|
||||||
|
> > ThisTooLongDoubleBlockquoteLineIsOkaytexttexttexttexttexttexttexttexttexttexttext
|
||||||
|
|
||||||
|
ThisLineIsTooLongButIsNotReportedBecauseItLooksLikePartOfAListItemtexttexttexttext
|
||||||
|
|
||||||
|
{MD013:5}
|
||||||
|
{MD013:7}
|
||||||
|
{MD013:13}
|
||||||
|
{MD013:17}
|
||||||
|
{MD013:26}
|
||||||
|
{MD013:32}
|
||||||
|
{MD013:35}
|
||||||
|
{MD013:38}
|
||||||
|
{MD013:42}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue