Skip to content

Commit

Permalink
feat: add auto-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Dec 13, 2024
1 parent 88f2edb commit 3a53e8d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
57 changes: 50 additions & 7 deletions src/sentences-per-line.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
[
`
Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
]
: [],
Expand Down
7 changes: 7 additions & 0 deletions src/sentences-per-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
}
}
Expand Down

0 comments on commit 3a53e8d

Please sign in to comment.