From a4ebde355e1ad2d046a801e1639541e561576b78 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sun, 5 Jan 2025 18:29:14 +0200 Subject: [PATCH 1/2] remove unnecessary checks so the rule correctly doesn't report on the various ways to have augmented modules --- packages/eslint-plugin/src/rules/no-shadow.ts | 5 +- .../tests/rules/no-shadow/no-shadow.test.ts | 124 ++++++------------ 2 files changed, 42 insertions(+), 87 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-shadow.ts b/packages/eslint-plugin/src/rules/no-shadow.ts index 0e1f87149608..e55344db1004 100644 --- a/packages/eslint-plugin/src/rules/no-shadow.ts +++ b/packages/eslint-plugin/src/rules/no-shadow.ts @@ -272,9 +272,8 @@ export default createRule({ scope, firstDefinition.parent.source.value, ) && - secondDefinition.node.type === AST_NODE_TYPES.TSInterfaceDeclaration && - secondDefinition.node.parent.type === - AST_NODE_TYPES.ExportNamedDeclaration + (secondDefinition.node.type === AST_NODE_TYPES.TSInterfaceDeclaration || + secondDefinition.node.type === AST_NODE_TYPES.TSTypeAliasDeclaration) ); } diff --git a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts index 6dd82ef35747..0f505041df3c 100644 --- a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts +++ b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts @@ -415,48 +415,6 @@ declare module 'baz' { }, { code: ` -import type { Foo } from 'bar'; - -declare module 'bar' { - export type Foo = string; -} - `, - errors: [ - { - data: { - name: 'Foo', - shadowedColumn: 15, - shadowedLine: 2, - }, - messageId: 'noShadow', - type: AST_NODE_TYPES.Identifier, - }, - ], - }, - { - code: ` -import type { Foo } from 'bar'; - -declare module 'bar' { - interface Foo { - x: string; - } -} - `, - errors: [ - { - data: { - name: 'Foo', - shadowedColumn: 15, - shadowedLine: 2, - }, - messageId: 'noShadow', - type: AST_NODE_TYPES.Identifier, - }, - ], - }, - { - code: ` import { type Foo } from 'bar'; declare module 'baz' { @@ -479,48 +437,6 @@ declare module 'baz' { }, { code: ` -import { type Foo } from 'bar'; - -declare module 'bar' { - export type Foo = string; -} - `, - errors: [ - { - data: { - name: 'Foo', - shadowedColumn: 15, - shadowedLine: 2, - }, - messageId: 'noShadow', - type: AST_NODE_TYPES.Identifier, - }, - ], - }, - { - code: ` -import { type Foo } from 'bar'; - -declare module 'bar' { - interface Foo { - x: string; - } -} - `, - errors: [ - { - data: { - name: 'Foo', - shadowedColumn: 15, - shadowedLine: 2, - }, - messageId: 'noShadow', - type: AST_NODE_TYPES.Identifier, - }, - ], - }, - { - code: ` let x = foo((x, y) => {}); let y; `, @@ -1027,5 +943,45 @@ const person = { options: [{ ignoreOnInitialization: true }], }, { code: 'const [x = y => y] = [].map(y => y);' }, + { + code: ` +import type { Foo } from 'bar'; + +declare module 'bar' { + export type Foo = string; +} + `, + }, + { + code: ` +import type { Foo } from 'bar'; + +declare module 'bar' { + interface Foo { + x: string; + } +} + `, + }, + { + code: ` +import { type Foo } from 'bar'; + +declare module 'bar' { + export type Foo = string; +} + `, + }, + { + code: ` +import { type Foo } from 'bar'; + +declare module 'bar' { + interface Foo { + x: string; + } +} + `, + }, ], }); From a3e29793c3f2475bf4bc5847a382cb2cdf905022 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Thu, 23 Jan 2025 20:44:04 +0200 Subject: [PATCH 2/2] add tests for exported interface and non-exported type alias declaration --- .../tests/rules/no-shadow/no-shadow.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts index 2b376d275b5b..22e04824b877 100644 --- a/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts +++ b/packages/eslint-plugin/tests/rules/no-shadow/no-shadow.test.ts @@ -1428,6 +1428,26 @@ declare module 'bar' { code: ` import { type Foo } from 'bar'; +declare module 'bar' { + export interface Foo { + x: string; + } +} + `, + }, + { + code: ` +import { type Foo } from 'bar'; + +declare module 'bar' { + type Foo = string; +} + `, + }, + { + code: ` +import { type Foo } from 'bar'; + declare module 'bar' { interface Foo { x: string; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy