Skip to content

Commit dac51dd

Browse files
fix: correct blockESLint intake multi-line comment parsing (#2172)
## PR Checklist - [x] Addresses an existing open issue: fixes #2171 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview 🎁
1 parent eb98bd3 commit dac51dd

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/blocks/blockESLintIntake.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,36 @@ export default tseslint.config(
313313
],
314314
},
315315
],
316+
[
317+
"multi-line custom commented group in rules",
318+
`
319+
export default tseslint.config(
320+
{ ignores: ["lib"] },
321+
{
322+
extends: [tseslint.configs.strictTypeChecked],
323+
files: ["**/*.{js,ts}"],
324+
languageOptions: { /* ... */ },
325+
rules: {
326+
// First line.
327+
// Second line.
328+
// Third line.
329+
"@typescript-eslint/prefer-nullish-coalescing": "error"
330+
},
331+
settings: { /* ... */ }
332+
}
333+
);`,
334+
{
335+
ignores: ["lib"],
336+
rules: [
337+
{
338+
comment: "First line.\nSecond line.\nThird line.",
339+
entries: {
340+
"@typescript-eslint/prefer-nullish-coalescing": "error",
341+
},
342+
},
343+
],
344+
},
345+
],
316346
])("returns data when given %s", (_, sourceText, expected) => {
317347
const actual = blockESLintIntake(sourceText);
318348

src/blocks/eslint/blockESLintIntake.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export function blockESLintIntake(sourceText: string) {
9494
property.range[0],
9595
);
9696
const comment =
97-
precedingText.replaceAll(/\/\/|\n/g, "").trim() || undefined;
97+
precedingText.replaceAll(/\/\/ ?|\t\s*/g, "").trim() || undefined;
9898

9999
// blockESLintMoreStyling's comment always gets pushed to the end.
100100
if (comment === stylisticComment) {

0 commit comments

Comments
 (0)