From d9ff161ce75ca06fc826fa8d656d5a7cc45c0da8 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Tue, 24 Oct 2023 02:43:33 -0400 Subject: [PATCH 1/4] chore: enable prefer-nullish-calescing internally --- .eslintrc.js | 7 ++++++- .../eslint-plugin/src/rules/consistent-type-imports.ts | 2 +- packages/eslint-plugin/src/rules/key-spacing.ts | 2 +- packages/eslint-plugin/src/rules/no-extraneous-class.ts | 2 +- .../eslint-plugin/src/rules/switch-exhaustiveness-check.ts | 1 + packages/eslint-plugin/src/rules/unified-signatures.ts | 2 +- .../src/create-program/createProjectProgram.ts | 2 +- 7 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ac2e363f4e13..379fb411c0a3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -56,7 +56,6 @@ module.exports = { '@typescript-eslint/consistent-indexed-object-style': 'off', '@typescript-eslint/no-unnecessary-condition': 'off', '@typescript-eslint/no-dynamic-delete': 'off', - '@typescript-eslint/prefer-nullish-coalescing': 'off', // TODO(#7130): Investigate changing these in or removing these from presets '@typescript-eslint/no-confusing-void-expression': 'off', @@ -108,6 +107,12 @@ module.exports = { 'error', { varsIgnorePattern: '^_', argsIgnorePattern: '^_' }, ], + '@typescript-eslint/prefer-nullish-coalescing': [ + 'error', + { + ignorePrimitives: true, + }, + ], // // Internal repo rules diff --git a/packages/eslint-plugin/src/rules/consistent-type-imports.ts b/packages/eslint-plugin/src/rules/consistent-type-imports.ts index 57e15ea29174..483406f34699 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-imports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-imports.ts @@ -607,7 +607,7 @@ export default createRule({ const { namedSpecifiers: valueImportNamedSpecifiers } = classifySpecifier(sourceImports.valueImport); if ( - sourceImports.valueOnlyNamedImport || + sourceImports.valueOnlyNamedImport ?? valueImportNamedSpecifiers.length ) { yield* fixInsertTypeKeywordInNamedSpecifierList( diff --git a/packages/eslint-plugin/src/rules/key-spacing.ts b/packages/eslint-plugin/src/rules/key-spacing.ts index 707c9dc4431b..a035fd754fb4 100644 --- a/packages/eslint-plugin/src/rules/key-spacing.ts +++ b/packages/eslint-plugin/src/rules/key-spacing.ts @@ -393,7 +393,7 @@ export default createRule({ let alignGroups: TSESTree.Node[][] = []; let unalignedElements: TSESTree.Node[] = []; - if (options.align || options.multiLine?.align) { + if (options.align ?? options.multiLine?.align) { let currentAlignGroup: TSESTree.Node[] = []; alignGroups.push(currentAlignGroup); diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index 009da2a21a75..0ecabbfd6cd2 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -83,7 +83,7 @@ export default createRule({ | TSESTree.ClassDeclaration | TSESTree.ClassExpression; - if (parent.superClass || isAllowWithDecorator(parent)) { + if (parent.superClass ?? isAllowWithDecorator(parent)) { return; } diff --git a/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts b/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts index 6abdbf27fc6e..e0b5707c1fbe 100644 --- a/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts +++ b/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts @@ -70,6 +70,7 @@ export default createRule({ if ( symbolName && + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (missingBranchName || missingBranchName === '') && requiresQuoting(missingBranchName.toString(), compilerOptions.target) ) { diff --git a/packages/eslint-plugin/src/rules/unified-signatures.ts b/packages/eslint-plugin/src/rules/unified-signatures.ts index 950125e8686f..e9a10c1f24ac 100644 --- a/packages/eslint-plugin/src/rules/unified-signatures.ts +++ b/packages/eslint-plugin/src/rules/unified-signatures.ts @@ -525,7 +525,7 @@ export default createRule({ key ??= getOverloadKey(signature); if ( currentScope && - (containingNode || signature).parent === currentScope.parent + (containingNode ?? signature).parent === currentScope.parent ) { const overloads = currentScope.overloads.get(key); if (overloads !== undefined) { diff --git a/packages/typescript-estree/src/create-program/createProjectProgram.ts b/packages/typescript-estree/src/create-program/createProjectProgram.ts index edfe00992c19..d128cd18b7f5 100644 --- a/packages/typescript-estree/src/create-program/createProjectProgram.ts +++ b/packages/typescript-estree/src/create-program/createProjectProgram.ts @@ -37,7 +37,7 @@ function createProjectProgram( // The file was either matched within the tsconfig, or we allow creating a default program // eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major - if (astAndProgram || parseSettings.DEPRECATED__createDefaultProgram) { + if (astAndProgram ?? parseSettings.DEPRECATED__createDefaultProgram) { return astAndProgram; } From 4914ed240e2125a3037ecc42e9ce4462efb371bb Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 29 Nov 2023 00:23:22 +0100 Subject: [PATCH 2/4] A couple complaints --- .../eslint-plugin/src/rules/padding-line-between-statements.ts | 2 +- packages/eslint-plugin/src/rules/unified-signatures.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/src/rules/padding-line-between-statements.ts b/packages/eslint-plugin/src/rules/padding-line-between-statements.ts index 255ceb0c712a..aacf1db21369 100644 --- a/packages/eslint-plugin/src/rules/padding-line-between-statements.ts +++ b/packages/eslint-plugin/src/rules/padding-line-between-statements.ts @@ -478,7 +478,7 @@ function verifyForAlways( } return true; }, - })! || nextNode; + }) ?? nextNode; const insertText = isTokenOnSameLine(prevToken, nextToken) ? '\n\n' : '\n'; diff --git a/packages/eslint-plugin/src/rules/unified-signatures.ts b/packages/eslint-plugin/src/rules/unified-signatures.ts index e9a10c1f24ac..c2bb139ef42c 100644 --- a/packages/eslint-plugin/src/rules/unified-signatures.ts +++ b/packages/eslint-plugin/src/rules/unified-signatures.ts @@ -368,7 +368,7 @@ export default createRule({ } return typeContainsTypeParameter( - (type as TSESTree.TSTypeAnnotation).typeAnnotation || + (type as TSESTree.TSTypeAnnotation).typeAnnotation ?? (type as TSESTree.TSArrayType).elementType, ); } From 84da5edbd0179d1f2c2155b04910a6322e2e148d Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 29 Nov 2023 01:24:50 +0100 Subject: [PATCH 3/4] One last complaint --- packages/rule-tester/src/utils/getRuleOptionsSchema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rule-tester/src/utils/getRuleOptionsSchema.ts b/packages/rule-tester/src/utils/getRuleOptionsSchema.ts index 1ff81d658e8e..f00ff1de6c94 100644 --- a/packages/rule-tester/src/utils/getRuleOptionsSchema.ts +++ b/packages/rule-tester/src/utils/getRuleOptionsSchema.ts @@ -33,5 +33,5 @@ export function getRuleOptionsSchema( } // Given a full schema, leave it alone - return schema || null; + return schema ?? null; } From 85b1560102e07be46ff9a19534b8071c28ea6518 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Wed, 24 Jan 2024 08:47:33 -0500 Subject: [PATCH 4/4] Enable ignoreConditionalTests --- .eslintrc.js | 1 + packages/eslint-plugin/src/rules/consistent-type-imports.ts | 2 +- packages/eslint-plugin/src/rules/key-spacing.ts | 2 +- packages/eslint-plugin/src/rules/no-extraneous-class.ts | 2 +- packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts | 1 - .../src/create-program/createProjectProgram.ts | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b85225fe7c13..3ca7d2fb3fba 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -113,6 +113,7 @@ module.exports = { '@typescript-eslint/prefer-nullish-coalescing': [ 'error', { + ignoreConditionalTests: true, ignorePrimitives: true, }, ], diff --git a/packages/eslint-plugin/src/rules/consistent-type-imports.ts b/packages/eslint-plugin/src/rules/consistent-type-imports.ts index 8f0aec931fa9..fd452d750b66 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-imports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-imports.ts @@ -613,7 +613,7 @@ export default createRule({ const { namedSpecifiers: valueImportNamedSpecifiers } = classifySpecifier(sourceImports.valueImport); if ( - sourceImports.valueOnlyNamedImport ?? + sourceImports.valueOnlyNamedImport || valueImportNamedSpecifiers.length ) { yield* fixInsertTypeKeywordInNamedSpecifierList( diff --git a/packages/eslint-plugin/src/rules/key-spacing.ts b/packages/eslint-plugin/src/rules/key-spacing.ts index f72dfcbe3c8a..bb882d1e8b48 100644 --- a/packages/eslint-plugin/src/rules/key-spacing.ts +++ b/packages/eslint-plugin/src/rules/key-spacing.ts @@ -386,7 +386,7 @@ export default createRule({ let alignGroups: TSESTree.Node[][] = []; let unalignedElements: TSESTree.Node[] = []; - if (options.align ?? options.multiLine?.align) { + if (options.align || options.multiLine?.align) { let currentAlignGroup: TSESTree.Node[] = []; alignGroups.push(currentAlignGroup); diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index 0ecabbfd6cd2..009da2a21a75 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -83,7 +83,7 @@ export default createRule({ | TSESTree.ClassDeclaration | TSESTree.ClassExpression; - if (parent.superClass ?? isAllowWithDecorator(parent)) { + if (parent.superClass || isAllowWithDecorator(parent)) { return; } diff --git a/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts b/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts index 0d61c0e765f3..64ab5ef6b2e2 100644 --- a/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts +++ b/packages/eslint-plugin/src/rules/switch-exhaustiveness-check.ts @@ -222,7 +222,6 @@ export default createRule({ if ( symbolName && - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing (missingBranchName || missingBranchName === '') && requiresQuoting(missingBranchName.toString(), compilerOptions.target) ) { diff --git a/packages/typescript-estree/src/create-program/createProjectProgram.ts b/packages/typescript-estree/src/create-program/createProjectProgram.ts index 185b0c703363..a58097e3cd73 100644 --- a/packages/typescript-estree/src/create-program/createProjectProgram.ts +++ b/packages/typescript-estree/src/create-program/createProjectProgram.ts @@ -37,7 +37,7 @@ function createProjectProgram( // The file was either matched within the tsconfig, or we allow creating a default program // eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major - if (astAndProgram ?? parseSettings.DEPRECATED__createDefaultProgram) { + if (astAndProgram || parseSettings.DEPRECATED__createDefaultProgram) { return astAndProgram; } 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