From 8e974f95d5421eb4298dc96f5c00726b8f853b97 Mon Sep 17 00:00:00 2001 From: David Anson Date: Sat, 29 Nov 2025 18:37:39 -0800 Subject: [PATCH] Update MD013/line-length default mode to prevent trailing non-whitespace text that begins *just over* the length limit (edge case). --- lib/md013.mjs | 4 +- test/long-lines-thresholds.md | 8 +- .../markdownlint-test-scenarios.mjs.md | 76 +++++++++++++++++- .../markdownlint-test-scenarios.mjs.snap | Bin 328380 -> 328688 bytes 4 files changed, 79 insertions(+), 9 deletions(-) diff --git a/lib/md013.mjs b/lib/md013.mjs index 1bb21aed..9d8792d6 100644 --- a/lib/md013.mjs +++ b/lib/md013.mjs @@ -64,7 +64,9 @@ export default { const inCode = codeBlockLineNumbers.has(lineNumber); const inTable = tableLineNumbers.has(lineNumber); 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) && (includeCodeBlocks || !inCode) && (includeTables || !inTable) && diff --git a/test/long-lines-thresholds.md b/test/long-lines-thresholds.md index 8abf6d14..39403f52 100644 --- a/test/long-lines-thresholds.md +++ b/test/long-lines-thresholds.md @@ -13,7 +13,7 @@ Text text text text text text text textx 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 @@ -25,7 +25,7 @@ Text 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 te text @@ -35,7 +35,7 @@ Text text text textx text Text text text textxe text ``` -{MD013:-3} {MD013:-4} +{MD013:-3} {MD013:-4} {MD013:-5} Text text tex text Text text text text @@ -43,7 +43,7 @@ Text text text textxe text Text text textxe text Text text textxet text -{MD013:-2} {MD013:-3} +{MD013:-2} {MD013:-3} {MD013:-4}