From 2b27f69c4bd6e0bd16de37e5c1f318f5a2d182ff Mon Sep 17 00:00:00 2001 From: yeonjuan Date: Wed, 5 Oct 2022 02:57:33 +0900 Subject: [PATCH 1/2] fix(eslint-plugin): [consistent-indexed-object-style] handle interface generic --- .../rules/consistent-indexed-object-style.ts | 4 ++-- .../consistent-indexed-object-style.test.ts | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts b/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts index 2b260865a4c4..535692f3fa86 100644 --- a/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts +++ b/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts @@ -1,5 +1,5 @@ import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; -import { AST_NODE_TYPES } from '@typescript-eslint/utils'; +import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils'; import { createRule } from '../util'; @@ -67,7 +67,7 @@ export default createRule({ if (parentId) { const scope = context.getScope(); - const superVar = scope.set.get(parentId.name); + const superVar = ASTUtils.findVariable(scope, parentId.name); if (superVar) { const isCircular = superVar.references.some( item => diff --git a/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts b/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts index 5c59f92b92de..539d7cb117e4 100644 --- a/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts +++ b/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts @@ -39,7 +39,16 @@ interface Foo { [key: string]: Foo; } `, - + ` +interface Foo { + [key: string]: Foo; +} + `, + ` +interface Foo { + [key: string]: Foo | string; +} +`, // Type literal 'type Foo = {};', ` @@ -328,6 +337,17 @@ type Foo = Readonly>; }, { code: ` +interface Foo { + [k: string]: T; +} + `, + output: ` +type Foo = Record; + `, + errors: [{ messageId: 'preferRecord', line: 2, column: 1 }], + }, + { + code: ` interface Foo { [k: string]: A.Foo; } From a6a43810e6965b1489d744b9bdfb810bb534d7c9 Mon Sep 17 00:00:00 2001 From: yeonjuan Date: Wed, 5 Oct 2022 03:23:46 +0900 Subject: [PATCH 2/2] fix lint error --- .../tests/rules/consistent-indexed-object-style.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts b/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts index 539d7cb117e4..6bdc76362e0a 100644 --- a/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts +++ b/packages/eslint-plugin/tests/rules/consistent-indexed-object-style.test.ts @@ -48,7 +48,7 @@ interface Foo { interface Foo { [key: string]: Foo | string; } -`, + `, // Type literal 'type Foo = {};', ` 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