Update MD013/line-length to support stern parameter (fixes #256).

This commit is contained in:
David Anson 2020-03-22 14:06:29 -07:00
parent 11ea2ad5f1
commit de86a26e4e
6 changed files with 101 additions and 5 deletions

View file

@ -11,6 +11,7 @@ const longLineRePostfixRelaxed = "}.*\\s.*$";
const longLineRePostfixStrict = "}.+$";
const labelRe = /^\s*\[.*[^\\]]:/;
const linkOrImageOnlyLineRe = /^[es]*(lT?L|I)[ES]*$/;
const sternModeRe = /^([#>\s]*\s)?\S*$/;
const tokenTypeMap = {
"em_open": "e",
"em_close": "E",
@ -33,8 +34,9 @@ module.exports = {
const codeLineLength =
Number(params.config.code_block_line_length || lineLength);
const strict = !!params.config.strict;
const stern = !!params.config.stern;
const longLineRePostfix =
strict ? longLineRePostfixStrict : longLineRePostfixRelaxed;
(strict || stern) ? longLineRePostfixStrict : longLineRePostfixRelaxed;
const longLineRe =
new RegExp(longLineRePrefix + lineLength + longLineRePostfix);
const longHeadingLineRe =
@ -79,7 +81,8 @@ module.exports = {
(includeTables || !inTable) &&
(includeHeadings || !isHeading) &&
(strict ||
(!includesSorted(linkOnlyLineNumbers, lineNumber) &&
(!(stern && sternModeRe.test(line)) &&
!includesSorted(linkOnlyLineNumbers, lineNumber) &&
!labelRe.test(line))) &&
lengthRe.test(line)) {
addErrorDetailIf(