From ab411525d142a6439f6bb490d694f6f5051a3b90 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Tue, 15 Aug 2023 21:40:46 -0700 Subject: [PATCH] Enable logical-assignment-operators rule internally --- .eslintrc.js | 1 + .../src/rules/consistent-type-imports.ts | 17 ++++++++--------- .../src/rules/unified-signatures.ts | 2 +- .../rule-tester/src/utils/config-validator.ts | 2 +- .../src/referencer/ClassVisitor.ts | 7 +++---- .../getWatchProgramsForProjects.ts | 3 +-- .../src/components/config/ConfigTypeScript.tsx | 2 +- 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5f0a828f3c35..0cbb0a0772cb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -121,6 +121,7 @@ module.exports = { null: 'never', }, ], + 'logical-assignment-operators': 'error', 'no-else-return': 'error', 'no-mixed-operators': 'error', 'no-console': 'error', diff --git a/packages/eslint-plugin/src/rules/consistent-type-imports.ts b/packages/eslint-plugin/src/rules/consistent-type-imports.ts index fac248681312..9aaa296a4b0c 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-imports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-imports.ts @@ -105,15 +105,14 @@ export default util.createRule({ ImportDeclaration(node): void { const source = node.source.value; // sourceImports is the object containing all the specifics for a particular import source, type or value - const sourceImports = - sourceImportsMap[source] ?? - (sourceImportsMap[source] = { - source, - reportValueImports: [], // if there is a mismatch where type importKind but value specifiers - typeOnlyNamedImport: null, // if only type imports - valueOnlyNamedImport: null, // if only value imports with named specifiers - valueImport: null, // if only value imports - }); + sourceImportsMap[source] ??= { + source, + reportValueImports: [], // if there is a mismatch where type importKind but value specifiers + typeOnlyNamedImport: null, // if only type imports + valueOnlyNamedImport: null, // if only value imports with named specifiers + valueImport: null, // if only value imports + }; + const sourceImports = sourceImportsMap[source]; if (node.importKind === 'type') { if ( !sourceImports.typeOnlyNamedImport && diff --git a/packages/eslint-plugin/src/rules/unified-signatures.ts b/packages/eslint-plugin/src/rules/unified-signatures.ts index 1a033f905ba2..34fb04c295ec 100644 --- a/packages/eslint-plugin/src/rules/unified-signatures.ts +++ b/packages/eslint-plugin/src/rules/unified-signatures.ts @@ -521,7 +521,7 @@ export default util.createRule({ key?: string, containingNode?: ContainingNode, ): void { - key = key ?? getOverloadKey(signature); + key ??= getOverloadKey(signature); if ( currentScope && (containingNode || signature).parent === currentScope.parent diff --git a/packages/rule-tester/src/utils/config-validator.ts b/packages/rule-tester/src/utils/config-validator.ts index ef88f7e664eb..3177b91b2a50 100644 --- a/packages/rule-tester/src/utils/config-validator.ts +++ b/packages/rule-tester/src/utils/config-validator.ts @@ -248,7 +248,7 @@ function validateConfigSchema( config: TesterConfigWithDefaults, source: string, ): void { - validateSchema = validateSchema || ajv.compile(configSchema); + validateSchema ||= ajv.compile(configSchema); if (!validateSchema(config)) { throw new Error( diff --git a/packages/scope-manager/src/referencer/ClassVisitor.ts b/packages/scope-manager/src/referencer/ClassVisitor.ts index f1f4a746d3b5..b22cc27133c6 100644 --- a/packages/scope-manager/src/referencer/ClassVisitor.ts +++ b/packages/scope-manager/src/referencer/ClassVisitor.ts @@ -154,10 +154,9 @@ class ClassVisitor extends Visitor { * ) {} * } */ - withMethodDecorators = - withMethodDecorators || - (methodNode.kind !== 'set' && - node.params.some(param => param.decorators.length)); + withMethodDecorators ||= + methodNode.kind !== 'set' && + node.params.some(param => param.decorators.length); if (!withMethodDecorators && methodNode.kind === 'set') { const keyName = getLiteralMethodKeyName(methodNode); diff --git a/packages/typescript-estree/src/create-program/getWatchProgramsForProjects.ts b/packages/typescript-estree/src/create-program/getWatchProgramsForProjects.ts index 2ec2b4ce35ae..1b144b9381d1 100644 --- a/packages/typescript-estree/src/create-program/getWatchProgramsForProjects.ts +++ b/packages/typescript-estree/src/create-program/getWatchProgramsForProjects.ts @@ -180,8 +180,7 @@ function getWatchProgramsForProjects( if (fileList.has(filePath)) { log('Found existing program for file. %s', filePath); - updatedProgram = - updatedProgram ?? existingWatch.getProgram().getProgram(); + updatedProgram ??= existingWatch.getProgram().getProgram(); // sets parent pointers in source files updatedProgram.getTypeChecker(); diff --git a/packages/website/src/components/config/ConfigTypeScript.tsx b/packages/website/src/components/config/ConfigTypeScript.tsx index 7a7a66b174dd..b367af6fafb7 100644 --- a/packages/website/src/components/config/ConfigTypeScript.tsx +++ b/packages/website/src/components/config/ConfigTypeScript.tsx @@ -35,7 +35,7 @@ function ConfigTypeScript(props: ConfigTypeScriptProps): React.JSX.Element { getTypescriptOptions().reduce>( (group, item) => { const category = item.category!.message; - group[category] = group[category] ?? { + group[category] ??= { heading: category, fields: [], };