From 3a53e8d884809899bcadd381965953d33eb121c2 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 13 Dec 2024 17:20:22 -0500 Subject: [PATCH] feat: add auto-fixes --- src/sentences-per-line.test.ts | 57 +++++++++++++++++++++++++++++----- src/sentences-per-line.ts | 7 +++++ 2 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/sentences-per-line.test.ts b/src/sentences-per-line.test.ts index 92697ec4..d1eb5851 100644 --- a/src/sentences-per-line.test.ts +++ b/src/sentences-per-line.test.ts @@ -8,13 +8,49 @@ describe("sentences-per-line", () => { ["", undefined], ["abc", undefined], ["abc.", undefined], - ["Abc. Def.", "Abc. Def."], - ["Abc def. Ghi jkl.", "Abc def. Ghi j"], + [ + "Abc. Def.", + "Abc. Def.", + { + fixInfo: { + deleteCount: 1, + editColumn: 5, + insertText: "\n", + lineNumber: 1, + }, + lineNumber: 1, + }, + ], + [ + "Abc def. Ghi jkl.", + "Abc def. Ghi j", + { + fixInfo: { + deleteCount: 1, + editColumn: 9, + insertText: "\n", + lineNumber: 1, + }, + lineNumber: 1, + }, + ], ["`Abc. Def.`", undefined], ["`Abc.` Def.", undefined], ["`Abc.` `Def.`", undefined], ["``Abc.`` Def.", undefined], - ["`Abc.` Def. Ghi", "c.` Def. Gh"], + [ + "`Abc.` Def. Ghi", + "c.` Def. Gh", + { + fixInfo: { + deleteCount: 1, + editColumn: 12, + insertText: "\n", + lineNumber: 1, + }, + lineNumber: 1, + }, + ], ["```js```.", undefined], [ ` @@ -44,9 +80,17 @@ Abc. Def. Abc. Def. `, "Abc. Def.", - 6, + { + fixInfo: { + deleteCount: 1, + editColumn: 5, + insertText: "\n", + lineNumber: 6, + }, + lineNumber: 6, + }, ], - ])("%s", (input, errorContext, lineNumber = 1) => { + ] as const)("%s", (input, errorContext, report?) => { const actual = markdownlint.sync({ config: { default: false, @@ -63,11 +107,10 @@ Abc. Def. errorContext, errorDetail: null, errorRange: null, - fixInfo: null, - lineNumber, ruleDescription: "Each sentence should be on its own line", ruleInformation: null, ruleNames: ["sentences-per-line"], + ...report, }, ] : [], diff --git a/src/sentences-per-line.ts b/src/sentences-per-line.ts index 99feb84a..3a7dc144 100644 --- a/src/sentences-per-line.ts +++ b/src/sentences-per-line.ts @@ -96,6 +96,13 @@ const visitLine = ( lineNumber, undefined, line.slice(Math.max(0, i - 7), 14), + undefined, + { + deleteCount: 1, + editColumn: i + 2, + insertText: "\n", + lineNumber, + }, ); } }