From fe80a432a856dab09a3fc19c791ce66483fdda42 Mon Sep 17 00:00:00 2001 From: Adnan Hashmi <56730784+adnanhashmi09@users.noreply.github.com> Date: Mon, 24 Oct 2022 07:40:02 +0530 Subject: [PATCH 1/3] chore(eslint-plugin): [prefer-nullish-coalescing] removed forceSuggestionFixer option (#5835) --- packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts b/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts index 6d820369b0a..ca40160e982 100644 --- a/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts +++ b/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts @@ -48,9 +48,6 @@ export default util.createRule({ ignoreMixedLogicalExpressions: { type: 'boolean', }, - forceSuggestionFixer: { - type: 'boolean', - }, }, additionalProperties: false, }, From 96e1c6c171a34b0793c50c3dba853c3999a6bd49 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sun, 23 Oct 2022 22:11:32 -0400 Subject: [PATCH 2/3] fix(eslint-plugin): [no-base-to-string] ignore Error, URL, and URLSearchParams by default (#5839) --- packages/eslint-plugin/src/rules/no-base-to-string.ts | 2 +- packages/eslint-plugin/tests/rules/no-base-to-string.test.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/no-base-to-string.ts b/packages/eslint-plugin/src/rules/no-base-to-string.ts index 8c81878238f..8b8521491f2 100644 --- a/packages/eslint-plugin/src/rules/no-base-to-string.ts +++ b/packages/eslint-plugin/src/rules/no-base-to-string.ts @@ -48,7 +48,7 @@ export default util.createRule({ }, defaultOptions: [ { - ignoredTypeNames: ['RegExp'], + ignoredTypeNames: ['Error', 'RegExp', 'URL', 'URLSearchParams'], }, ], create(context, [option]) { diff --git a/packages/eslint-plugin/tests/rules/no-base-to-string.test.ts b/packages/eslint-plugin/tests/rules/no-base-to-string.test.ts index a60ac656a40..c8af0c48ad8 100644 --- a/packages/eslint-plugin/tests/rules/no-base-to-string.test.ts +++ b/packages/eslint-plugin/tests/rules/no-base-to-string.test.ts @@ -113,6 +113,9 @@ tag\`\${{}}\`; return \`\${v}\`; } `, + "'' += new Error();", + "'' += new URL();", + "'' += new URLSearchParams();", ], invalid: [ { From e70a10aea684bc6bca05b69bfce3bae769a5f5ab Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 24 Oct 2022 06:44:18 -0700 Subject: [PATCH 3/3] feat(eslint-plugin): [no-unsafe-declaration-merging] switch to use scope analysis instead of type information (#5865) --- .../rules/no-unsafe-declaration-merging.ts | 45 ++++++++++++++----- .../no-unsafe-declaration-merging.test.ts | 16 +++---- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-unsafe-declaration-merging.ts b/packages/eslint-plugin/src/rules/no-unsafe-declaration-merging.ts index 7982fe5c5f4..89d68db6e67 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-declaration-merging.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-declaration-merging.ts @@ -1,5 +1,6 @@ +import type { Scope } from '@typescript-eslint/scope-manager'; import type { TSESTree } from '@typescript-eslint/utils'; -import * as ts from 'typescript'; +import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as util from '../util'; @@ -10,7 +11,7 @@ export default util.createRule({ docs: { description: 'Disallow unsafe declaration merging', recommended: 'strict', - requiresTypeChecking: true, + requiresTypeChecking: false, }, messages: { unsafeMerging: @@ -20,17 +21,22 @@ export default util.createRule({ }, defaultOptions: [], create(context) { - const parserServices = util.getParserServices(context); - const checker = parserServices.program.getTypeChecker(); - function checkUnsafeDeclaration( + scope: Scope, node: TSESTree.Identifier, - unsafeKind: ts.SyntaxKind, + unsafeKind: AST_NODE_TYPES, ): void { - const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node); - const type = checker.getTypeAtLocation(tsNode); - const symbol = type.getSymbol(); - if (symbol?.declarations?.some(decl => decl.kind === unsafeKind)) { + const variable = scope.set.get(node.name); + if (!variable) { + return; + } + + const defs = variable.defs; + if (defs.length <= 1) { + return; + } + + if (defs.some(def => def.node.type === unsafeKind)) { context.report({ node, messageId: 'unsafeMerging', @@ -41,11 +47,26 @@ export default util.createRule({ return { ClassDeclaration(node): void { if (node.id) { - checkUnsafeDeclaration(node.id, ts.SyntaxKind.InterfaceDeclaration); + // by default eslint returns the inner class scope for the ClassDeclaration node + // but we want the outer scope within which merged variables will sit + const currentScope = context.getScope().upper; + if (currentScope == null) { + return; + } + + checkUnsafeDeclaration( + currentScope, + node.id, + AST_NODE_TYPES.TSInterfaceDeclaration, + ); } }, TSInterfaceDeclaration(node): void { - checkUnsafeDeclaration(node.id, ts.SyntaxKind.ClassDeclaration); + checkUnsafeDeclaration( + context.getScope(), + node.id, + AST_NODE_TYPES.ClassDeclaration, + ); }, }; }, diff --git a/packages/eslint-plugin/tests/rules/no-unsafe-declaration-merging.test.ts b/packages/eslint-plugin/tests/rules/no-unsafe-declaration-merging.test.ts index e92c1ed36e7..1feabbe8158 100644 --- a/packages/eslint-plugin/tests/rules/no-unsafe-declaration-merging.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unsafe-declaration-merging.test.ts @@ -80,23 +80,19 @@ class Foo {} }, { code: ` -namespace Foo { - export interface Bar {} -} -namespace Foo { - export class Bar {} -} +class Foo {} +interface Foo {} `, errors: [ { messageId: 'unsafeMerging', - line: 3, - column: 20, + line: 2, + column: 7, }, { messageId: 'unsafeMerging', - line: 6, - column: 16, + line: 3, + column: 11, }, ], },