Update MD013/line-length default mode to prevent trailing non-whitespace text that begins *just over* the length limit (edge case).
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run

This commit is contained in:
David Anson 2025-11-29 18:37:39 -08:00
parent 601910116d
commit 8e974f95d5
4 changed files with 79 additions and 9 deletions

View file

@ -64,7 +64,9 @@ export default {
const inCode = codeBlockLineNumbers.has(lineNumber); const inCode = codeBlockLineNumbers.has(lineNumber);
const inTable = tableLineNumbers.has(lineNumber); const inTable = tableLineNumbers.has(lineNumber);
const maxLength = inCode ? codeLineLength : (isHeading ? headingLineLength : lineLength); const maxLength = inCode ? codeLineLength : (isHeading ? headingLineLength : lineLength);
const text = (strict || stern) ? line : line.replace(/\S*$/u, ""); // If not strict/stern, the last run of non-whitespace is allowed to go
// beyond the limit as long as it begins within the limit
const text = (strict || stern) ? line : line.replace(/\S*$/u, "#");
if ((maxLength > 0) && if ((maxLength > 0) &&
(includeCodeBlocks || !inCode) && (includeCodeBlocks || !inCode) &&
(includeTables || !inTable) && (includeTables || !inTable) &&

View file

@ -13,7 +13,7 @@ Text text text text text text text textx text
Text text text text text text text textxe text Text text text text text text text textxe text
{MD013:-2} {MD013:-4} {MD013:-2} {MD013:-4} {MD013:-6}
## Text text text text text te text ## Text text text text text te text
@ -25,7 +25,7 @@ Text text text text text text text textxe text
## Text text text text text textxe text ## Text text text text text textxe text
{MD013:-2} {MD013:-4} {MD013:-2} {MD013:-4} {MD013:-6}
```text ```text
Text text text te text Text text text te text
@ -35,7 +35,7 @@ Text text text textx text
Text text text textxe text Text text text textxe text
``` ```
{MD013:-3} {MD013:-4} {MD013:-3} {MD013:-4} {MD013:-5}
Text text tex text Text text tex text
Text text text text Text text text text
@ -43,7 +43,7 @@ Text text text textxe text
Text text textxe text Text text textxe text
Text text textxet text Text text textxet text
{MD013:-2} {MD013:-3} {MD013:-2} {MD013:-3} {MD013:-4}
<!-- markdownlint-configure-file { <!-- markdownlint-configure-file {
"code-block-style": false, "code-block-style": false,

View file

@ -42664,6 +42664,23 @@ Generated by [AVA](https://avajs.dev).
{ {
errors: [ errors: [
{
errorContext: null,
errorDetail: 'Expected: 40; Actual: 44',
errorRange: [
41,
4,
],
fixInfo: null,
lineNumber: 10,
ruleDescription: 'Line length',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md013.md',
ruleNames: [
'MD013',
'line-length',
],
severity: 'error',
},
{ {
errorContext: null, errorContext: null,
errorDetail: 'Expected: 40; Actual: 45', errorDetail: 'Expected: 40; Actual: 45',
@ -42698,6 +42715,23 @@ Generated by [AVA](https://avajs.dev).
], ],
severity: 'error', severity: 'error',
}, },
{
errorContext: null,
errorDetail: 'Expected: 33; Actual: 37',
errorRange: [
34,
4,
],
fixInfo: null,
lineNumber: 22,
ruleDescription: 'Line length',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md013.md',
ruleNames: [
'MD013',
'line-length',
],
severity: 'error',
},
{ {
errorContext: null, errorContext: null,
errorDetail: 'Expected: 33; Actual: 38', errorDetail: 'Expected: 33; Actual: 38',
@ -42732,6 +42766,23 @@ Generated by [AVA](https://avajs.dev).
], ],
severity: 'error', severity: 'error',
}, },
{
errorContext: null,
errorDetail: 'Expected: 20; Actual: 24',
errorRange: [
21,
4,
],
fixInfo: null,
lineNumber: 33,
ruleDescription: 'Line length',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md013.md',
ruleNames: [
'MD013',
'line-length',
],
severity: 'error',
},
{ {
errorContext: null, errorContext: null,
errorDetail: 'Expected: 20; Actual: 25', errorDetail: 'Expected: 20; Actual: 25',
@ -42766,6 +42817,23 @@ Generated by [AVA](https://avajs.dev).
], ],
severity: 'error', severity: 'error',
}, },
{
errorContext: null,
errorDetail: 'Expected: 20; Actual: 24',
errorRange: [
21,
4,
],
fixInfo: null,
lineNumber: 42,
ruleDescription: 'Line length',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md013.md',
ruleNames: [
'MD013',
'line-length',
],
severity: 'error',
},
{ {
errorContext: null, errorContext: null,
errorDetail: 'Expected: 20; Actual: 25', errorDetail: 'Expected: 20; Actual: 25',
@ -42816,7 +42884,7 @@ Generated by [AVA](https://avajs.dev).
Text text text text text text text textxe text␊ Text text text text text text text textxe text␊
{MD013:-2} {MD013:-4}␊ {MD013:-2} {MD013:-4} {MD013:-6}
## Text text text text text te text␊ ## Text text text text text te text␊
@ -42828,7 +42896,7 @@ Generated by [AVA](https://avajs.dev).
## Text text text text text textxe text␊ ## Text text text text text textxe text␊
{MD013:-2} {MD013:-4}␊ {MD013:-2} {MD013:-4} {MD013:-6}
\`\`\`text␊ \`\`\`text␊
Text text text te text␊ Text text text te text␊
@ -42838,7 +42906,7 @@ Generated by [AVA](https://avajs.dev).
Text text text textxe text␊ Text text text textxe text␊
\`\`\`␊ \`\`\`␊
{MD013:-3} {MD013:-4}␊ {MD013:-3} {MD013:-4} {MD013:-5}
Text text tex text␊ Text text tex text␊
Text text text text␊ Text text text text␊
@ -42846,7 +42914,7 @@ Generated by [AVA](https://avajs.dev).
Text text textxe text␊ Text text textxe text␊
Text text textxet text␊ Text text textxet text␊
{MD013:-2} {MD013:-3}␊ {MD013:-2} {MD013:-3} {MD013:-4}
<!-- markdownlint-configure-file {␊ <!-- markdownlint-configure-file {␊
"code-block-style": false,␊ "code-block-style": false,␊