Update MD013/line-length to include strict mode (fixes #237).

This commit is contained in:
David Anson 2019-12-12 21:22:45 -08:00
parent 5ae5e448b0
commit b39e5e309e
7 changed files with 78 additions and 16 deletions

View file

@ -3,11 +3,12 @@
"use strict";
const { addErrorDetailIf, filterTokens, forEachHeading, forEachLine,
includesSorted, rangeFromRegExp } = require("../helpers");
includesSorted } = require("../helpers");
const { lineMetadata } = require("./cache");
const longLineRePrefix = "^(.{";
const longLineRePostfix = "})(.*\\s.*)$";
const longLineRePrefix = "^.{";
const longLineRePostfixRelaxed = "}.*\\s.*$";
const longLineRePostfixStrict = "}.+$";
const labelRe = /^\s*\[.*[^\\]]:/;
const linkOnlyLineRe = /^[es]*lT?L[ES]*$/;
const tokenTypeMap = {
@ -28,6 +29,9 @@ module.exports = {
const lineLength = params.config.line_length || 80;
const headingLineLength = params.config.heading_line_length || lineLength;
const codeLineLength = params.config.code_block_line_length || lineLength;
const strict = !!params.config.strict;
const longLineRePostfix =
strict ? longLineRePostfixStrict : longLineRePostfixRelaxed;
const longLineRe =
new RegExp(longLineRePrefix + lineLength + longLineRePostfix);
const longHeadingLineRe =
@ -71,11 +75,18 @@ module.exports = {
if ((includeCodeBlocks || !inCode) &&
(includeTables || !inTable) &&
(includeHeadings || !isHeading) &&
!includesSorted(linkOnlyLineNumbers, lineNumber) &&
lengthRe.test(line) &&
!labelRe.test(line)) {
addErrorDetailIf(onError, lineNumber, length, line.length,
null, null, rangeFromRegExp(line, lengthRe));
(strict ||
(!includesSorted(linkOnlyLineNumbers, lineNumber) &&
!labelRe.test(line))) &&
lengthRe.test(line)) {
addErrorDetailIf(
onError,
lineNumber,
length,
line.length,
null,
null,
[ length + 1, line.length - length ]);
}
});
}