From 3b64f4aded58168a9f00a6694ceffcdf8b6097b2 Mon Sep 17 00:00:00 2001 From: nayounsang Date: Fri, 27 Jun 2025 23:46:15 +0900 Subject: [PATCH 1/2] test: add tc --- .../rules/consistent-generic-constructors.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/consistent-generic-constructors.test.ts b/packages/eslint-plugin/tests/rules/consistent-generic-constructors.test.ts index 4d0403a85a87..1a573186b1ae 100644 --- a/packages/eslint-plugin/tests/rules/consistent-generic-constructors.test.ts +++ b/packages/eslint-plugin/tests/rules/consistent-generic-constructors.test.ts @@ -45,6 +45,16 @@ class A { ` const a = function (a: Foo = new Foo()) {}; `, + { + code: ` +const foo: Foo = new Foo(); + `, + languageOptions: { + parserOptions: { + isolatedDeclarations: true, + }, + }, + }, // type-annotation { code: 'const a = new Foo();', From a4c6aa9ce08ea4eab2734eda8ba11f5348cebb05 Mon Sep 17 00:00:00 2001 From: nayounsang Date: Fri, 27 Jun 2025 23:48:27 +0900 Subject: [PATCH 2/2] fix: ignore constructor report when id is enabled --- .../eslint-plugin/src/rules/consistent-generic-constructors.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/consistent-generic-constructors.ts b/packages/eslint-plugin/src/rules/consistent-generic-constructors.ts index f2a4808d25dd..a26f1422460e 100644 --- a/packages/eslint-plugin/src/rules/consistent-generic-constructors.ts +++ b/packages/eslint-plugin/src/rules/consistent-generic-constructors.ts @@ -123,7 +123,8 @@ export default createRule({ return; } - if (lhs?.typeArguments && !rhs.typeArguments) { + const isolatedDeclarations = context.parserOptions.isolatedDeclarations; + if (!isolatedDeclarations && lhs?.typeArguments && !rhs.typeArguments) { const hasParens = context.sourceCode.getTokenAfter(rhs.callee)?.value === '('; const extraComments = new Set(