diff --git a/.eslintrc.js b/.eslintrc.js index 6c10e3036eb8..f6502ce3c885 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -98,6 +98,7 @@ module.exports = { allowRegExp: true, }, ], + '@typescript-eslint/sort-type-constituents': 'error', '@typescript-eslint/no-unused-vars': [ 'error', { varsIgnorePattern: '^_', argsIgnorePattern: '^_' }, diff --git a/packages/ast-spec/tests/util/parsers/parser-types.ts b/packages/ast-spec/tests/util/parsers/parser-types.ts index 4538d8ed4a9f..496ba192236b 100644 --- a/packages/ast-spec/tests/util/parsers/parser-types.ts +++ b/packages/ast-spec/tests/util/parsers/parser-types.ts @@ -45,4 +45,4 @@ export interface ParserResponseError { readonly type: ParserResponseType.Error; readonly error: unknown; } -export type ParserResponse = ParserResponseSuccess | ParserResponseError; +export type ParserResponse = ParserResponseError | ParserResponseSuccess; diff --git a/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts b/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts index 72d261382566..be81846a116a 100644 --- a/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts +++ b/packages/eslint-plugin-internal/src/rules/plugin-test-formatting.ts @@ -67,7 +67,7 @@ function doIndent(line: string, indent: number): string { return line; } -function getQuote(code: string): "'" | '"' | null { +function getQuote(code: string): '"' | "'" | null { const hasSingleQuote = code.includes("'"); const hasDoubleQuote = code.includes('"'); if (hasSingleQuote && hasDoubleQuote) { @@ -95,12 +95,12 @@ type Options = [ type MessageIds = | 'invalidFormatting' | 'invalidFormattingErrorTest' + | 'prettierException' | 'singleLineQuotes' | 'templateLiteralEmptyEnds' | 'templateLiteralLastLineIndent' - | 'templateStringRequiresIndent' | 'templateStringMinimumIndent' - | 'prettierException'; + | 'templateStringRequiresIndent'; export default createRule({ name: 'plugin-test-formatting', diff --git a/packages/eslint-plugin-tslint/src/rules/config.ts b/packages/eslint-plugin-tslint/src/rules/config.ts index 847b6846ea95..e7918218a905 100644 --- a/packages/eslint-plugin-tslint/src/rules/config.ts +++ b/packages/eslint-plugin-tslint/src/rules/config.ts @@ -32,14 +32,14 @@ const createRule = ESLintUtils.RuleCreator( ); export type RawRulesConfig = Record< string, - | null - | undefined - | boolean | unknown[] + | boolean | { - severity?: RuleSeverity | 'warn' | 'none' | 'default'; + severity?: RuleSeverity | 'default' | 'none' | 'warn'; options?: unknown; } + | null + | undefined >; export type MessageIds = 'failure'; diff --git a/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts b/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts index 3b52ffb0b68b..0534cc8ce0d1 100644 --- a/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts +++ b/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts @@ -4,12 +4,12 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as util from '../util'; type RuleNode = + | TSESTree.BlockStatement | TSESTree.ClassBody | TSESTree.Program - | TSESTree.TSModuleBlock - | TSESTree.TSTypeLiteral | TSESTree.TSInterfaceBody - | TSESTree.BlockStatement; + | TSESTree.TSModuleBlock + | TSESTree.TSTypeLiteral; type Member = | TSESTree.ClassElement | TSESTree.ProgramStatement diff --git a/packages/eslint-plugin/src/rules/array-type.ts b/packages/eslint-plugin/src/rules/array-type.ts index 08ff550a1418..cd4a1f89cb2f 100644 --- a/packages/eslint-plugin/src/rules/array-type.ts +++ b/packages/eslint-plugin/src/rules/array-type.ts @@ -72,7 +72,7 @@ function typeNeedsParentheses(node: TSESTree.Node): boolean { } } -export type OptionString = 'array' | 'generic' | 'array-simple'; +export type OptionString = 'array-simple' | 'array' | 'generic'; type Options = [ { default: OptionString; @@ -80,9 +80,9 @@ type Options = [ }, ]; type MessageIds = - | 'errorStringGeneric' | 'errorStringArray' | 'errorStringArraySimple' + | 'errorStringGeneric' | 'errorStringGenericSimple'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts index 3f9c60bdb8db..7de0718bde6b 100644 --- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts @@ -19,8 +19,8 @@ export const defaultMinimumDescriptionLength = 3; type MessageIds = | 'tsDirectiveComment' - | 'tsDirectiveCommentRequiresDescription' - | 'tsDirectiveCommentDescriptionNotMatchPattern'; + | 'tsDirectiveCommentDescriptionNotMatchPattern' + | 'tsDirectiveCommentRequiresDescription'; export default util.createRule<[Options], MessageIds>({ name: 'ban-ts-comment', diff --git a/packages/eslint-plugin/src/rules/ban-tslint-comment.ts b/packages/eslint-plugin/src/rules/ban-tslint-comment.ts index 8a920faddf5f..4453649b717e 100644 --- a/packages/eslint-plugin/src/rules/ban-tslint-comment.ts +++ b/packages/eslint-plugin/src/rules/ban-tslint-comment.ts @@ -9,7 +9,7 @@ const ENABLE_DISABLE_REGEX = const toText = ( text: string, - type: AST_TOKEN_TYPES.Line | AST_TOKEN_TYPES.Block, + type: AST_TOKEN_TYPES.Block | AST_TOKEN_TYPES.Line, ): string => type === AST_TOKEN_TYPES.Line ? ['//', text.trim()].join(' ') diff --git a/packages/eslint-plugin/src/rules/ban-types.ts b/packages/eslint-plugin/src/rules/ban-types.ts index b2912dc83023..1557e3f998f9 100644 --- a/packages/eslint-plugin/src/rules/ban-types.ts +++ b/packages/eslint-plugin/src/rules/ban-types.ts @@ -5,7 +5,6 @@ import * as util from '../util'; type Types = Record< string, - | null | boolean | string | { @@ -13,6 +12,7 @@ type Types = Record< fixWith?: string; suggest?: readonly string[]; } + | null >; export type Options = [ @@ -35,7 +35,7 @@ function stringifyNode( } function getCustomMessage( - bannedType: null | true | string | { message?: string; fixWith?: string }, + bannedType: string | true | { message?: string; fixWith?: string } | null, ): string { if (bannedType == null || bannedType === true) { return ''; diff --git a/packages/eslint-plugin/src/rules/brace-style.ts b/packages/eslint-plugin/src/rules/brace-style.ts index 0b5b543e0676..2e471cb88532 100644 --- a/packages/eslint-plugin/src/rules/brace-style.ts +++ b/packages/eslint-plugin/src/rules/brace-style.ts @@ -119,7 +119,7 @@ export default createRule({ return { ...rules, 'TSInterfaceBody, TSModuleBlock'( - node: TSESTree.TSModuleBlock | TSESTree.TSInterfaceBody, + node: TSESTree.TSInterfaceBody | TSESTree.TSModuleBlock, ): void { const openingCurly = sourceCode.getFirstToken(node)!; const closingCurly = sourceCode.getLastToken(node)!; diff --git a/packages/eslint-plugin/src/rules/class-literal-property-style.ts b/packages/eslint-plugin/src/rules/class-literal-property-style.ts index 7563c6b97fc0..fbe74bef0e41 100644 --- a/packages/eslint-plugin/src/rules/class-literal-property-style.ts +++ b/packages/eslint-plugin/src/rules/class-literal-property-style.ts @@ -13,7 +13,7 @@ interface NodeWithModifiers { const printNodeModifiers = ( node: NodeWithModifiers, - final: 'readonly' | 'get', + final: 'get' | 'readonly', ): string => `${node.accessibility ?? ''}${ node.static ? ' static' : '' diff --git a/packages/eslint-plugin/src/rules/comma-spacing.ts b/packages/eslint-plugin/src/rules/comma-spacing.ts index 36f3751bef76..3d709c8e7f08 100644 --- a/packages/eslint-plugin/src/rules/comma-spacing.ts +++ b/packages/eslint-plugin/src/rules/comma-spacing.ts @@ -14,7 +14,7 @@ type Options = [ after: boolean; }, ]; -type MessageIds = 'unexpected' | 'missing'; +type MessageIds = 'missing' | 'unexpected'; export default createRule({ name: 'comma-spacing', diff --git a/packages/eslint-plugin/src/rules/consistent-generic-constructors.ts b/packages/eslint-plugin/src/rules/consistent-generic-constructors.ts index e437bc38d761..8719d0b5dc5d 100644 --- a/packages/eslint-plugin/src/rules/consistent-generic-constructors.ts +++ b/packages/eslint-plugin/src/rules/consistent-generic-constructors.ts @@ -3,8 +3,8 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import { createRule } from '../util'; -type MessageIds = 'preferTypeAnnotation' | 'preferConstructor'; -type Options = ['type-annotation' | 'constructor']; +type MessageIds = 'preferConstructor' | 'preferTypeAnnotation'; +type Options = ['constructor' | 'type-annotation']; export default createRule({ name: 'consistent-generic-constructors', @@ -35,9 +35,9 @@ export default createRule({ return { 'VariableDeclarator,PropertyDefinition,:matches(FunctionDeclaration,FunctionExpression) > AssignmentPattern'( node: - | TSESTree.VariableDeclarator + | TSESTree.AssignmentPattern | TSESTree.PropertyDefinition - | TSESTree.AssignmentPattern, + | TSESTree.VariableDeclarator, ): void { function getLHSRHS(): [ TSESTree.BindingName | TSESTree.PropertyDefinition, @@ -84,8 +84,8 @@ export default createRule({ messageId: 'preferTypeAnnotation', fix(fixer) { function getIDToAttachAnnotation(): - | TSESTree.Token - | TSESTree.Node { + | TSESTree.Node + | TSESTree.Token { if (node.type !== AST_NODE_TYPES.PropertyDefinition) { return lhsName; } 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 268946ae463b..5aece3ea4802 100644 --- a/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts +++ b/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts @@ -3,8 +3,8 @@ import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils'; import { createRule } from '../util'; -type MessageIds = 'preferRecord' | 'preferIndexSignature'; -type Options = ['record' | 'index-signature']; +type MessageIds = 'preferIndexSignature' | 'preferRecord'; +type Options = ['index-signature' | 'record']; export default createRule({ name: 'consistent-indexed-object-style', @@ -32,7 +32,7 @@ export default createRule({ function checkMembers( members: TSESTree.TypeElement[], - node: TSESTree.TSTypeLiteral | TSESTree.TSInterfaceDeclaration, + node: TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeLiteral, parentId: TSESTree.Identifier | undefined, prefix: string, postfix: string, diff --git a/packages/eslint-plugin/src/rules/consistent-type-assertions.ts b/packages/eslint-plugin/src/rules/consistent-type-assertions.ts index cce706c8effd..9903f15e19e4 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-assertions.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-assertions.ts @@ -5,16 +5,16 @@ import * as util from '../util'; // intentionally mirroring the options export type MessageIds = - | 'as' | 'angle-bracket' + | 'as' | 'never' - | 'unexpectedObjectTypeAssertion' | 'replaceObjectTypeAssertionWithAnnotation' - | 'replaceObjectTypeAssertionWithSatisfies'; + | 'replaceObjectTypeAssertionWithSatisfies' + | 'unexpectedObjectTypeAssertion'; type OptUnion = | { - assertionStyle: 'as' | 'angle-bracket'; - objectLiteralTypeAssertions?: 'allow' | 'allow-as-parameter' | 'never'; + assertionStyle: 'angle-bracket' | 'as'; + objectLiteralTypeAssertions?: 'allow-as-parameter' | 'allow' | 'never'; } | { assertionStyle: 'never'; @@ -117,7 +117,7 @@ export default util.createRule({ } function reportIncorrectAssertionType( - node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression, + node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion, ): void { const messageId = options.assertionStyle; @@ -168,7 +168,7 @@ export default util.createRule({ } function checkExpression( - node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression, + node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion, ): void { if ( options.assertionStyle === 'never' || diff --git a/packages/eslint-plugin/src/rules/consistent-type-exports.ts b/packages/eslint-plugin/src/rules/consistent-type-exports.ts index 0a3b7b93deec..e65451ded1da 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-exports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-exports.ts @@ -25,9 +25,9 @@ interface ReportValueExport { } type MessageIds = - | 'typeOverValue' + | 'multipleExportsAreTypes' | 'singleExportIsType' - | 'multipleExportsAreTypes'; + | 'typeOverValue'; export default util.createRule({ name: 'consistent-type-exports', diff --git a/packages/eslint-plugin/src/rules/consistent-type-imports.ts b/packages/eslint-plugin/src/rules/consistent-type-imports.ts index 701c53b25416..dfa5e48ed652 100644 --- a/packages/eslint-plugin/src/rules/consistent-type-imports.ts +++ b/packages/eslint-plugin/src/rules/consistent-type-imports.ts @@ -3,8 +3,8 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as util from '../util'; -type Prefer = 'type-imports' | 'no-type-imports'; -type FixStyle = 'separate-type-imports' | 'inline-type-imports'; +type Prefer = 'no-type-imports' | 'type-imports'; +type FixStyle = 'inline-type-imports' | 'separate-type-imports'; type Options = [ { @@ -33,13 +33,13 @@ interface ReportValueImport { } type MessageIds = - | 'typeOverValue' - | 'someImportsAreOnlyTypes' + | 'aImportInDecoMeta' | 'aImportIsOnlyTypes' - | 'valueOverType' | 'noImportTypeAnnotations' + | 'someImportsAreOnlyTypes' | 'someImportsInDecoMeta' - | 'aImportInDecoMeta'; + | 'typeOverValue' + | 'valueOverType'; export default util.createRule({ name: 'consistent-type-imports', meta: { diff --git a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts index a390dc8d33a4..e57465be8365 100644 --- a/packages/eslint-plugin/src/rules/explicit-function-return-type.ts +++ b/packages/eslint-plugin/src/rules/explicit-function-return-type.ts @@ -102,8 +102,8 @@ export default util.createRule({ function isAllowedFunction( node: | TSESTree.ArrowFunctionExpression - | TSESTree.FunctionExpression - | TSESTree.FunctionDeclaration, + | TSESTree.FunctionDeclaration + | TSESTree.FunctionExpression, ): boolean { if (options.allowFunctionsWithoutTypeParameters && !node.typeParameters) { return true; @@ -164,8 +164,8 @@ export default util.createRule({ function isIIFE( node: | TSESTree.ArrowFunctionExpression - | TSESTree.FunctionExpression - | TSESTree.FunctionDeclaration, + | TSESTree.FunctionDeclaration + | TSESTree.FunctionExpression, ): boolean { return node.parent.type === AST_NODE_TYPES.CallExpression; } diff --git a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts index 9670659c975c..d95a58dc281e 100644 --- a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts +++ b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts @@ -23,9 +23,9 @@ interface Config { type Options = [Config]; type MessageIds = - | 'unwantedPublicAccessibility' + | 'addExplicitAccessibility' | 'missingAccessibility' - | 'addExplicitAccessibility'; + | 'unwantedPublicAccessibility'; export default util.createRule({ name: 'explicit-member-accessibility', diff --git a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts index 0e6c56038c51..d4a0efd56e54 100644 --- a/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts +++ b/packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts @@ -25,11 +25,11 @@ type Options = [ }, ]; type MessageIds = - | 'missingReturnType' + | 'anyTypedArg' + | 'anyTypedArgUnnamed' | 'missingArgType' | 'missingArgTypeUnnamed' - | 'anyTypedArg' - | 'anyTypedArgUnnamed'; + | 'missingReturnType'; export default util.createRule({ name: 'explicit-module-boundary-types', @@ -154,7 +154,7 @@ export default util.createRule({ }; function checkParameters( - node: TSESTree.TSEmptyBodyFunctionExpression | FunctionNode, + node: FunctionNode | TSESTree.TSEmptyBodyFunctionExpression, ): void { function checkParameter(param: TSESTree.Parameter): void { function report( diff --git a/packages/eslint-plugin/src/rules/func-call-spacing.ts b/packages/eslint-plugin/src/rules/func-call-spacing.ts index fd0b50a65fd0..b72c54951f92 100644 --- a/packages/eslint-plugin/src/rules/func-call-spacing.ts +++ b/packages/eslint-plugin/src/rules/func-call-spacing.ts @@ -3,15 +3,15 @@ import type { TSESTree } from '@typescript-eslint/utils'; import * as util from '../util'; export type Options = [ - 'never' | 'always', + 'always' | 'never', { allowNewlines?: boolean; }?, ]; export type MessageIds = - | 'unexpectedWhitespace' + | 'missing' | 'unexpectedNewline' - | 'missing'; + | 'unexpectedWhitespace'; export default util.createRule({ name: 'func-call-spacing', diff --git a/packages/eslint-plugin/src/rules/indent.ts b/packages/eslint-plugin/src/rules/indent.ts index 80d81293dd09..94c1899f2d43 100644 --- a/packages/eslint-plugin/src/rules/indent.ts +++ b/packages/eslint-plugin/src/rules/indent.ts @@ -130,12 +130,12 @@ export default util.createRule({ */ function TSPropertySignatureToProperty( node: - | TSESTree.TSPropertySignature | TSESTree.TSEnumMember + | TSESTree.TSPropertySignature | TSESTree.TypeElement, type: - | AST_NODE_TYPES.PropertyDefinition - | AST_NODE_TYPES.Property = AST_NODE_TYPES.Property, + | AST_NODE_TYPES.Property + | AST_NODE_TYPES.PropertyDefinition = AST_NODE_TYPES.Property, ): TSESTree.Node | null { const base = { // indent doesn't actually use these diff --git a/packages/eslint-plugin/src/rules/key-spacing.ts b/packages/eslint-plugin/src/rules/key-spacing.ts index 0fd0032c7c03..096f3b7493e7 100644 --- a/packages/eslint-plugin/src/rules/key-spacing.ts +++ b/packages/eslint-plugin/src/rules/key-spacing.ts @@ -65,9 +65,9 @@ export default util.createRule({ } type KeyTypeNode = + | TSESTree.PropertyDefinition | TSESTree.TSIndexSignature - | TSESTree.TSPropertySignature - | TSESTree.PropertyDefinition; + | TSESTree.TSPropertySignature; type KeyTypeNodeWithTypeAnnotation = KeyTypeNode & { typeAnnotation: TSESTree.TSTypeAnnotation; @@ -127,7 +127,7 @@ export default util.createRule({ function checkBeforeColon( node: KeyTypeNodeWithTypeAnnotation, expectedWhitespaceBeforeColon: number, - mode: 'strict' | 'minimum', + mode: 'minimum' | 'strict', ): void { const { typeAnnotation } = node; const colon = typeAnnotation.loc.start.column; @@ -161,7 +161,7 @@ export default util.createRule({ function checkAfterColon( node: KeyTypeNodeWithTypeAnnotation, expectedWhitespaceAfterColon: number, - mode: 'strict' | 'minimum', + mode: 'minimum' | 'strict', ): void { const { typeAnnotation } = node; const colon = typeAnnotation.loc.start.column; @@ -239,7 +239,7 @@ export default util.createRule({ function checkAlignGroup(group: TSESTree.Node[]): void { let alignColumn = 0; - const align: 'value' | 'colon' = + const align: 'colon' | 'value' = (typeof options.align === 'object' ? options.align.on : typeof options.multiLine?.align === 'object' @@ -372,9 +372,9 @@ export default util.createRule({ function validateBody( body: - | TSESTree.TSTypeLiteral + | TSESTree.ClassBody | TSESTree.TSInterfaceBody - | TSESTree.ClassBody, + | TSESTree.TSTypeLiteral, ): void { const isSingleLine = body.loc.start.line === body.loc.end.line; diff --git a/packages/eslint-plugin/src/rules/member-delimiter-style.ts b/packages/eslint-plugin/src/rules/member-delimiter-style.ts index ac2d9e1aea42..e0055a385e17 100644 --- a/packages/eslint-plugin/src/rules/member-delimiter-style.ts +++ b/packages/eslint-plugin/src/rules/member-delimiter-style.ts @@ -28,10 +28,10 @@ type Config = BaseOptions & { }; type Options = [Config]; type MessageIds = - | 'unexpectedComma' - | 'unexpectedSemi' | 'expectedComma' - | 'expectedSemi'; + | 'expectedSemi' + | 'unexpectedComma' + | 'unexpectedSemi'; type LastTokenType = TSESTree.Token; interface MakeFixFunctionParams { diff --git a/packages/eslint-plugin/src/rules/member-ordering.ts b/packages/eslint-plugin/src/rules/member-ordering.ts index ee2093a19ede..29b748e88cfe 100644 --- a/packages/eslint-plugin/src/rules/member-ordering.ts +++ b/packages/eslint-plugin/src/rules/member-ordering.ts @@ -12,9 +12,9 @@ export type MessageIds = type ReadonlyType = 'readonly-field' | 'readonly-signature'; type MemberKind = + | ReadonlyType | 'call-signature' | 'constructor' - | ReadonlyType | 'field' | 'get' | 'method' @@ -25,16 +25,16 @@ type MemberKind = type DecoratedMemberKind = | Exclude | 'field' - | 'method' | 'get' + | 'method' | 'set'; type NonCallableMemberKind = Exclude< MemberKind, - 'constructor' | 'signature' | 'readonly-signature' + 'constructor' | 'readonly-signature' | 'signature' >; -type MemberScope = 'static' | 'instance' | 'abstract'; +type MemberScope = 'abstract' | 'instance' | 'static'; type Accessibility = TSESTree.Accessibility | '#private'; @@ -42,20 +42,20 @@ type BaseMemberType = | MemberKind | `${Accessibility}-${Exclude< MemberKind, - 'signature' | 'readonly-signature' | 'static-initialization' + 'readonly-signature' | 'signature' | 'static-initialization' >}` - | `${Accessibility}-decorated-${DecoratedMemberKind}` - | `decorated-${DecoratedMemberKind}` | `${Accessibility}-${MemberScope}-${NonCallableMemberKind}` - | `${MemberScope}-${NonCallableMemberKind}`; + | `${Accessibility}-decorated-${DecoratedMemberKind}` + | `${MemberScope}-${NonCallableMemberKind}` + | `decorated-${DecoratedMemberKind}`; type MemberType = BaseMemberType | BaseMemberType[]; type AlphabeticalOrder = - | 'alphabetically' | 'alphabetically-case-insensitive' - | 'natural' - | 'natural-case-insensitive'; + | 'alphabetically' + | 'natural-case-insensitive' + | 'natural'; type Order = AlphabeticalOrder | 'as-written'; @@ -372,11 +372,11 @@ function getNodeType(node: Member): MemberKind | null { function getMemberRawName( member: | TSESTree.MethodDefinition - | TSESTree.TSMethodSignature - | TSESTree.TSAbstractMethodDefinition + | TSESTree.Property | TSESTree.PropertyDefinition + | TSESTree.TSAbstractMethodDefinition | TSESTree.TSAbstractPropertyDefinition - | TSESTree.Property + | TSESTree.TSMethodSignature | TSESTree.TSPropertySignature, sourceCode: TSESLint.SourceCode, ): string { @@ -885,7 +885,7 @@ export default util.createRule({ // Standardize config let order: Order | undefined; - let memberTypes: string | MemberType[] | undefined; + let memberTypes: MemberType[] | string | undefined; let optionalityOrder: OptionalityOrder | undefined; // returns true if everything is good and false if an error was reported diff --git a/packages/eslint-plugin/src/rules/method-signature-style.ts b/packages/eslint-plugin/src/rules/method-signature-style.ts index e9db86cd6870..ee8ea18ebf83 100644 --- a/packages/eslint-plugin/src/rules/method-signature-style.ts +++ b/packages/eslint-plugin/src/rules/method-signature-style.ts @@ -3,7 +3,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as util from '../util'; -export type Options = [('property' | 'method')?]; +export type Options = [('method' | 'property')?]; export type MessageIds = 'errorMethod' | 'errorProperty'; export default util.createRule({ @@ -49,7 +49,7 @@ export default util.createRule({ } function getMethodParams( - node: TSESTree.TSMethodSignature | TSESTree.TSFunctionType, + node: TSESTree.TSFunctionType | TSESTree.TSMethodSignature, ): string { let params = '()'; if (node.params.length > 0) { @@ -78,7 +78,7 @@ export default util.createRule({ } function getMethodReturnType( - node: TSESTree.TSMethodSignature | TSESTree.TSFunctionType, + node: TSESTree.TSFunctionType | TSESTree.TSMethodSignature, ): string { return node.returnType == null ? // if the method has no return type, it implicitly has an `any` return type diff --git a/packages/eslint-plugin/src/rules/naming-convention-utils/enums.ts b/packages/eslint-plugin/src/rules/naming-convention-utils/enums.ts index 02900ab1d8b6..1b26c18ecb22 100644 --- a/packages/eslint-plugin/src/rules/naming-convention-utils/enums.ts +++ b/packages/eslint-plugin/src/rules/naming-convention-utils/enums.ts @@ -78,7 +78,7 @@ enum MetaSelectors { Selectors.typeProperty, } type MetaSelectorsString = keyof typeof MetaSelectors; -type IndividualAndMetaSelectorsString = SelectorsString | MetaSelectorsString; +type IndividualAndMetaSelectorsString = MetaSelectorsString | SelectorsString; enum Modifiers { // const variable diff --git a/packages/eslint-plugin/src/rules/naming-convention-utils/shared.ts b/packages/eslint-plugin/src/rules/naming-convention-utils/shared.ts index 9772f91ced8d..a1d63d31bad2 100644 --- a/packages/eslint-plugin/src/rules/naming-convention-utils/shared.ts +++ b/packages/eslint-plugin/src/rules/naming-convention-utils/shared.ts @@ -12,13 +12,13 @@ function selectorTypeToMessageString(selectorType: SelectorsString): string { } function isMetaSelector( - selector: IndividualAndMetaSelectorsString | Selectors | MetaSelectors, + selector: IndividualAndMetaSelectorsString | MetaSelectors | Selectors, ): selector is MetaSelectorsString { return selector in MetaSelectors; } function isMethodOrPropertySelector( - selector: IndividualAndMetaSelectorsString | Selectors | MetaSelectors, + selector: IndividualAndMetaSelectorsString | MetaSelectors | Selectors, ): boolean { return ( selector === MetaSelectors.method || selector === MetaSelectors.property diff --git a/packages/eslint-plugin/src/rules/naming-convention-utils/types.ts b/packages/eslint-plugin/src/rules/naming-convention-utils/types.ts index d5c15994b8bb..fd0910050e00 100644 --- a/packages/eslint-plugin/src/rules/naming-convention-utils/types.ts +++ b/packages/eslint-plugin/src/rules/naming-convention-utils/types.ts @@ -35,7 +35,7 @@ interface Selector { | IndividualAndMetaSelectorsString[]; modifiers?: ModifiersString[]; types?: TypeModifiersString[]; - filter?: string | MatchRegex; + filter?: MatchRegex | string; } interface NormalizedMatchRegex { @@ -52,7 +52,7 @@ interface NormalizedSelector { prefix: string[] | null; suffix: string[] | null; // selector options - selector: Selectors | MetaSelectors; + selector: MetaSelectors | Selectors; modifiers: Modifiers[] | null; types: TypeModifiers[] | null; filter: NormalizedMatchRegex | null; @@ -61,7 +61,7 @@ interface NormalizedSelector { } type ValidatorFunction = ( - node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.Literal | TSESTree.PrivateIdentifier, modifiers?: Set, ) => void; type ParsedOptions = Record; diff --git a/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts b/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts index 78fb3ca51708..4c80a167a0f7 100644 --- a/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts +++ b/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts @@ -25,7 +25,7 @@ function createValidator( context: Context, allConfigs: NormalizedSelector[], ): ( - node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.Literal | TSESTree.PrivateIdentifier, ) => void { // make sure the "highest priority" configs are checked first const selectorType = Selectors[type]; @@ -71,7 +71,7 @@ function createValidator( }); return ( - node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.Literal | TSESTree.PrivateIdentifier, modifiers: Set = new Set(), ): void => { const originalName = @@ -155,7 +155,7 @@ function createValidator( formats?: PredefinedFormats[]; originalName: string; processedName?: string; - position?: 'leading' | 'trailing' | 'prefix' | 'suffix'; + position?: 'leading' | 'prefix' | 'suffix' | 'trailing'; custom?: NonNullable; count?: 'one' | 'two'; }): Record { @@ -184,7 +184,7 @@ function createValidator( position: 'leading' | 'trailing', config: NormalizedSelector, name: string, - node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.Literal | TSESTree.PrivateIdentifier, originalName: string, ): string | null { const option = @@ -305,7 +305,7 @@ function createValidator( position: 'prefix' | 'suffix', config: NormalizedSelector, name: string, - node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.Literal | TSESTree.PrivateIdentifier, originalName: string, ): string | null { const affixes = config[position]; @@ -345,7 +345,7 @@ function createValidator( function validateCustom( config: NormalizedSelector, name: string, - node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.Literal | TSESTree.PrivateIdentifier, originalName: string, ): boolean { const custom = config.custom; @@ -378,7 +378,7 @@ function createValidator( function validatePredefinedFormat( config: NormalizedSelector, name: string, - node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.Literal | TSESTree.PrivateIdentifier, originalName: string, modifiers: Set, ): boolean { diff --git a/packages/eslint-plugin/src/rules/naming-convention.ts b/packages/eslint-plugin/src/rules/naming-convention.ts index acd91fd725b2..d3e52d377cf2 100644 --- a/packages/eslint-plugin/src/rules/naming-convention.ts +++ b/packages/eslint-plugin/src/rules/naming-convention.ts @@ -12,12 +12,12 @@ import type { import { Modifiers, parseOptions, SCHEMA } from './naming-convention-utils'; type MessageIds = - | 'unexpectedUnderscore' - | 'missingUnderscore' + | 'doesNotMatchFormat' + | 'doesNotMatchFormatTrimmed' | 'missingAffix' + | 'missingUnderscore' | 'satisfyCustom' - | 'doesNotMatchFormat' - | 'doesNotMatchFormatTrimmed'; + | 'unexpectedUnderscore'; // Note that this intentionally does not strictly type the modifiers/types properties. // This is because doing so creates a huge headache, as the rule's code doesn't need to care. @@ -94,13 +94,13 @@ export default util.createRule({ function handleMember( validator: ValidatorFunction, node: - | TSESTree.PropertyNonComputedName - | TSESTree.PropertyDefinitionNonComputedName - | TSESTree.TSAbstractPropertyDefinitionNonComputedName - | TSESTree.TSPropertySignatureNonComputedName | TSESTree.MethodDefinitionNonComputedName + | TSESTree.PropertyDefinitionNonComputedName + | TSESTree.PropertyNonComputedName | TSESTree.TSAbstractMethodDefinitionNonComputedName - | TSESTree.TSMethodSignatureNonComputedName, + | TSESTree.TSAbstractPropertyDefinitionNonComputedName + | TSESTree.TSMethodSignatureNonComputedName + | TSESTree.TSPropertySignatureNonComputedName, modifiers: Set, ): void { if (!validator) { @@ -117,10 +117,10 @@ export default util.createRule({ function getMemberModifiers( node: - | TSESTree.PropertyDefinition - | TSESTree.TSAbstractPropertyDefinition | TSESTree.MethodDefinition + | TSESTree.PropertyDefinition | TSESTree.TSAbstractMethodDefinition + | TSESTree.TSAbstractPropertyDefinition | TSESTree.TSParameterProperty, ): Set { const modifiers = new Set(); @@ -186,12 +186,12 @@ export default util.createRule({ function isAsyncMemberOrProperty( propertyOrMemberNode: - | TSESTree.PropertyNonComputedName - | TSESTree.TSMethodSignatureNonComputedName + | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionNonComputedName + | TSESTree.PropertyNonComputedName + | TSESTree.TSAbstractMethodDefinitionNonComputedName | TSESTree.TSAbstractPropertyDefinitionNonComputedName - | TSESTree.MethodDefinitionNonComputedName - | TSESTree.TSAbstractMethodDefinitionNonComputedName, + | TSESTree.TSMethodSignatureNonComputedName, ): boolean { return Boolean( 'value' in propertyOrMemberNode && @@ -273,8 +273,8 @@ export default util.createRule({ handler: ( node: | TSESTree.FunctionDeclaration - | TSESTree.TSDeclareFunction - | TSESTree.FunctionExpression, + | TSESTree.FunctionExpression + | TSESTree.TSDeclareFunction, validator, ): void => { if (node.id == null) { @@ -313,11 +313,11 @@ export default util.createRule({ validator: validators.parameter, handler: ( node: + | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.TSDeclareFunction - | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.FunctionExpression - | TSESTree.ArrowFunctionExpression, + | TSESTree.TSDeclareFunction + | TSESTree.TSEmptyBodyFunctionExpression, validator, ): void => { node.params.forEach(param => { @@ -442,10 +442,10 @@ export default util.createRule({ validator: validators.classMethod, handler: ( node: - | TSESTree.PropertyDefinitionNonComputedName - | TSESTree.TSAbstractPropertyDefinitionNonComputedName | TSESTree.MethodDefinitionNonComputedName - | TSESTree.TSAbstractMethodDefinitionNonComputedName, + | TSESTree.PropertyDefinitionNonComputedName + | TSESTree.TSAbstractMethodDefinitionNonComputedName + | TSESTree.TSAbstractPropertyDefinitionNonComputedName, validator, ): void => { const modifiers = getMemberModifiers(node); diff --git a/packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts b/packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts index f75396a27fe3..5e91950ed202 100644 --- a/packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-confusing-non-null-assertion.ts @@ -32,7 +32,7 @@ export default util.createRule({ const sourceCode = context.getSourceCode(); return { 'BinaryExpression, AssignmentExpression'( - node: TSESTree.BinaryExpression | TSESTree.AssignmentExpression, + node: TSESTree.AssignmentExpression | TSESTree.BinaryExpression, ): void { function isLeftHandPrimaryExpression( node: TSESTree.Expression | TSESTree.PrivateIdentifier, diff --git a/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts b/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts index 1a2b81b9f8f0..ab6f08c1bb55 100644 --- a/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts +++ b/packages/eslint-plugin/src/rules/no-confusing-void-expression.ts @@ -14,12 +14,12 @@ export type Options = [ export type MessageId = | 'invalidVoidExpr' - | 'invalidVoidExprWrapVoid' | 'invalidVoidExprArrow' | 'invalidVoidExprArrowWrapVoid' | 'invalidVoidExprReturn' | 'invalidVoidExprReturnLast' | 'invalidVoidExprReturnWrapVoid' + | 'invalidVoidExprWrapVoid' | 'voidExprWrapVoid'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/no-duplicate-enum-values.ts b/packages/eslint-plugin/src/rules/no-duplicate-enum-values.ts index 323acb805a02..8aeb1c4200b3 100644 --- a/packages/eslint-plugin/src/rules/no-duplicate-enum-values.ts +++ b/packages/eslint-plugin/src/rules/no-duplicate-enum-values.ts @@ -45,7 +45,7 @@ export default util.createRule({ return; } - let value: string | number | undefined; + let value: number | string | undefined; if (isStringLiteral(member.initializer)) { value = String(member.initializer.value); } else if (isNumberLiteral(member.initializer)) { diff --git a/packages/eslint-plugin/src/rules/no-empty-function.ts b/packages/eslint-plugin/src/rules/no-empty-function.ts index 8113ee6ce553..e77981eab301 100644 --- a/packages/eslint-plugin/src/rules/no-empty-function.ts +++ b/packages/eslint-plugin/src/rules/no-empty-function.ts @@ -131,7 +131,7 @@ export default util.createRule({ * @private */ function isAllowedEmptyDecoratedFunctions( - node: TSESTree.FunctionExpression | TSESTree.FunctionDeclaration, + node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression, ): boolean { if (isAllowedDecoratedFunctions && isBodyEmpty(node)) { const decorators = diff --git a/packages/eslint-plugin/src/rules/no-explicit-any.ts b/packages/eslint-plugin/src/rules/no-explicit-any.ts index f16da26fa62e..3e92039827da 100644 --- a/packages/eslint-plugin/src/rules/no-explicit-any.ts +++ b/packages/eslint-plugin/src/rules/no-explicit-any.ts @@ -9,7 +9,7 @@ export type Options = [ ignoreRestArgs?: boolean; }, ]; -export type MessageIds = 'unexpectedAny' | 'suggestUnknown' | 'suggestNever'; +export type MessageIds = 'suggestNever' | 'suggestUnknown' | 'unexpectedAny'; export default util.createRule({ name: 'no-explicit-any', diff --git a/packages/eslint-plugin/src/rules/no-extraneous-class.ts b/packages/eslint-plugin/src/rules/no-extraneous-class.ts index 6982283e0c95..8c6c64e089ca 100644 --- a/packages/eslint-plugin/src/rules/no-extraneous-class.ts +++ b/packages/eslint-plugin/src/rules/no-extraneous-class.ts @@ -11,7 +11,7 @@ type Options = [ allowWithDecorator?: boolean; }, ]; -type MessageIds = 'empty' | 'onlyStatic' | 'onlyConstructor'; +type MessageIds = 'empty' | 'onlyConstructor' | 'onlyStatic'; export default util.createRule({ name: 'no-extraneous-class', diff --git a/packages/eslint-plugin/src/rules/no-floating-promises.ts b/packages/eslint-plugin/src/rules/no-floating-promises.ts index 053e6763693d..00c86a09c11b 100644 --- a/packages/eslint-plugin/src/rules/no-floating-promises.ts +++ b/packages/eslint-plugin/src/rules/no-floating-promises.ts @@ -15,9 +15,9 @@ type Options = [ type MessageId = | 'floating' - | 'floatingVoid' + | 'floatingFixAwait' | 'floatingFixVoid' - | 'floatingFixAwait'; + | 'floatingVoid'; export default util.createRule({ name: 'no-floating-promises', diff --git a/packages/eslint-plugin/src/rules/no-implied-eval.ts b/packages/eslint-plugin/src/rules/no-implied-eval.ts index 9c4a83b5d1b4..0560d7647c42 100644 --- a/packages/eslint-plugin/src/rules/no-implied-eval.ts +++ b/packages/eslint-plugin/src/rules/no-implied-eval.ts @@ -131,7 +131,7 @@ export default util.createRule({ } function checkImpliedEval( - node: TSESTree.NewExpression | TSESTree.CallExpression, + node: TSESTree.CallExpression | TSESTree.NewExpression, ): void { const calleeName = getCalleeName(node.callee); if (calleeName == null) { diff --git a/packages/eslint-plugin/src/rules/no-inferrable-types.ts b/packages/eslint-plugin/src/rules/no-inferrable-types.ts index 4a1ed72eff82..54823f7be392 100644 --- a/packages/eslint-plugin/src/rules/no-inferrable-types.ts +++ b/packages/eslint-plugin/src/rules/no-inferrable-types.ts @@ -90,12 +90,12 @@ export default util.createRule({ type Keywords = | TSESTree.TSBigIntKeyword | TSESTree.TSBooleanKeyword - | TSESTree.TSNumberKeyword | TSESTree.TSNullKeyword + | TSESTree.TSNumberKeyword | TSESTree.TSStringKeyword | TSESTree.TSSymbolKeyword - | TSESTree.TSUndefinedKeyword - | TSESTree.TSTypeReference; + | TSESTree.TSTypeReference + | TSESTree.TSUndefinedKeyword; const keywordMap = { [AST_NODE_TYPES.TSBigIntKeyword]: 'bigint', [AST_NODE_TYPES.TSBooleanKeyword]: 'boolean', @@ -193,9 +193,9 @@ export default util.createRule({ */ function reportInferrableType( node: - | TSESTree.VariableDeclarator | TSESTree.Parameter - | TSESTree.PropertyDefinition, + | TSESTree.PropertyDefinition + | TSESTree.VariableDeclarator, typeNode: TSESTree.TSTypeAnnotation | undefined, initNode: TSESTree.Expression | null | undefined, ): void { @@ -243,9 +243,9 @@ export default util.createRule({ function inferrableParameterVisitor( node: - | TSESTree.FunctionExpression + | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.ArrowFunctionExpression, + | TSESTree.FunctionExpression, ): void { if (ignoreParameters || !node.params) { return; diff --git a/packages/eslint-plugin/src/rules/no-invalid-void-type.ts b/packages/eslint-plugin/src/rules/no-invalid-void-type.ts index 38872f499ca0..4808a439f5a3 100644 --- a/packages/eslint-plugin/src/rules/no-invalid-void-type.ts +++ b/packages/eslint-plugin/src/rules/no-invalid-void-type.ts @@ -4,14 +4,14 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as util from '../util'; interface Options { - allowInGenericTypeArguments?: boolean | string[]; + allowInGenericTypeArguments?: string[] | boolean; allowAsThisParameter?: boolean; } type MessageIds = | 'invalidVoidForGeneric' - | 'invalidVoidNotReturnOrGeneric' | 'invalidVoidNotReturn' + | 'invalidVoidNotReturnOrGeneric' | 'invalidVoidNotReturnOrThisParam' | 'invalidVoidNotReturnOrThisParamOrGeneric' | 'invalidVoidUnionConstituent'; diff --git a/packages/eslint-plugin/src/rules/no-loop-func.ts b/packages/eslint-plugin/src/rules/no-loop-func.ts index 5fcac7e417e2..f4e4b50825c9 100644 --- a/packages/eslint-plugin/src/rules/no-loop-func.ts +++ b/packages/eslint-plugin/src/rules/no-loop-func.ts @@ -35,8 +35,8 @@ export default util.createRule({ function checkForLoops( node: | TSESTree.ArrowFunctionExpression - | TSESTree.FunctionExpression - | TSESTree.FunctionDeclaration, + | TSESTree.FunctionDeclaration + | TSESTree.FunctionExpression, ): void { const loopNode = getContainingLoopNode(node); diff --git a/packages/eslint-plugin/src/rules/no-misused-new.ts b/packages/eslint-plugin/src/rules/no-misused-new.ts index e435b55f5dd3..41df0cb5f997 100644 --- a/packages/eslint-plugin/src/rules/no-misused-new.ts +++ b/packages/eslint-plugin/src/rules/no-misused-new.ts @@ -25,9 +25,9 @@ export default util.createRule({ */ function getTypeReferenceName( node: + | TSESTree.EntityName | TSESTree.TSTypeAnnotation | TSESTree.TypeNode - | TSESTree.EntityName | undefined, ): string | null { if (node) { @@ -50,7 +50,7 @@ export default util.createRule({ * @param returnType type to be compared */ function isMatchingParentType( - parent: undefined | TSESTree.Node, + parent: TSESTree.Node | undefined, returnType: TSESTree.TSTypeAnnotation | undefined, ): boolean { if ( diff --git a/packages/eslint-plugin/src/rules/no-misused-promises.ts b/packages/eslint-plugin/src/rules/no-misused-promises.ts index 3728d567621a..a5fe0721b88d 100644 --- a/packages/eslint-plugin/src/rules/no-misused-promises.ts +++ b/packages/eslint-plugin/src/rules/no-misused-promises.ts @@ -8,7 +8,7 @@ import * as util from '../util'; type Options = [ { checksConditionals?: boolean; - checksVoidReturn?: boolean | ChecksVoidReturnOptions; + checksVoidReturn?: ChecksVoidReturnOptions | boolean; checksSpreads?: boolean; }, ]; @@ -23,15 +23,15 @@ interface ChecksVoidReturnOptions { type MessageId = | 'conditional' + | 'spread' | 'voidReturnArgument' - | 'voidReturnVariable' + | 'voidReturnAttribute' | 'voidReturnProperty' | 'voidReturnReturnValue' - | 'voidReturnAttribute' - | 'spread'; + | 'voidReturnVariable'; function parseChecksVoidReturn( - checksVoidReturn: boolean | ChecksVoidReturnOptions | undefined, + checksVoidReturn: ChecksVoidReturnOptions | boolean | undefined, ): ChecksVoidReturnOptions | false { switch (checksVoidReturn) { case false: diff --git a/packages/eslint-plugin/src/rules/no-non-null-assertion.ts b/packages/eslint-plugin/src/rules/no-non-null-assertion.ts index b997e6fde3fa..ba8b88158def 100644 --- a/packages/eslint-plugin/src/rules/no-non-null-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-non-null-assertion.ts @@ -29,7 +29,7 @@ export default util.createRule<[], MessageIds>({ TSNonNullExpression(node): void { const suggest: TSESLint.ReportSuggestionArray = []; function convertTokenToOptional( - replacement: '?' | '?.', + replacement: '?.' | '?', ): TSESLint.ReportFixFunction { return (fixer: TSESLint.RuleFixer): TSESLint.RuleFix | null => { const operator = sourceCode.getTokenAfter( diff --git a/packages/eslint-plugin/src/rules/no-redeclare.ts b/packages/eslint-plugin/src/rules/no-redeclare.ts index 3591895fa575..1f47b575c813 100644 --- a/packages/eslint-plugin/src/rules/no-redeclare.ts +++ b/packages/eslint-plugin/src/rules/no-redeclare.ts @@ -67,8 +67,8 @@ export default util.createRule({ function* iterateDeclarations(variable: TSESLint.Scope.Variable): Generator< { - type: 'builtin' | 'syntax' | 'comment'; - node?: TSESTree.Identifier | TSESTree.Comment; + type: 'builtin' | 'comment' | 'syntax'; + node?: TSESTree.Comment | TSESTree.Identifier; loc?: TSESTree.SourceLocation; }, void, diff --git a/packages/eslint-plugin/src/rules/no-shadow.ts b/packages/eslint-plugin/src/rules/no-shadow.ts index 461d5cb60162..ed202e9ea759 100644 --- a/packages/eslint-plugin/src/rules/no-shadow.ts +++ b/packages/eslint-plugin/src/rules/no-shadow.ts @@ -529,7 +529,7 @@ export default util.createRule({ */ function getDeclaredLocation( variable: TSESLint.Scope.Variable, - ): { global: true } | { global: false; line: number; column: number } { + ): { global: false; line: number; column: number } | { global: true } { const identifier = variable.identifiers[0]; if (identifier) { return { diff --git a/packages/eslint-plugin/src/rules/no-this-alias.ts b/packages/eslint-plugin/src/rules/no-this-alias.ts index 49010d9579e3..57a326e2e808 100644 --- a/packages/eslint-plugin/src/rules/no-this-alias.ts +++ b/packages/eslint-plugin/src/rules/no-this-alias.ts @@ -55,7 +55,7 @@ export default util.createRule({ create(context, [{ allowDestructuring, allowedNames }]) { return { "VariableDeclarator[init.type='ThisExpression'], AssignmentExpression[right.type='ThisExpression']"( - node: TSESTree.VariableDeclarator | TSESTree.AssignmentExpression, + node: TSESTree.AssignmentExpression | TSESTree.VariableDeclarator, ): void { const id = node.type === AST_NODE_TYPES.VariableDeclarator ? node.id : node.left; diff --git a/packages/eslint-plugin/src/rules/no-type-alias.ts b/packages/eslint-plugin/src/rules/no-type-alias.ts index cc41d65f78e8..cc568a6fa9db 100644 --- a/packages/eslint-plugin/src/rules/no-type-alias.ts +++ b/packages/eslint-plugin/src/rules/no-type-alias.ts @@ -5,10 +5,10 @@ import * as util from '../util'; type Values = | 'always' - | 'never' - | 'in-unions' | 'in-intersections' - | 'in-unions-and-intersections'; + | 'in-unions-and-intersections' + | 'in-unions' + | 'never'; type Options = [ { @@ -22,11 +22,11 @@ type Options = [ allowGenerics?: 'always' | 'never'; }, ]; -type MessageIds = 'noTypeAlias' | 'noCompositionAlias'; +type MessageIds = 'noCompositionAlias' | 'noTypeAlias'; type CompositionType = - | AST_NODE_TYPES.TSUnionType - | AST_NODE_TYPES.TSIntersectionType; + | AST_NODE_TYPES.TSIntersectionType + | AST_NODE_TYPES.TSUnionType; interface TypeWithLabel { node: TSESTree.Node; compositionType: CompositionType | null; diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts index c2cb6a218447..d0aba2defc7a 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-boolean-literal-compare.ts @@ -6,11 +6,11 @@ import * as ts from 'typescript'; import * as util from '../util'; type MessageIds = - | 'direct' - | 'negated' + | 'comparingNullableToFalse' | 'comparingNullableToTrueDirect' | 'comparingNullableToTrueNegated' - | 'comparingNullableToFalse'; + | 'direct' + | 'negated'; type Options = [ { diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts index 7809ccf1bdf0..007a8a07a6d6 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-condition.ts @@ -64,16 +64,16 @@ export type Options = [ ]; export type MessageId = - | 'alwaysTruthy' | 'alwaysFalsy' - | 'alwaysTruthyFunc' | 'alwaysFalsyFunc' - | 'neverNullish' | 'alwaysNullish' + | 'alwaysTruthy' + | 'alwaysTruthyFunc' | 'literalBooleanExpression' - | 'noOverlapBooleanExpression' | 'never' + | 'neverNullish' | 'neverOptionalChain' + | 'noOverlapBooleanExpression' | 'noStrictNullCheck'; export default createRule({ @@ -488,7 +488,7 @@ export default createRule({ // ?.y // This access is considered "unnecessary" according to the types // ``` function optionChainContainsOptionArrayIndex( - node: TSESTree.MemberExpression | TSESTree.CallExpression, + node: TSESTree.CallExpression | TSESTree.MemberExpression, ): boolean { const lhsNode = node.type === AST_NODE_TYPES.CallExpression ? node.callee : node.object; @@ -588,9 +588,9 @@ export default createRule({ } function checkOptionalChain( - node: TSESTree.MemberExpression | TSESTree.CallExpression, + node: TSESTree.CallExpression | TSESTree.MemberExpression, beforeOperator: TSESTree.Node, - fix: '' | '.', + fix: '.' | '', ): void { // We only care if this step in the chain is optional. If just descend // from an optional chain, then that's fine. diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts index 2abcfddfc578..c1c558dab8a0 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-qualifier.ts @@ -126,9 +126,9 @@ export default util.createRule({ function enterDeclaration( node: - | TSESTree.TSModuleDeclaration + | TSESTree.ExportNamedDeclaration | TSESTree.TSEnumDeclaration - | TSESTree.ExportNamedDeclaration, + | TSESTree.TSModuleDeclaration, ): void { namespacesInScope.push(esTreeNodeToTSNodeMap.get(node)); } diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts index e0d305cc0dd4..cb3b881e8feb 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-arguments.ts @@ -6,15 +6,15 @@ import * as util from '../util'; import { findFirstResult } from '../util'; type ParameterCapableTSNode = - | ts.TaggedTemplateExpression - | ts.ImportTypeNode | ts.CallExpression - | ts.NewExpression - | ts.TypeReferenceNode | ts.ExpressionWithTypeArguments + | ts.ImportTypeNode | ts.JsxOpeningElement | ts.JsxSelfClosingElement - | ts.TypeQueryNode; + | ts.NewExpression + | ts.TaggedTemplateExpression + | ts.TypeQueryNode + | ts.TypeReferenceNode; type MessageIds = 'unnecessaryTypeParameter'; @@ -136,7 +136,7 @@ function getTypeParametersFromNode( } function getTypeParametersFromType( - type: ts.EntityName | ts.Expression | ts.ClassDeclaration, + type: ts.ClassDeclaration | ts.EntityName | ts.Expression, checker: ts.TypeChecker, ): readonly ts.TypeParameterDeclaration[] | undefined { const symAtLocation = checker.getSymbolAtLocation(type); diff --git a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts index 589a257e572b..d466b59fe076 100644 --- a/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts +++ b/packages/eslint-plugin/src/rules/no-unnecessary-type-assertion.ts @@ -228,7 +228,7 @@ export default util.createRule({ } }, 'TSAsExpression, TSTypeAssertion'( - node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression, + node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion, ): void { if ( options.typesToIgnore?.includes( diff --git a/packages/eslint-plugin/src/rules/no-unsafe-argument.ts b/packages/eslint-plugin/src/rules/no-unsafe-argument.ts index 0f1294229183..dab8c33be89c 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-argument.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-argument.ts @@ -6,9 +6,9 @@ import * as util from '../util'; type MessageIds = | 'unsafeArgument' - | 'unsafeTupleSpread' | 'unsafeArraySpread' - | 'unsafeSpread'; + | 'unsafeSpread' + | 'unsafeTupleSpread'; const enum RestTypeKind { Array, @@ -22,13 +22,13 @@ type RestType = index: number; } | { - typeArguments: readonly ts.Type[]; - kind: RestTypeKind.Tuple; + type: ts.Type; + kind: RestTypeKind.Other; index: number; } | { - type: ts.Type; - kind: RestTypeKind.Other; + typeArguments: readonly ts.Type[]; + kind: RestTypeKind.Tuple; index: number; }; diff --git a/packages/eslint-plugin/src/rules/no-unused-vars.ts b/packages/eslint-plugin/src/rules/no-unused-vars.ts index a847294a52d7..7c174482dcdc 100644 --- a/packages/eslint-plugin/src/rules/no-unused-vars.ts +++ b/packages/eslint-plugin/src/rules/no-unused-vars.ts @@ -11,7 +11,7 @@ export type Options = [ | { vars?: 'all' | 'local'; varsIgnorePattern?: string; - args?: 'all' | 'after-used' | 'none'; + args?: 'after-used' | 'all' | 'none'; ignoreRestSiblings?: boolean; argsIgnorePattern?: string; caughtErrors?: 'all' | 'none'; @@ -23,7 +23,7 @@ export type Options = [ interface TranslatedOptions { vars: 'all' | 'local'; varsIgnorePattern?: RegExp; - args: 'all' | 'after-used' | 'none'; + args: 'after-used' | 'all' | 'none'; ignoreRestSiblings: boolean; argsIgnorePattern?: RegExp; caughtErrors: 'all' | 'none'; @@ -486,13 +486,13 @@ export default util.createRule({ } type DeclarationSelectorNode = - | TSESTree.TSInterfaceDeclaration - | TSESTree.TSTypeAliasDeclaration | TSESTree.ClassDeclaration | TSESTree.FunctionDeclaration | TSESTree.TSDeclareFunction | TSESTree.TSEnumDeclaration + | TSESTree.TSInterfaceDeclaration | TSESTree.TSModuleDeclaration + | TSESTree.TSTypeAliasDeclaration | TSESTree.VariableDeclaration; function ambientDeclarationSelector( parent: string, diff --git a/packages/eslint-plugin/src/rules/no-use-before-define.ts b/packages/eslint-plugin/src/rules/no-use-before-define.ts index 8cca3042691e..7d15cd25a19d 100644 --- a/packages/eslint-plugin/src/rules/no-use-before-define.ts +++ b/packages/eslint-plugin/src/rules/no-use-before-define.ts @@ -10,7 +10,7 @@ const SENTINEL_TYPE = /** * Parses a given value as options. */ -function parseOptions(options: string | Config | null): Required { +function parseOptions(options: Config | string | null): Required { let functions = true; let classes = true; let enums = true; @@ -233,7 +233,7 @@ interface Config { ignoreTypeReferences?: boolean; allowNamedExports?: boolean; } -type Options = ['nofunc' | Config]; +type Options = [Config | 'nofunc']; type MessageIds = 'noUseBeforeDefine'; export default util.createRule({ diff --git a/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts b/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts index 9b0a313e756e..2cfdd7ea1f88 100644 --- a/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts +++ b/packages/eslint-plugin/src/rules/non-nullable-type-assertion-style.ts @@ -89,7 +89,7 @@ export default util.createRule({ }; const isConstAssertion = ( - node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression, + node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion, ): boolean => { return ( node.typeAnnotation.type === AST_NODE_TYPES.TSTypeReference && @@ -100,7 +100,7 @@ export default util.createRule({ return { 'TSAsExpression, TSTypeAssertion'( - node: TSESTree.TSTypeAssertion | TSESTree.TSAsExpression, + node: TSESTree.TSAsExpression | TSESTree.TSTypeAssertion, ): void { if (isConstAssertion(node)) { return; 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 deeeafadad5a..ad7852337c32 100644 --- a/packages/eslint-plugin/src/rules/padding-line-between-statements.ts +++ b/packages/eslint-plugin/src/rules/padding-line-between-statements.ts @@ -28,8 +28,8 @@ interface NodeTestObject { interface PaddingOption { blankLine: keyof typeof PaddingTypes; - prev: string | string[]; - next: string | string[]; + prev: string[] | string; + next: string[] | string; } type MessageIds = 'expectedBlankLine' | 'unexpectedBlankLine'; @@ -644,10 +644,10 @@ export default util.createRule({ // eslint-disable-next-line no-restricted-syntax -- We need all raw options. const configureList = context.options || []; - type Scope = null | { + type Scope = { upper: Scope; prevNode: TSESTree.Node | null; - }; + } | null; let scopeInfo: Scope = null; @@ -682,7 +682,7 @@ export default util.createRule({ * @returns `true` if the statement node matched the type. * @private */ - function match(node: TSESTree.Node, type: string | string[]): boolean { + function match(node: TSESTree.Node, type: string[] | string): boolean { let innerStatementNode = node; while (innerStatementNode.type === AST_NODE_TYPES.LabeledStatement) { diff --git a/packages/eslint-plugin/src/rules/parameter-properties.ts b/packages/eslint-plugin/src/rules/parameter-properties.ts index f70bdb8b81b1..f97f8f736ed4 100644 --- a/packages/eslint-plugin/src/rules/parameter-properties.ts +++ b/packages/eslint-plugin/src/rules/parameter-properties.ts @@ -4,13 +4,13 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as util from '../util'; type Modifier = - | 'readonly' + | 'private readonly' | 'private' + | 'protected readonly' | 'protected' + | 'public readonly' | 'public' - | 'private readonly' - | 'protected readonly' - | 'public readonly'; + | 'readonly'; type Prefer = 'class-property' | 'parameter-property'; diff --git a/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts b/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts index 9d01f3af0266..2cf8660b34f7 100644 --- a/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts +++ b/packages/eslint-plugin/src/rules/prefer-nullish-coalescing.ts @@ -15,10 +15,10 @@ export type Options = [ ]; export type MessageIds = + | 'noStrictNullCheck' | 'preferNullishOverOr' | 'preferNullishOverTernary' - | 'suggestNullish' - | 'noStrictNullCheck'; + | 'suggestNullish'; export default util.createRule({ name: 'prefer-nullish-coalescing', @@ -174,7 +174,7 @@ export default util.createRule({ return; } - let operator: '==' | '!=' | '===' | '!==' | undefined; + let operator: '!=' | '!==' | '==' | '===' | undefined; let nodesInsideTestExpression: TSESTree.Node[] = []; if (node.test.type === AST_NODE_TYPES.BinaryExpression) { nodesInsideTestExpression = [node.test.left, node.test.right]; diff --git a/packages/eslint-plugin/src/rules/prefer-optional-chain.ts b/packages/eslint-plugin/src/rules/prefer-optional-chain.ts index f3cbeb3b8423..e0662cd03482 100644 --- a/packages/eslint-plugin/src/rules/prefer-optional-chain.ts +++ b/packages/eslint-plugin/src/rules/prefer-optional-chain.ts @@ -9,10 +9,10 @@ type ValidChainTarget = | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.Identifier - | TSESTree.PrivateIdentifier | TSESTree.MemberExpression - | TSESTree.ThisExpression - | TSESTree.MetaProperty; + | TSESTree.MetaProperty + | TSESTree.PrivateIdentifier + | TSESTree.ThisExpression; /* The AST is always constructed such the first element is always the deepest element. @@ -479,7 +479,7 @@ interface ReportIfMoreThanOneOptions { sourceCode: Readonly; context: Readonly< TSESLint.RuleContext< - 'preferOptionalChain' | 'optionalChainSuggest', + 'optionalChainSuggest' | 'preferOptionalChain', never[] > >; diff --git a/packages/eslint-plugin/src/rules/prefer-readonly.ts b/packages/eslint-plugin/src/rules/prefer-readonly.ts index 1f177251dbc8..713a703a56f0 100644 --- a/packages/eslint-plugin/src/rules/prefer-readonly.ts +++ b/packages/eslint-plugin/src/rules/prefer-readonly.ts @@ -336,10 +336,10 @@ class ClassScope { public enterConstructor( node: + | ts.ConstructorDeclaration | ts.GetAccessorDeclaration - | ts.SetAccessorDeclaration | ts.MethodDeclaration - | ts.ConstructorDeclaration, + | ts.SetAccessorDeclaration, ): void { this.constructorScopeDepth = DIRECTLY_INSIDE_CONSTRUCTOR; diff --git a/packages/eslint-plugin/src/rules/prefer-return-this-type.ts b/packages/eslint-plugin/src/rules/prefer-return-this-type.ts index b0ae1acd8ff0..bc8375d7a7dc 100644 --- a/packages/eslint-plugin/src/rules/prefer-return-this-type.ts +++ b/packages/eslint-plugin/src/rules/prefer-return-this-type.ts @@ -9,8 +9,8 @@ type ClassLikeDeclaration = | TSESTree.ClassExpression; type FunctionLike = - | TSESTree.MethodDefinition['value'] - | TSESTree.ArrowFunctionExpression; + | TSESTree.ArrowFunctionExpression + | TSESTree.MethodDefinition['value']; export default createRule({ name: 'prefer-return-this-type', diff --git a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts index 79a5a3d0b839..d6afab60146d 100644 --- a/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts +++ b/packages/eslint-plugin/src/rules/prefer-string-starts-ends-with.ts @@ -315,7 +315,7 @@ export default createRule({ function* fixWithRightOperand( fixer: TSESLint.RuleFixer, node: TSESTree.BinaryExpression, - kind: 'start' | 'end', + kind: 'end' | 'start', isNegative: boolean, isOptional: boolean, ): IterableIterator { @@ -346,7 +346,7 @@ export default createRule({ node: TSESTree.BinaryExpression, callNode: TSESTree.CallExpression, calleeNode: TSESTree.MemberExpression, - kind: 'start' | 'end', + kind: 'end' | 'start', negative: boolean, isOptional: boolean, ): IterableIterator { diff --git a/packages/eslint-plugin/src/rules/require-await.ts b/packages/eslint-plugin/src/rules/require-await.ts index b59bfe41bbbe..de3624ecbf7d 100644 --- a/packages/eslint-plugin/src/rules/require-await.ts +++ b/packages/eslint-plugin/src/rules/require-await.ts @@ -13,9 +13,9 @@ interface ScopeInfo { isAsyncYield: boolean; } type FunctionNode = + | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression - | TSESTree.ArrowFunctionExpression; + | TSESTree.FunctionExpression; export default util.createRule({ name: 'require-await', @@ -148,7 +148,7 @@ export default util.createRule({ 'ArrowFunctionExpression[async = true] > :not(BlockStatement, AwaitExpression)'( node: Exclude< TSESTree.Node, - TSESTree.BlockStatement | TSESTree.AwaitExpression + TSESTree.AwaitExpression | TSESTree.BlockStatement >, ): void { const expression = services.esTreeNodeToTSNodeMap.get(node); diff --git a/packages/eslint-plugin/src/rules/return-await.ts b/packages/eslint-plugin/src/rules/return-await.ts index f9d6584d13f8..35863976ce6f 100644 --- a/packages/eslint-plugin/src/rules/return-await.ts +++ b/packages/eslint-plugin/src/rules/return-await.ts @@ -7,9 +7,9 @@ import * as util from '../util'; import { getOperatorPrecedence } from '../util/getOperatorPrecedence'; type FunctionNode = + | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression - | TSESTree.ArrowFunctionExpression; + | TSESTree.FunctionExpression; interface ScopeInfo { hasAsync: boolean; diff --git a/packages/eslint-plugin/src/rules/space-before-function-paren.ts b/packages/eslint-plugin/src/rules/space-before-function-paren.ts index d82e8a94b26a..e6015783a670 100644 --- a/packages/eslint-plugin/src/rules/space-before-function-paren.ts +++ b/packages/eslint-plugin/src/rules/space-before-function-paren.ts @@ -3,7 +3,7 @@ import { AST_NODE_TYPES } from '@typescript-eslint/utils'; import * as util from '../util'; -type Option = 'never' | 'always'; +type Option = 'always' | 'never'; type FuncOption = Option | 'ignore'; export type Options = [ @@ -14,7 +14,7 @@ export type Options = [ asyncArrow?: FuncOption; }, ]; -export type MessageIds = 'unexpected' | 'missing'; +export type MessageIds = 'missing' | 'unexpected'; export default util.createRule({ name: 'space-before-function-paren', @@ -75,8 +75,8 @@ export default util.createRule({ | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression - | TSESTree.TSEmptyBodyFunctionExpression - | TSESTree.TSDeclareFunction, + | TSESTree.TSDeclareFunction + | TSESTree.TSEmptyBodyFunctionExpression, ): boolean { if (node.id != null) { return true; @@ -102,8 +102,8 @@ export default util.createRule({ | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression - | TSESTree.TSEmptyBodyFunctionExpression - | TSESTree.TSDeclareFunction, + | TSESTree.TSDeclareFunction + | TSESTree.TSEmptyBodyFunctionExpression, ): FuncOption { if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) { // Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar @@ -134,8 +134,8 @@ export default util.createRule({ | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression - | TSESTree.TSEmptyBodyFunctionExpression - | TSESTree.TSDeclareFunction, + | TSESTree.TSDeclareFunction + | TSESTree.TSEmptyBodyFunctionExpression, ): void { const functionConfig = getConfigForFunction(node); diff --git a/packages/eslint-plugin/src/rules/space-infix-ops.ts b/packages/eslint-plugin/src/rules/space-infix-ops.ts index 3b83b20e3789..c1df490436fd 100644 --- a/packages/eslint-plugin/src/rules/space-infix-ops.ts +++ b/packages/eslint-plugin/src/rules/space-infix-ops.ts @@ -70,8 +70,8 @@ export default util.createRule({ } function checkAndReportAssignmentSpace( - leftNode: TSESTree.Token | TSESTree.Node | null, - rightNode?: TSESTree.Token | TSESTree.Node | null, + leftNode: TSESTree.Node | TSESTree.Token | null, + rightNode?: TSESTree.Node | TSESTree.Token | null, ): void { if (!rightNode || !leftNode) { return; diff --git a/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts index de2d99205fd7..3e0d60d48cea 100644 --- a/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts +++ b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts @@ -23,29 +23,29 @@ export type Options = [ ]; export type MessageId = - | 'conditionErrorOther' | 'conditionErrorAny' - | 'conditionErrorNullish' | 'conditionErrorNullableBoolean' - | 'conditionErrorString' + | 'conditionErrorNullableEnum' + | 'conditionErrorNullableNumber' + | 'conditionErrorNullableObject' | 'conditionErrorNullableString' + | 'conditionErrorNullish' | 'conditionErrorNumber' - | 'conditionErrorNullableNumber' | 'conditionErrorObject' - | 'conditionErrorNullableObject' - | 'conditionErrorNullableEnum' - | 'noStrictNullCheck' - | 'conditionFixDefaultFalse' - | 'conditionFixDefaultEmptyString' - | 'conditionFixDefaultZero' - | 'conditionFixCompareNullish' + | 'conditionErrorOther' + | 'conditionErrorString' | 'conditionFixCastBoolean' - | 'conditionFixCompareTrue' + | 'conditionFixCompareEmptyString' | 'conditionFixCompareFalse' + | 'conditionFixCompareNaN' + | 'conditionFixCompareNullish' | 'conditionFixCompareStringLength' - | 'conditionFixCompareEmptyString' + | 'conditionFixCompareTrue' | 'conditionFixCompareZero' - | 'conditionFixCompareNaN'; + | 'conditionFixDefaultEmptyString' + | 'conditionFixDefaultFalse' + | 'conditionFixDefaultZero' + | 'noStrictNullCheck'; export default util.createRule({ name: 'strict-boolean-expressions', @@ -792,17 +792,17 @@ export default util.createRule({ /** The types we care about */ type VariantType = - | 'nullish' + | 'any' | 'boolean' - | 'truthy boolean' - | 'string' - | 'truthy string' + | 'enum' + | 'never' + | 'nullish' | 'number' - | 'truthy number' | 'object' - | 'enum' - | 'any' - | 'never'; + | 'string' + | 'truthy boolean' + | 'truthy number' + | 'truthy string'; /** * Check union variants for the types we care about diff --git a/packages/eslint-plugin/src/rules/typedef.ts b/packages/eslint-plugin/src/rules/typedef.ts index 51820a11ef95..595081906afa 100644 --- a/packages/eslint-plugin/src/rules/typedef.ts +++ b/packages/eslint-plugin/src/rules/typedef.ts @@ -152,7 +152,7 @@ export default util.createRule<[Options], MessageIds>({ } function isAncestorHasTypeAnnotation( - node: TSESTree.ObjectPattern | TSESTree.ArrayPattern, + node: TSESTree.ArrayPattern | TSESTree.ObjectPattern, ): boolean { let ancestor: TSESTree.Node | undefined = node.parent; diff --git a/packages/eslint-plugin/src/rules/unbound-method.ts b/packages/eslint-plugin/src/rules/unbound-method.ts index f3cc2b711859..ce2ec6ccd735 100644 --- a/packages/eslint-plugin/src/rules/unbound-method.ts +++ b/packages/eslint-plugin/src/rules/unbound-method.ts @@ -205,7 +205,7 @@ export default util.createRule({ checkMethodAndReport(node, services.getSymbolAtLocation(node)); }, 'VariableDeclarator, AssignmentExpression'( - node: TSESTree.VariableDeclarator | TSESTree.AssignmentExpression, + node: TSESTree.AssignmentExpression | TSESTree.VariableDeclarator, ): void { const [idNode, initNode] = node.type === AST_NODE_TYPES.VariableDeclarator diff --git a/packages/eslint-plugin/src/rules/unified-signatures.ts b/packages/eslint-plugin/src/rules/unified-signatures.ts index 79c969d0c2b0..1a033f905ba2 100644 --- a/packages/eslint-plugin/src/rules/unified-signatures.ts +++ b/packages/eslint-plugin/src/rules/unified-signatures.ts @@ -9,15 +9,15 @@ interface Failure { } type Unify = - | { - kind: 'single-parameter-difference'; - p0: TSESTree.Parameter; - p1: TSESTree.Parameter; - } | { kind: 'extra-parameter'; extraParameter: TSESTree.Parameter; otherSignature: SignatureDefinition; + } + | { + kind: 'single-parameter-difference'; + p0: TSESTree.Parameter; + p1: TSESTree.Parameter; }; /** @@ -27,16 +27,16 @@ type Unify = type IsTypeParameter = (typeName: string) => boolean; type ScopeNode = + | TSESTree.ClassBody | TSESTree.Program - | TSESTree.TSModuleBlock | TSESTree.TSInterfaceBody - | TSESTree.ClassBody + | TSESTree.TSModuleBlock | TSESTree.TSTypeLiteral; type OverloadNode = MethodDefinition | SignatureDefinition; type ContainingNode = - | TSESTree.ExportNamedDeclaration - | TSESTree.ExportDefaultDeclaration; + | TSESTree.ExportDefaultDeclaration + | TSESTree.ExportNamedDeclaration; type SignatureDefinition = | TSESTree.FunctionExpression @@ -582,8 +582,8 @@ export default util.createRule({ function getExportingNode( node: TSESTree.TSDeclareFunction, ): - | TSESTree.ExportNamedDeclaration | TSESTree.ExportDefaultDeclaration + | TSESTree.ExportNamedDeclaration | undefined { return node.parent.type === AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES.ExportDefaultDeclaration diff --git a/packages/eslint-plugin/src/util/getFunctionHeadLoc.ts b/packages/eslint-plugin/src/util/getFunctionHeadLoc.ts index e81d6ca8e625..ddc004d0397d 100644 --- a/packages/eslint-plugin/src/util/getFunctionHeadLoc.ts +++ b/packages/eslint-plugin/src/util/getFunctionHeadLoc.ts @@ -3,8 +3,8 @@ import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/utils'; type FunctionNode = | TSESTree.ArrowFunctionExpression - | TSESTree.FunctionExpression - | TSESTree.FunctionDeclaration; + | TSESTree.FunctionDeclaration + | TSESTree.FunctionExpression; /** * Creates a report location for the given function. diff --git a/packages/eslint-plugin/src/util/misc.ts b/packages/eslint-plugin/src/util/misc.ts index 8362736bd628..4c4823cf5045 100644 --- a/packages/eslint-plugin/src/util/misc.ts +++ b/packages/eslint-plugin/src/util/misc.ts @@ -32,7 +32,7 @@ function upperCaseFirst(str: string): string { return str[0].toUpperCase() + str.slice(1); } -function arrayGroupByToMap( +function arrayGroupByToMap( array: T[], getKey: (item: T) => Key, ): Map { @@ -108,11 +108,11 @@ enum MemberNameType { function getNameFromMember( member: | TSESTree.MethodDefinition - | TSESTree.TSMethodSignature - | TSESTree.TSAbstractMethodDefinition + | TSESTree.Property | TSESTree.PropertyDefinition + | TSESTree.TSAbstractMethodDefinition | TSESTree.TSAbstractPropertyDefinition - | TSESTree.Property + | TSESTree.TSMethodSignature | TSESTree.TSPropertySignature, sourceCode: TSESLint.SourceCode, ): { type: MemberNameType; name: string } { @@ -188,7 +188,7 @@ function formatWordList(words: string[]): string { */ function findLastIndex( members: T[], - predicate: (member: T) => boolean | undefined | null, + predicate: (member: T) => boolean | null | undefined, ): number { let idx = members.length - 1; diff --git a/packages/eslint-plugin/tests/RuleTester.ts b/packages/eslint-plugin/tests/RuleTester.ts index 21abfa49c951..741b33e0260c 100644 --- a/packages/eslint-plugin/tests/RuleTester.ts +++ b/packages/eslint-plugin/tests/RuleTester.ts @@ -44,8 +44,8 @@ export function batchedSingleLineTests< TMessageIds extends string, TOptions extends readonly unknown[], >( - options: ValidTestCase | InvalidTestCase, -): (ValidTestCase | InvalidTestCase)[] { + options: InvalidTestCase | ValidTestCase, +): (InvalidTestCase | ValidTestCase)[] { // -- eslint counts lines from 1 const lineOffset = options.code.startsWith('\n') ? 2 : 1; const output = diff --git a/packages/eslint-plugin/tests/rules/block-spacing.test.ts b/packages/eslint-plugin/tests/rules/block-spacing.test.ts index 3dac892e3977..dabb15e692f3 100644 --- a/packages/eslint-plugin/tests/rules/block-spacing.test.ts +++ b/packages/eslint-plugin/tests/rules/block-spacing.test.ts @@ -12,7 +12,7 @@ const ruleTester = new RuleTester({ }); type InvalidBlockSpacingTestCase = InvalidTestCase< - 'missing' | 'extra', + 'extra' | 'missing', ['always' | 'never'] >; diff --git a/packages/eslint-plugin/tests/rules/indent/utils.ts b/packages/eslint-plugin/tests/rules/indent/utils.ts index 70d5f7a93b88..ae0b6e502ed0 100644 --- a/packages/eslint-plugin/tests/rules/indent/utils.ts +++ b/packages/eslint-plugin/tests/rules/indent/utils.ts @@ -68,7 +68,7 @@ export function expectedErrors( providedErrors: ProvidedError | ProvidedError[], ): TSESLint.TestCaseError[]; export function expectedErrors( - providedIndentType: string | ProvidedError | ProvidedError[], + providedIndentType: ProvidedError | ProvidedError[] | string, providedErrors?: ProvidedError | ProvidedError[], ): TSESLint.TestCaseError[] { let indentType: string; diff --git a/packages/eslint-plugin/tests/rules/naming-convention/cases/createTestCases.ts b/packages/eslint-plugin/tests/rules/naming-convention/cases/createTestCases.ts index cdb37896e8c8..7f7f0efcd491 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention/cases/createTestCases.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention/cases/createTestCases.ts @@ -13,7 +13,7 @@ import type { import { selectorTypeToMessageString } from '../../../../src/rules/naming-convention-utils'; export const formatTestNames: Readonly< - Record> + Record> > = { camelCase: { valid: ['strictCamelCase', 'lower', 'camelCaseUNSTRICT'], diff --git a/packages/eslint-plugin/tests/rules/prefer-string-starts-ends-with.test.ts b/packages/eslint-plugin/tests/rules/prefer-string-starts-ends-with.test.ts index 1440a6521fd2..aaea8e8b36c7 100644 --- a/packages/eslint-plugin/tests/rules/prefer-string-starts-ends-with.test.ts +++ b/packages/eslint-plugin/tests/rules/prefer-string-starts-ends-with.test.ts @@ -1064,8 +1064,8 @@ ruleTester.run('prefer-string-starts-ends-with', rule, { }); type Case> = - | TSESLint.ValidTestCase - | TSESLint.InvalidTestCase; + | TSESLint.InvalidTestCase + | TSESLint.ValidTestCase; function addOptional>( cases: (TSESLint.ValidTestCase | string)[], ): TSESLint.ValidTestCase[]; diff --git a/packages/eslint-plugin/tests/rules/sort-type-constituents.test.ts b/packages/eslint-plugin/tests/rules/sort-type-constituents.test.ts index 81a0754f73e5..e1a2afc38288 100644 --- a/packages/eslint-plugin/tests/rules/sort-type-constituents.test.ts +++ b/packages/eslint-plugin/tests/rules/sort-type-constituents.test.ts @@ -11,7 +11,7 @@ const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', }); -const valid = (operator: '|' | '&'): TSESLint.ValidTestCase[] => [ +const valid = (operator: '&' | '|'): TSESLint.ValidTestCase[] => [ { code: `type T = A ${operator} B;`, }, @@ -86,7 +86,7 @@ type T = }, ]; const invalid = ( - operator: '|' | '&', + operator: '&' | '|', ): TSESLint.InvalidTestCase[] => { const type = operator === '|' ? 'Union' : 'Intersection'; return [ diff --git a/packages/eslint-plugin/tools/generate-configs.ts b/packages/eslint-plugin/tools/generate-configs.ts index 1ddf337d8cf6..5056bdb7de42 100644 --- a/packages/eslint-plugin/tools/generate-configs.ts +++ b/packages/eslint-plugin/tools/generate-configs.ts @@ -52,7 +52,7 @@ async function main(): Promise { } interface LinterConfig extends TSESLint.Linter.Config { - extends?: string | string[]; + extends?: string[] | string; plugins?: string[]; } diff --git a/packages/eslint-plugin/typings/eslint-rules.d.ts b/packages/eslint-plugin/typings/eslint-rules.d.ts index 68ce182646cf..295dd4d757c5 100644 --- a/packages/eslint-plugin/typings/eslint-rules.d.ts +++ b/packages/eslint-plugin/typings/eslint-rules.d.ts @@ -8,10 +8,10 @@ declare module 'eslint/lib/rules/arrow-parens' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - | 'unexpectedParens' | 'expectedParens' - | 'unexpectedParensInline' - | 'expectedParensBlock', + | 'expectedParensBlock' + | 'unexpectedParens' + | 'unexpectedParensInline', [ 'always' | 'as-needed', { @@ -35,7 +35,7 @@ declare module 'eslint/lib/rules/camelcase' { allow?: string[]; ignoreDestructuring?: boolean; properties?: 'always' | 'never'; - genericType?: 'never' | 'always'; + genericType?: 'always' | 'never'; }, ], { @@ -52,7 +52,7 @@ declare module 'eslint/lib/rules/indent' { const rule: TSESLint.RuleModule< 'wrongIndentation', [ - ('tab' | number)?, + (number | 'tab')?, { SwitchCase?: number; VariableDeclarator?: @@ -107,9 +107,9 @@ declare module 'eslint/lib/rules/indent' { 'DoWhileStatement, WhileStatement, ForInStatement, ForOfStatement'( node: | TSESTree.DoWhileStatement - | TSESTree.WhileStatement | TSESTree.ForInStatement - | TSESTree.ForOfStatement, + | TSESTree.ForOfStatement + | TSESTree.WhileStatement, ): void; ExportNamedDeclaration(node: TSESTree.ExportNamedDeclaration): void; ForStatement(node: TSESTree.ForStatement): void; @@ -120,8 +120,8 @@ declare module 'eslint/lib/rules/indent' { ImportDeclaration(node: TSESTree.ImportDeclaration): void; 'MemberExpression, JSXMemberExpression, MetaProperty'( node: - | TSESTree.MemberExpression | TSESTree.JSXMemberExpression + | TSESTree.MemberExpression | TSESTree.MetaProperty, ): void; NewExpression(node: TSESTree.NewExpression): void; @@ -149,33 +149,33 @@ declare module 'eslint/lib/rules/key-spacing' { { beforeColon?: boolean; afterColon?: boolean; - mode?: 'strict' | 'minimum'; + mode?: 'minimum' | 'strict'; align?: - | 'value' | 'colon' + | 'value' | { - on?: 'value' | 'colon'; + on?: 'colon' | 'value'; beforeColon?: boolean; afterColon?: boolean; - mode?: 'strict' | 'minimum'; + mode?: 'minimum' | 'strict'; }; singleLine?: { beforeColon?: boolean; afterColon?: boolean; - mode?: 'strict' | 'minimum'; + mode?: 'minimum' | 'strict'; }; multiLine?: { beforeColon?: boolean; afterColon?: boolean; - mode?: 'strict' | 'minimum'; + mode?: 'minimum' | 'strict'; align?: - | 'value' | 'colon' + | 'value' | { - on?: 'value' | 'colon'; + on?: 'colon' | 'value'; beforeColon?: boolean; afterColon?: boolean; - mode?: 'strict' | 'minimum'; + mode?: 'minimum' | 'strict'; }; }; }, @@ -211,10 +211,10 @@ declare module 'eslint/lib/rules/keyword-spacing' { }, ]; type MessageIds = - | 'expectedBefore' | 'expectedAfter' - | 'unexpectedBefore' - | 'unexpectedAfter'; + | 'expectedBefore' + | 'unexpectedAfter' + | 'unexpectedBefore'; const rule: TSESLint.RuleModule< MessageIds, @@ -329,10 +329,10 @@ declare module 'eslint/lib/rules/no-implicit-globals' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - | 'globalNonLexicalBinding' + | 'assignmentToReadonlyGlobal' | 'globalLexicalBinding' + | 'globalNonLexicalBinding' | 'globalVariableLeak' - | 'assignmentToReadonlyGlobal' | 'redeclarationOfReadonlyGlobal', [], { @@ -402,7 +402,7 @@ declare module 'eslint/lib/rules/no-restricted-globals' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - 'defaultMessage' | 'customMessage', + 'customMessage' | 'defaultMessage', ( | string | { @@ -465,7 +465,7 @@ declare module 'eslint/lib/rules/no-unused-vars' { | { vars?: 'all' | 'local'; varsIgnorePattern?: string; - args?: 'all' | 'after-used' | 'none'; + args?: 'after-used' | 'all' | 'none'; ignoreRestSiblings?: boolean; argsIgnorePattern?: string; caughtErrors?: 'all' | 'none'; @@ -525,15 +525,15 @@ declare module 'eslint/lib/rules/strict' { const rule: TSESLint.RuleModule< | 'function' | 'global' + | 'implied' + | 'module' | 'multiple' | 'never' + | 'nonSimpleParameterList' | 'unnecessary' - | 'module' - | 'implied' | 'unnecessaryInClasses' - | 'nonSimpleParameterList' | 'wrap', - ['never' | 'global' | 'function' | 'safe'], + ['function' | 'global' | 'never' | 'safe'], { ArrowFunctionExpression(node: TSESTree.ArrowFunctionExpression): void; } @@ -565,7 +565,7 @@ declare module 'eslint/lib/rules/no-extra-parens' { conditionalAssign?: boolean; returnAssign?: boolean; nestedBinaryExpressions?: boolean; - ignoreJSX?: 'none' | 'all' | 'multi-line' | 'single-line'; + ignoreJSX?: 'all' | 'multi-line' | 'none' | 'single-line'; enforceForArrowConditionals?: boolean; }?, ], @@ -615,7 +615,7 @@ declare module 'eslint/lib/rules/semi' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - 'missingSemi' | 'extraSemi', + 'extraSemi' | 'missingSemi', [ 'always' | 'never', { @@ -647,7 +647,7 @@ declare module 'eslint/lib/rules/quotes' { const rule: TSESLint.RuleModule< 'wrongQuotes', [ - 'single' | 'double' | 'backtick', + 'backtick' | 'double' | 'single', { allowTemplateLiterals?: boolean; avoidEscape?: boolean; @@ -665,7 +665,7 @@ declare module 'eslint/lib/rules/block-spacing' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - 'missing' | 'extra', + 'extra' | 'missing', ['always' | 'never'], { BlockStatement(node: TSESTree.BlockStatement): void; @@ -680,14 +680,14 @@ declare module 'eslint/lib/rules/brace-style' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - | 'nextLineOpen' - | 'sameLineOpen' | 'blockSameLine' | 'nextLineClose' - | 'singleLineClose' - | 'sameLineClose', + | 'nextLineOpen' + | 'sameLineClose' + | 'sameLineOpen' + | 'singleLineClose', [ - '1tbs' | 'stroustrup' | 'allman', + '1tbs' | 'allman' | 'stroustrup', { allowSingleLine?: boolean; }?, @@ -839,7 +839,7 @@ declare module 'eslint/lib/rules/dot-notation' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - 'useDot' | 'useBrackets', + 'useBrackets' | 'useDot', [ { allowKeywords?: boolean; @@ -879,18 +879,18 @@ declare module 'eslint/lib/rules/comma-dangle' { | 'only-multiline'; type Selectors = | 'arrays' - | 'objects' - | 'imports' + | 'enums' | 'exports' | 'functions' - | 'enums' | 'generics' + | 'imports' + | 'objects' | 'tuples'; type ObjectOptions = Partial>; const rule: TSESLint.RuleModule< - 'unexpected' | 'missing', - [StringOptions | ObjectOptions], + 'missing' | 'unexpected', + [ObjectOptions | StringOptions], { TSEnumDeclaration(node: TSESTree.TSEnumDeclaration): void; TSTypeParameterDeclaration( @@ -954,7 +954,7 @@ declare module 'eslint/lib/rules/prefer-const' { 'useConst', [ { - destructuring?: 'any' | 'all'; + destructuring?: 'all' | 'any'; ignoreReadBeforeAssign?: boolean; }, ], @@ -970,10 +970,10 @@ declare module 'eslint/lib/rules/object-curly-spacing' { import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; const rule: TSESLint.RuleModule< - | 'requireSpaceBefore' | 'requireSpaceAfter' - | 'unexpectedSpaceBefore' - | 'unexpectedSpaceAfter', + | 'requireSpaceBefore' + | 'unexpectedSpaceAfter' + | 'unexpectedSpaceBefore', [ 'always' | 'never', { @@ -1006,14 +1006,14 @@ declare module 'eslint/lib/rules/no-restricted-imports' { } )[]; export type ArrayOfStringOrObjectPatterns = - | string[] | { group: string[]; message?: string; caseSensitive?: boolean; // extended allowTypeImports?: boolean; - }[]; + }[] + | string[]; } interface ObjectOfPathsAndPatterns { @@ -1022,14 +1022,14 @@ declare module 'eslint/lib/rules/no-restricted-imports' { } const rule: TSESLint.RuleModule< - | 'path' - | 'pathWithCustomMessage' - | 'patterns' - | 'patternWithCustomMessage' | 'everything' | 'everythingWithCustomMessage' | 'importName' - | 'importNameWithCustomMessage', + | 'importNameWithCustomMessage' + | 'path' + | 'pathWithCustomMessage' + | 'patterns' + | 'patternWithCustomMessage', rule.ArrayOfStringOrObject | [ObjectOfPathsAndPatterns], { ImportDeclaration(node: TSESTree.ImportDeclaration): void; diff --git a/packages/parser/src/parser.ts b/packages/parser/src/parser.ts index 73f7587ca556..8577dd61bccd 100644 --- a/packages/parser/src/parser.ts +++ b/packages/parser/src/parser.ts @@ -78,14 +78,14 @@ function getLib(compilerOptions: ts.CompilerOptions): Lib[] { } function parse( - code: string | ts.SourceFile, + code: ts.SourceFile | string, options?: ParserOptions, ): ParseForESLintResult['ast'] { return parseForESLint(code, options).ast; } function parseForESLint( - code: string | ts.SourceFile, + code: ts.SourceFile | string, options?: ParserOptions | null, ): ParseForESLintResult { if (!options || typeof options !== 'object') { diff --git a/packages/rule-schema-to-typescript-types/src/printAST.ts b/packages/rule-schema-to-typescript-types/src/printAST.ts index f05829535504..70dd47924f4e 100644 --- a/packages/rule-schema-to-typescript-types/src/printAST.ts +++ b/packages/rule-schema-to-typescript-types/src/printAST.ts @@ -14,7 +14,7 @@ export function printASTWithComment(ast: AST): string { function printComment({ commentLines: commentLinesIn, }: { - readonly commentLines?: string[] | undefined | null; + readonly commentLines?: string[] | null | undefined; }): string { if (commentLinesIn == null || commentLinesIn.length === 0) { return ''; diff --git a/packages/rule-tester/src/RuleTester.ts b/packages/rule-tester/src/RuleTester.ts index cf2b394d7162..cc6577611378 100644 --- a/packages/rule-tester/src/RuleTester.ts +++ b/packages/rule-tester/src/RuleTester.ts @@ -73,7 +73,7 @@ let defaultConfig = deepMerge( export class RuleTester extends TestFramework { readonly #testerConfig: TesterConfigWithDefaults; - readonly #rules: Record = {}; + readonly #rules: Record = {}; readonly #linter: Linter = new Linter(); /** @@ -145,7 +145,7 @@ export class RuleTester extends TestFramework { * Adds the `only` property to a test to run it in isolation. */ static only>( - item: string | ValidTestCase, + item: ValidTestCase | string, ): ValidTestCase; /** * Adds the `only` property to a test to run it in isolation. @@ -155,10 +155,10 @@ export class RuleTester extends TestFramework { ): InvalidTestCase; static only>( item: - | string + | InvalidTestCase | ValidTestCase - | InvalidTestCase, - ): ValidTestCase | InvalidTestCase { + | string, + ): InvalidTestCase | ValidTestCase { if (typeof item === 'string') { return { code: item, only: true }; } @@ -169,7 +169,7 @@ export class RuleTester extends TestFramework { /** * Define a rule for one particular run of tests. */ - defineRule(name: string, rule: AnyRuleModule | AnyRuleCreateFunction): void { + defineRule(name: string, rule: AnyRuleCreateFunction | AnyRuleModule): void { this.#rules[name] = rule; } @@ -206,8 +206,8 @@ export class RuleTester extends TestFramework { TMessageIds extends string, TOptions extends readonly unknown[], T extends - | ValidTestCase - | InvalidTestCase, + | InvalidTestCase + | ValidTestCase, >( test: T, ): T => { @@ -284,8 +284,8 @@ export class RuleTester extends TestFramework { */ const maybeMarkAsOnly = < T extends - | ValidTestCase - | InvalidTestCase, + | InvalidTestCase + | ValidTestCase, >( test: T, ): T => { @@ -436,7 +436,7 @@ export class RuleTester extends TestFramework { >( ruleName: string, rule: RuleModule, - item: ValidTestCase | InvalidTestCase, + item: InvalidTestCase | ValidTestCase, ): { messages: Linter.LintMessage[]; output: string; @@ -625,7 +625,7 @@ export class RuleTester extends TestFramework { >( ruleName: string, rule: RuleModule, - itemIn: string | ValidTestCase, + itemIn: ValidTestCase | string, ): void { const item: ValidTestCase = typeof itemIn === 'object' ? itemIn : { code: itemIn }; @@ -1013,7 +1013,7 @@ function assertASTDidntChange(beforeAST: unknown, afterAST: unknown): void { * value is a regular expression, it is checked against the actual * value. */ -function assertMessageMatches(actual: string, expected: string | RegExp): void { +function assertMessageMatches(actual: string, expected: RegExp | string): void { if (expected instanceof RegExp) { // assert.js doesn't have a built-in RegExp match function assert.ok( diff --git a/packages/rule-tester/src/types/DependencyConstraint.ts b/packages/rule-tester/src/types/DependencyConstraint.ts index 37cb3d5a1805..ecb86e912cdb 100644 --- a/packages/rule-tester/src/types/DependencyConstraint.ts +++ b/packages/rule-tester/src/types/DependencyConstraint.ts @@ -2,16 +2,16 @@ import type { RangeOptions } from 'semver'; export interface SemverVersionConstraint { readonly range: string; - readonly options?: boolean | RangeOptions; + readonly options?: RangeOptions | boolean; } export type AtLeastVersionConstraint = - | `${number}` - | `${number}.${number}` + | `${number}.${number}.${number}-${string}` | `${number}.${number}.${number}` - | `${number}.${number}.${number}-${string}`; + | `${number}.${number}` + | `${number}`; export type VersionConstraint = - | SemverVersionConstraint - | AtLeastVersionConstraint; + | AtLeastVersionConstraint + | SemverVersionConstraint; export interface DependencyConstraint { /** * Passing a string for the value is shorthand for a '>=' constraint diff --git a/packages/rule-tester/src/types/ValidTestCase.ts b/packages/rule-tester/src/types/ValidTestCase.ts index 4aa2ef0aa6c4..74776b58f199 100644 --- a/packages/rule-tester/src/types/ValidTestCase.ts +++ b/packages/rule-tester/src/types/ValidTestCase.ts @@ -25,7 +25,7 @@ export interface ValidTestCase> { /** * The additional global variables. */ - readonly globals?: Record; + readonly globals?: Record; /** * Options for the test case. */ diff --git a/packages/rule-tester/src/types/index.ts b/packages/rule-tester/src/types/index.ts index bebb6786af89..a4901875d9e6 100644 --- a/packages/rule-tester/src/types/index.ts +++ b/packages/rule-tester/src/types/index.ts @@ -6,8 +6,8 @@ type Mutable = { -readonly [P in keyof T]: T[P]; }; export type TesterConfigWithDefaults = Mutable< - RuleTesterConfig & - Required> + Required> & + RuleTesterConfig >; export interface RunTests< diff --git a/packages/scope-manager/src/analyze.ts b/packages/scope-manager/src/analyze.ts index de115c1117d4..2ab613325c95 100644 --- a/packages/scope-manager/src/analyze.ts +++ b/packages/scope-manager/src/analyze.ts @@ -55,7 +55,7 @@ interface AnalyzeOptions { /** * The source type of the script. */ - sourceType?: 'script' | 'module'; + sourceType?: 'module' | 'script'; /** * Emit design-type metadata for decorated declarations in source. diff --git a/packages/scope-manager/src/definition/ImportBindingDefinition.ts b/packages/scope-manager/src/definition/ImportBindingDefinition.ts index 2003158b84ef..9ac45579fc4c 100644 --- a/packages/scope-manager/src/definition/ImportBindingDefinition.ts +++ b/packages/scope-manager/src/definition/ImportBindingDefinition.ts @@ -5,9 +5,9 @@ import { DefinitionType } from './DefinitionType'; class ImportBindingDefinition extends DefinitionBase< DefinitionType.ImportBinding, - | TSESTree.ImportSpecifier | TSESTree.ImportDefaultSpecifier | TSESTree.ImportNamespaceSpecifier + | TSESTree.ImportSpecifier | TSESTree.TSImportEqualsDeclaration, TSESTree.ImportDeclaration | TSESTree.TSImportEqualsDeclaration, TSESTree.Identifier diff --git a/packages/scope-manager/src/referencer/ClassVisitor.ts b/packages/scope-manager/src/referencer/ClassVisitor.ts index e1653cbd2188..6123ab15e794 100644 --- a/packages/scope-manager/src/referencer/ClassVisitor.ts +++ b/packages/scope-manager/src/referencer/ClassVisitor.ts @@ -244,8 +244,8 @@ class ClassVisitor extends Visitor { | TSESTree.AccessorProperty | TSESTree.PropertyDefinition | TSESTree.TSAbstractAccessorProperty - | TSESTree.TSAbstractPropertyDefinition - | TSESTree.TSAbstractMethodDefinition, + | TSESTree.TSAbstractMethodDefinition + | TSESTree.TSAbstractPropertyDefinition, ): void { if (node.computed) { this.#referencer.visit(node.key); @@ -417,7 +417,7 @@ class ClassVisitor extends Visitor { */ function getLiteralMethodKeyName( node: TSESTree.MethodDefinition, -): string | number | null { +): number | string | null { if (node.computed && node.key.type === AST_NODE_TYPES.Literal) { if ( typeof node.key.value === 'string' || diff --git a/packages/scope-manager/src/referencer/PatternVisitor.ts b/packages/scope-manager/src/referencer/PatternVisitor.ts index 53de28469e85..6e1140e18959 100644 --- a/packages/scope-manager/src/referencer/PatternVisitor.ts +++ b/packages/scope-manager/src/referencer/PatternVisitor.ts @@ -7,7 +7,7 @@ import { VisitorBase } from './VisitorBase'; type PatternVisitorCallback = ( pattern: TSESTree.Identifier, info: { - assignments: (TSESTree.AssignmentPattern | TSESTree.AssignmentExpression)[]; + assignments: (TSESTree.AssignmentExpression | TSESTree.AssignmentPattern)[]; rest: boolean; topLevel: boolean; }, @@ -18,12 +18,12 @@ class PatternVisitor extends VisitorBase { public static isPattern( node: TSESTree.Node, ): node is + | TSESTree.ArrayPattern + | TSESTree.AssignmentPattern | TSESTree.Identifier | TSESTree.ObjectPattern - | TSESTree.ArrayPattern - | TSESTree.SpreadElement | TSESTree.RestElement - | TSESTree.AssignmentPattern { + | TSESTree.SpreadElement { const nodeType = node.type; return ( @@ -39,8 +39,8 @@ class PatternVisitor extends VisitorBase { readonly #rootPattern: TSESTree.Node; readonly #callback: PatternVisitorCallback; readonly #assignments: ( - | TSESTree.AssignmentPattern | TSESTree.AssignmentExpression + | TSESTree.AssignmentPattern )[] = []; public readonly rightHandNodes: TSESTree.Node[] = []; readonly #restElements: TSESTree.RestElement[] = []; diff --git a/packages/scope-manager/src/referencer/Referencer.ts b/packages/scope-manager/src/referencer/Referencer.ts index 90f75490904f..38e4a0d2adac 100644 --- a/packages/scope-manager/src/referencer/Referencer.ts +++ b/packages/scope-manager/src/referencer/Referencer.ts @@ -307,8 +307,8 @@ class Referencer extends Visitor { protected visitTypeAssertion( node: | TSESTree.TSAsExpression - | TSESTree.TSTypeAssertion - | TSESTree.TSSatisfiesExpression, + | TSESTree.TSSatisfiesExpression + | TSESTree.TSTypeAssertion, ): void { this.visit(node.expression); this.visitType(node.typeAnnotation); diff --git a/packages/scope-manager/src/referencer/Visitor.ts b/packages/scope-manager/src/referencer/Visitor.ts index a6b07b18efa2..bbcf348734df 100644 --- a/packages/scope-manager/src/referencer/Visitor.ts +++ b/packages/scope-manager/src/referencer/Visitor.ts @@ -12,7 +12,7 @@ interface VisitPatternOptions extends PatternVisitorOptions { } class Visitor extends VisitorBase { readonly #options: VisitorOptions; - constructor(optionsOrVisitor: VisitorOptions | Visitor) { + constructor(optionsOrVisitor: Visitor | VisitorOptions) { super( optionsOrVisitor instanceof Visitor ? optionsOrVisitor.#options diff --git a/packages/scope-manager/src/scope/FunctionScope.ts b/packages/scope-manager/src/scope/FunctionScope.ts index c2a48fc45c3f..8e8b405cd6a7 100644 --- a/packages/scope-manager/src/scope/FunctionScope.ts +++ b/packages/scope-manager/src/scope/FunctionScope.ts @@ -13,9 +13,9 @@ class FunctionScope extends ScopeBase< | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration | TSESTree.FunctionExpression + | TSESTree.Program | TSESTree.TSDeclareFunction - | TSESTree.TSEmptyBodyFunctionExpression - | TSESTree.Program, + | TSESTree.TSEmptyBodyFunctionExpression, Scope > { constructor( diff --git a/packages/scope-manager/src/scope/Scope.ts b/packages/scope-manager/src/scope/Scope.ts index 708869313a61..87999d4b74b3 100644 --- a/packages/scope-manager/src/scope/Scope.ts +++ b/packages/scope-manager/src/scope/Scope.ts @@ -20,8 +20,8 @@ import type { WithScope } from './WithScope'; type Scope = | BlockScope | CatchScope - | ClassScope | ClassFieldInitializerScope + | ClassScope | ClassStaticBlockScope | ConditionalTypeScope | ForScope diff --git a/packages/scope-manager/src/scope/ScopeBase.ts b/packages/scope-manager/src/scope/ScopeBase.ts index ae26d129cb56..e107c7d90570 100644 --- a/packages/scope-manager/src/scope/ScopeBase.ts +++ b/packages/scope-manager/src/scope/ScopeBase.ts @@ -124,7 +124,7 @@ function registerScope(scopeManager: ScopeManager, scope: Scope): void { const generator = createIdGenerator(); -type VariableScope = GlobalScope | FunctionScope | ModuleScope | TSModuleScope; +type VariableScope = FunctionScope | GlobalScope | ModuleScope | TSModuleScope; const VARIABLE_SCOPE_TYPES = new Set([ ScopeType.classFieldInitializer, ScopeType.classStaticBlock, @@ -413,7 +413,7 @@ abstract class ScopeBase< } protected defineVariable( - nameOrVariable: string | Variable, + nameOrVariable: Variable | string, set: Map, variables: Variable[], node: TSESTree.Identifier | null, diff --git a/packages/scope-manager/tests/fixtures.test.ts b/packages/scope-manager/tests/fixtures.test.ts index 06af753bc52d..9f628bfe41e8 100644 --- a/packages/scope-manager/tests/fixtures.test.ts +++ b/packages/scope-manager/tests/fixtures.test.ts @@ -37,7 +37,7 @@ const fixtures = glob const FOUR_SLASH = /^\/\/\/\/[ ]+@(\w+)[ ]*=[ ]*(.+)$/; const QUOTED_STRING = /^["'](.+?)['"]$/; -type ALLOWED_VALUE = ['number' | 'boolean' | 'string', Set?]; +type ALLOWED_VALUE = ['boolean' | 'number' | 'string', Set?]; const ALLOWED_OPTIONS: Map = new Map< keyof AnalyzeOptions, ALLOWED_VALUE diff --git a/packages/scope-manager/tests/util/parse.ts b/packages/scope-manager/tests/util/parse.ts index 70983bfdd90a..1ba739d66ed6 100644 --- a/packages/scope-manager/tests/util/parse.ts +++ b/packages/scope-manager/tests/util/parse.ts @@ -42,8 +42,8 @@ function parseAndAnalyze( function parseAndAnalyze( code: string, sourceTypeOrAnalyzeOption: - | SourceType - | AnalyzeOptions = DEFAULT_ANALYZE_OPTIONS, + | AnalyzeOptions + | SourceType = DEFAULT_ANALYZE_OPTIONS, parserOptions: tseslint.TSESTreeOptions = DEFAULT_PARSER_OPTIONS, ): ParseAndAnalyze { const ast = parse(code, { ...parserOptions }); diff --git a/packages/type-utils/src/TypeOrValueSpecifier.ts b/packages/type-utils/src/TypeOrValueSpecifier.ts index 0230f911dfb2..5542bf7d6022 100644 --- a/packages/type-utils/src/TypeOrValueSpecifier.ts +++ b/packages/type-utils/src/TypeOrValueSpecifier.ts @@ -5,26 +5,26 @@ import type * as ts from 'typescript'; interface FileSpecifier { from: 'file'; - name: string | string[]; + name: string[] | string; path?: string; } interface LibSpecifier { from: 'lib'; - name: string | string[]; + name: string[] | string; } interface PackageSpecifier { from: 'package'; - name: string | string[]; + name: string[] | string; package: string; } export type TypeOrValueSpecifier = - | string | FileSpecifier | LibSpecifier - | PackageSpecifier; + | PackageSpecifier + | string; export const typeOrValueSpecifierSchema: JSONSchema4 = { oneOf: [ @@ -118,7 +118,7 @@ export const typeOrValueSpecifierSchema: JSONSchema4 = { ], }; -function specifierNameMatches(type: ts.Type, name: string | string[]): boolean { +function specifierNameMatches(type: ts.Type, name: string[] | string): boolean { if (typeof name === 'string') { name = [name]; } diff --git a/packages/type-utils/src/isTypeReadonly.ts b/packages/type-utils/src/isTypeReadonly.ts index 9fc8d7c62164..8cfee5272b14 100644 --- a/packages/type-utils/src/isTypeReadonly.ts +++ b/packages/type-utils/src/isTypeReadonly.ts @@ -231,7 +231,7 @@ function isTypeReadonlyRecurser( type: ts.Type, options: ReadonlynessOptions, seenTypes: Set, -): Readonlyness.Readonly | Readonlyness.Mutable { +): Readonlyness.Mutable | Readonlyness.Readonly { const checker = program.getTypeChecker(); seenTypes.add(type); diff --git a/packages/types/src/lib.ts b/packages/types/src/lib.ts index c1c60650ffd4..bdd8348d24e2 100644 --- a/packages/types/src/lib.ts +++ b/packages/types/src/lib.ts @@ -4,89 +4,89 @@ // npx nx generate-lib @typescript-eslint/scope-manager type Lib = + | 'decorators.legacy' + | 'decorators' + | 'dom.iterable' + | 'dom' | 'es5' | 'es6' - | 'es2015' | 'es7' - | 'es2016' - | 'es2017' - | 'es2018' - | 'es2019' - | 'es2020' - | 'es2021' - | 'es2022' - | 'es2023' - | 'esnext' - | 'dom' - | 'dom.iterable' - | 'webworker' - | 'webworker.importscripts' - | 'webworker.iterable' - | 'scripthost' - | 'es2015.core' | 'es2015.collection' + | 'es2015.core' | 'es2015.generator' | 'es2015.iterable' | 'es2015.promise' | 'es2015.proxy' | 'es2015.reflect' - | 'es2015.symbol' | 'es2015.symbol.wellknown' + | 'es2015.symbol' + | 'es2015' | 'es2016.array.include' + | 'es2016.full' + | 'es2016' + | 'es2017.full' + | 'es2017.intl' | 'es2017.object' | 'es2017.sharedmemory' | 'es2017.string' - | 'es2017.intl' | 'es2017.typedarrays' + | 'es2017' | 'es2018.asyncgenerator' | 'es2018.asynciterable' + | 'es2018.full' | 'es2018.intl' | 'es2018.promise' | 'es2018.regexp' + | 'es2018' | 'es2019.array' + | 'es2019.full' + | 'es2019.intl' | 'es2019.object' | 'es2019.string' | 'es2019.symbol' - | 'es2019.intl' + | 'es2019' | 'es2020.bigint' | 'es2020.date' + | 'es2020.full' + | 'es2020.intl' + | 'es2020.number' | 'es2020.promise' | 'es2020.sharedmemory' | 'es2020.string' | 'es2020.symbol.wellknown' - | 'es2020.intl' - | 'es2020.number' + | 'es2020' + | 'es2021.full' + | 'es2021.intl' | 'es2021.promise' | 'es2021.string' | 'es2021.weakref' - | 'es2021.intl' + | 'es2021' | 'es2022.array' | 'es2022.error' + | 'es2022.full' | 'es2022.intl' | 'es2022.object' + | 'es2022.regexp' | 'es2022.sharedmemory' | 'es2022.string' - | 'es2022.regexp' + | 'es2022' | 'es2023.array' + | 'es2023.full' + | 'es2023' | 'esnext.array' - | 'esnext.symbol' | 'esnext.asynciterable' - | 'esnext.intl' | 'esnext.bigint' - | 'esnext.string' + | 'esnext.full' + | 'esnext.intl' | 'esnext.promise' + | 'esnext.string' + | 'esnext.symbol' | 'esnext.weakref' - | 'decorators' - | 'decorators.legacy' - | 'es2016.full' - | 'es2017.full' - | 'es2018.full' - | 'es2019.full' - | 'es2020.full' - | 'es2021.full' - | 'es2022.full' - | 'es2023.full' - | 'esnext.full' - | 'lib'; + | 'esnext' + | 'lib' + | 'scripthost' + | 'webworker.importscripts' + | 'webworker.iterable' + | 'webworker'; export { Lib }; diff --git a/packages/types/src/parser-options.ts b/packages/types/src/parser-options.ts index 815ad4409130..4e8bb90dfae1 100644 --- a/packages/types/src/parser-options.ts +++ b/packages/types/src/parser-options.ts @@ -2,7 +2,7 @@ import type { Program } from 'typescript'; import type { Lib } from './lib'; -type DebugLevel = boolean | ('typescript-eslint' | 'eslint' | 'typescript')[]; +type DebugLevel = ('eslint' | 'typescript-eslint' | 'typescript')[] | boolean; type CacheDurationSeconds = number | 'Infinity'; type EcmaVersion = @@ -25,7 +25,7 @@ type EcmaVersion = | 2021 | 2022; -type SourceType = 'script' | 'module'; +type SourceType = 'module' | 'script'; interface ParserOptions { ecmaFeatures?: { @@ -52,8 +52,8 @@ interface ParserOptions { filePath?: string; loc?: boolean; program?: Program | null; - project?: string | string[] | true | null; - projectFolderIgnoreList?: (string | RegExp)[]; + project?: string[] | string | true | null; + projectFolderIgnoreList?: (RegExp | string)[]; range?: boolean; sourceType?: SourceType; tokens?: boolean; diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 1db8c1c00e6f..b199381b890e 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -53,7 +53,7 @@ export interface ConverterOptions { * @returns converted error object */ export function convertError( - error: ts.DiagnosticWithLocation | SemanticOrSyntacticError, + error: SemanticOrSyntacticError | ts.DiagnosticWithLocation, ): TSError { return createError( ('message' in error && error.message) || (error.messageText as string), @@ -146,17 +146,17 @@ export class Converter { | TSESTree.NamedExportDeclarations, >( node: - | ts.FunctionDeclaration - | ts.VariableStatement | ts.ClassDeclaration | ts.ClassExpression - | ts.TypeAliasDeclaration + | ts.EnumDeclaration + | ts.FunctionDeclaration | ts.ImportEqualsDeclaration | ts.InterfaceDeclaration - | ts.EnumDeclaration - | ts.ModuleDeclaration, + | ts.ModuleDeclaration + | ts.TypeAliasDeclaration + | ts.VariableStatement, result: T, - ): TSESTree.ExportDefaultDeclaration | TSESTree.ExportNamedDeclaration | T { + ): T | TSESTree.ExportDefaultDeclaration | TSESTree.ExportNamedDeclaration { const modifiers = getModifiers(node); if (modifiers?.[0].kind === SyntaxKind.ExportKeyword) { /** @@ -309,10 +309,10 @@ export class Converter { private convertBodyExpressions( nodes: ts.NodeArray, parent: - | ts.SourceFile | ts.Block + | ts.ClassStaticBlockDeclaration | ts.ModuleBlock - | ts.ClassStaticBlockDeclaration, + | ts.SourceFile, ): TSESTree.Statement[] { let allowDirectives = canContainDirective(parent); @@ -409,11 +409,11 @@ export class Converter { private convertChainExpression( node: TSESTree.ChainElement, tsNode: - | ts.PropertyAccessExpression - | ts.ElementAccessExpression | ts.CallExpression - | ts.NonNullExpression, - ): TSESTree.ChainExpression | TSESTree.ChainElement { + | ts.ElementAccessExpression + | ts.NonNullExpression + | ts.PropertyAccessExpression, + ): TSESTree.ChainElement | TSESTree.ChainExpression { const { child, isOptional } = ((): { child: TSESTree.Node; isOptional: boolean; @@ -628,8 +628,8 @@ export class Converter { private convertMethodSignature( node: - | ts.MethodSignature | ts.GetAccessorDeclaration + | ts.MethodSignature | ts.SetAccessorDeclaration, ): TSESTree.TSMethodSignature { return this.createNode(node, { @@ -637,7 +637,7 @@ export class Converter { accessibility: getTSNodeAccessibility(node), computed: isComputedProperty(node.name), key: this.convertChild(node.name), - kind: ((): 'get' | 'set' | 'method' => { + kind: ((): 'get' | 'method' | 'set' => { switch (node.kind) { case SyntaxKind.GetAccessor: return 'get'; @@ -917,7 +917,7 @@ export class Converter { const isDeclare = hasModifier(SyntaxKind.DeclareKeyword, node); const result = this.createNode< - TSESTree.TSDeclareFunction | TSESTree.FunctionDeclaration + TSESTree.FunctionDeclaration | TSESTree.TSDeclareFunction >(node, { type: isDeclare || !node.body @@ -1172,10 +1172,10 @@ export class Converter { const key = this.convertChild(node.name); return this.createNode< + | TSESTree.AccessorProperty + | TSESTree.PropertyDefinition | TSESTree.TSAbstractAccessorProperty | TSESTree.TSAbstractPropertyDefinition - | TSESTree.PropertyDefinition - | TSESTree.AccessorProperty >(node, { type, key, @@ -1213,7 +1213,7 @@ export class Converter { // otherwise, it is a non-type accessor - intentional fallthrough case SyntaxKind.MethodDeclaration: { const method = this.createNode< - TSESTree.TSEmptyBodyFunctionExpression | TSESTree.FunctionExpression + TSESTree.FunctionExpression | TSESTree.TSEmptyBodyFunctionExpression >(node, { type: !node.body ? AST_NODE_TYPES.TSEmptyBodyFunctionExpression @@ -1239,9 +1239,9 @@ export class Converter { } let result: + | TSESTree.MethodDefinition | TSESTree.Property - | TSESTree.TSAbstractMethodDefinition - | TSESTree.MethodDefinition; + | TSESTree.TSAbstractMethodDefinition; if (parent.kind === SyntaxKind.ObjectLiteralExpression) { method.params = node.parameters.map(el => this.convertChild(el)); @@ -1275,7 +1275,7 @@ export class Converter { : AST_NODE_TYPES.MethodDefinition; result = this.createNode< - TSESTree.TSAbstractMethodDefinition | TSESTree.MethodDefinition + TSESTree.MethodDefinition | TSESTree.TSAbstractMethodDefinition >(node, { type: methodDefinitionType, accessibility: getTSNodeAccessibility(node), @@ -1314,7 +1314,7 @@ export class Converter { node.getFirstToken()!; const constructor = this.createNode< - TSESTree.TSEmptyBodyFunctionExpression | TSESTree.FunctionExpression + TSESTree.FunctionExpression | TSESTree.TSEmptyBodyFunctionExpression >(node, { type: !node.body ? AST_NODE_TYPES.TSEmptyBodyFunctionExpression @@ -1351,7 +1351,7 @@ export class Converter { const isStatic = hasModifier(SyntaxKind.StaticKeyword, node); return this.createNode< - TSESTree.TSAbstractMethodDefinition | TSESTree.MethodDefinition + TSESTree.MethodDefinition | TSESTree.TSAbstractMethodDefinition >(node, { type: hasModifier(SyntaxKind.AbstractKeyword, node) ? AST_NODE_TYPES.TSAbstractMethodDefinition @@ -1440,7 +1440,7 @@ export class Converter { return arrayItem; } } else { - let result: TSESTree.RestElement | TSESTree.Property; + let result: TSESTree.Property | TSESTree.RestElement; if (node.dotDotDotToken) { result = this.createNode(node, { type: AST_NODE_TYPES.RestElement, @@ -1610,8 +1610,8 @@ export class Converter { } case SyntaxKind.Parameter: { - let parameter: TSESTree.RestElement | TSESTree.BindingName; - let result: TSESTree.RestElement | TSESTree.AssignmentPattern; + let parameter: TSESTree.BindingName | TSESTree.RestElement; + let result: TSESTree.AssignmentPattern | TSESTree.RestElement; if (node.dotDotDotToken) { parameter = result = this.createNode(node, { @@ -2018,8 +2018,8 @@ export class Converter { } return this.createNode< | TSESTree.AssignmentExpression - | TSESTree.LogicalExpression | TSESTree.BinaryExpression + | TSESTree.LogicalExpression >(node, { type, operator: getTextForTokenKind(node.operatorToken.kind), @@ -2642,9 +2642,9 @@ export class Converter { : AST_NODE_TYPES.TSFunctionType; return this.createNode< - | TSESTree.TSFunctionType | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration + | TSESTree.TSFunctionType >(node, { type, params: this.convertParameters(node.parameters), @@ -2667,9 +2667,9 @@ export class Converter { : AST_NODE_TYPES.TSInstantiationExpression; return this.createNode< - | TSESTree.TSInterfaceHeritage | TSESTree.TSClassImplements | TSESTree.TSInstantiationExpression + | TSESTree.TSInterfaceHeritage >( node, this.#withDeprecatedAliasGetter( @@ -3347,7 +3347,7 @@ export class Converter { #withDeprecatedAliasGetter< Properties extends { type: string }, AliasKey extends string, - ValueKey extends keyof Properties & string, + ValueKey extends string & keyof Properties, >( node: Properties, aliasKey: AliasKey, diff --git a/packages/typescript-estree/src/create-program/getWatchProgramsForProjects.ts b/packages/typescript-estree/src/create-program/getWatchProgramsForProjects.ts index d56313e489de..01ab04c3ae56 100644 --- a/packages/typescript-estree/src/create-program/getWatchProgramsForProjects.ts +++ b/packages/typescript-estree/src/create-program/getWatchProgramsForProjects.ts @@ -91,7 +91,7 @@ function saveWatchCallback( * Holds information about the file currently being linted */ const currentLintOperationState: { - code: string | ts.SourceFile; + code: ts.SourceFile | string; filePath: CanonicalPath; } = { code: '', diff --git a/packages/typescript-estree/src/create-program/shared.ts b/packages/typescript-estree/src/create-program/shared.ts index 7fa97afa8492..b0e39d19e7e6 100644 --- a/packages/typescript-estree/src/create-program/shared.ts +++ b/packages/typescript-estree/src/create-program/shared.ts @@ -12,7 +12,7 @@ interface ASTAndDefiniteProgram { ast: ts.SourceFile; program: ts.Program; } -type ASTAndProgram = ASTAndNoProgram | ASTAndDefiniteProgram; +type ASTAndProgram = ASTAndDefiniteProgram | ASTAndNoProgram; /** * Compiler options required to avoid critical functionality issues diff --git a/packages/typescript-estree/src/getModifiers.ts b/packages/typescript-estree/src/getModifiers.ts index 00f1011aa4b5..0ccb3026a901 100644 --- a/packages/typescript-estree/src/getModifiers.ts +++ b/packages/typescript-estree/src/getModifiers.ts @@ -7,7 +7,7 @@ const isAtLeast48 = typescriptVersionIsAtLeast['4.8']; export function getModifiers( node: ts.Node | null | undefined, includeIllegalModifiers = false, -): undefined | ts.Modifier[] { +): ts.Modifier[] | undefined { if (node == null) { return undefined; } @@ -34,7 +34,7 @@ export function getModifiers( export function getDecorators( node: ts.Node | null | undefined, includeIllegalDecorators = false, -): undefined | ts.Decorator[] { +): ts.Decorator[] | undefined { if (node == null) { return undefined; } diff --git a/packages/typescript-estree/src/node-utils.ts b/packages/typescript-estree/src/node-utils.ts index da802c8d5cc0..74e53c5df21e 100644 --- a/packages/typescript-estree/src/node-utils.ts +++ b/packages/typescript-estree/src/node-utils.ts @@ -144,8 +144,8 @@ export function getBinaryExpressionType( operator: ts.Token, ): | AST_NODE_TYPES.AssignmentExpression - | AST_NODE_TYPES.LogicalExpression - | AST_NODE_TYPES.BinaryExpression { + | AST_NODE_TYPES.BinaryExpression + | AST_NODE_TYPES.LogicalExpression { if (isAssignmentOperator(operator)) { return AST_NODE_TYPES.AssignmentExpression; } else if (isLogicalOperator(operator)) { @@ -193,10 +193,10 @@ export function getLocFor( */ export function canContainDirective( node: - | ts.SourceFile | ts.Block + | ts.ClassStaticBlockDeclaration | ts.ModuleBlock - | ts.ClassStaticBlockDeclaration, + | ts.SourceFile, ): boolean { if (node.kind === ts.SyntaxKind.Block) { switch (node.parent.kind) { @@ -257,7 +257,7 @@ export function isJSXToken(node: ts.Node): boolean { */ export function getDeclarationKind( node: ts.VariableDeclarationList, -): 'let' | 'const' | 'var' { +): 'const' | 'let' | 'var' { if (node.flags & ts.NodeFlags.Let) { return 'let'; } @@ -274,7 +274,7 @@ export function getDeclarationKind( */ export function getTSNodeAccessibility( node: ts.Node, -): 'public' | 'protected' | 'private' | undefined { +): 'private' | 'protected' | 'public' | undefined { const modifiers = getModifiers(node); if (modifiers == null) { return undefined; @@ -414,10 +414,10 @@ export function isChainExpression( */ export function isChildUnwrappableOptionalChain( node: - | ts.PropertyAccessExpression - | ts.ElementAccessExpression | ts.CallExpression - | ts.NonNullExpression, + | ts.ElementAccessExpression + | ts.NonNullExpression + | ts.PropertyAccessExpression, child: TSESTree.Node, ): boolean { return ( @@ -434,7 +434,7 @@ export function isChildUnwrappableOptionalChain( */ export function getTokenType( token: ts.Identifier | ts.Token, -): Exclude { +): Exclude { let keywordKind: ts.SyntaxKind | undefined; if (isAtLeast50 && token.kind === SyntaxKind.Identifier) { keywordKind = ts.identifierToKeywordKind(token as ts.Identifier); diff --git a/packages/typescript-estree/src/parseSettings/createParseSettings.ts b/packages/typescript-estree/src/parseSettings/createParseSettings.ts index 28943a02c06e..dbf36c2df90f 100644 --- a/packages/typescript-estree/src/parseSettings/createParseSettings.ts +++ b/packages/typescript-estree/src/parseSettings/createParseSettings.ts @@ -21,7 +21,7 @@ const log = debug( let TSCONFIG_MATCH_CACHE: ExpiringCache | null; export function createParseSettings( - code: string | ts.SourceFile, + code: ts.SourceFile | string, options: Partial = {}, ): MutableParseSettings { const codeFullText = enforceCodeString(code); diff --git a/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts b/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts index 3e6f7a8ac4e4..64af27985f0e 100644 --- a/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts +++ b/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts @@ -20,7 +20,7 @@ export function getProjectConfigFiles( ParseSettings, 'filePath' | 'tsconfigMatchCache' | 'tsconfigRootDir' >, - project: string | string[] | true | undefined | null, + project: string[] | string | true | null | undefined, ): string[] | null { if (project !== true) { if (project == null) { diff --git a/packages/typescript-estree/src/parseSettings/index.ts b/packages/typescript-estree/src/parseSettings/index.ts index 9fc8986ad484..3cf3e2a6f692 100644 --- a/packages/typescript-estree/src/parseSettings/index.ts +++ b/packages/typescript-estree/src/parseSettings/index.ts @@ -4,7 +4,7 @@ import type { CanonicalPath } from '../create-program/shared'; import type { TSESTree } from '../ts-estree'; import type { CacheLike } from './ExpiringCache'; -type DebugModule = 'typescript-eslint' | 'eslint' | 'typescript'; +type DebugModule = 'eslint' | 'typescript-eslint' | 'typescript'; /** * Internal settings used by the parser to run on a file. @@ -18,7 +18,7 @@ export interface MutableParseSettings { /** * Code of the file being parsed, or raw source file containing it. */ - code: string | ts.SourceFile; + code: ts.SourceFile | string; /** * Full text of the file being parsed. @@ -101,7 +101,7 @@ export interface MutableParseSettings { /** * One or more instances of TypeScript Program objects to be used for type information. */ - programs: null | Iterable; + programs: Iterable | null; /** * Normalized paths to provided project paths. @@ -126,7 +126,7 @@ export interface MutableParseSettings { /** * If the `tokens` parse option is enabled, retrieved tokens. */ - tokens: null | TSESTree.Token[]; + tokens: TSESTree.Token[] | null; /** * Caches searches for TSConfigs from project directories. diff --git a/packages/typescript-estree/src/parser-options.ts b/packages/typescript-estree/src/parser-options.ts index da00e007d619..b867f32e63b7 100644 --- a/packages/typescript-estree/src/parser-options.ts +++ b/packages/typescript-estree/src/parser-options.ts @@ -68,7 +68,7 @@ interface ParseOptions { * When value is `false`, no logging will occur. * When value is not provided, `console.log()` will be used. */ - loggerFn?: ((message: string) => void) | false; + loggerFn?: false | ((message: string) => void); /** * Controls whether the `range` property is included on AST nodes. @@ -135,7 +135,7 @@ interface ParseAndGenerateServicesOptions extends ParseOptions { * or `true` to find the nearest tsconfig.json to the file. * If this is provided, type information will be returned. */ - project?: string | string[] | true | null; + project?: string[] | string | true | null; /** * If you provide a glob (or globs) to the project option, you can use this option to ignore certain folders from @@ -226,5 +226,5 @@ export interface ParserServicesWithoutTypeInformation program: null; } export type ParserServices = - | ParserServicesWithTypeInformation - | ParserServicesWithoutTypeInformation; + | ParserServicesWithoutTypeInformation + | ParserServicesWithTypeInformation; diff --git a/packages/typescript-estree/src/parser.ts b/packages/typescript-estree/src/parser.ts index f5b869c0efc1..c74935498c14 100644 --- a/packages/typescript-estree/src/parser.ts +++ b/packages/typescript-estree/src/parser.ts @@ -82,8 +82,8 @@ function getProgramAndAST( interface EmptyObject {} type AST = TSESTree.Program & - (T['tokens'] extends true ? { tokens: TSESTree.Token[] } : EmptyObject) & - (T['comment'] extends true ? { comments: TSESTree.Comment[] } : EmptyObject); + (T['comment'] extends true ? { comments: TSESTree.Comment[] } : EmptyObject) & + (T['tokens'] extends true ? { tokens: TSESTree.Token[] } : EmptyObject); interface ParseAndGenerateServicesResult { ast: AST; @@ -103,7 +103,7 @@ function parse( } function parseWithNodeMapsInternal( - code: string | ts.SourceFile, + code: ts.SourceFile | string, options: T | undefined, shouldPreserveNodeMaps: boolean, ): ParseWithNodeMapsResult { @@ -149,7 +149,7 @@ function clearParseAndGenerateServicesCalls(): void { } function parseAndGenerateServices( - code: string | ts.SourceFile, + code: ts.SourceFile | string, options: T, ): ParseAndGenerateServicesResult { /** diff --git a/packages/typescript-estree/src/semantic-or-syntactic-errors.ts b/packages/typescript-estree/src/semantic-or-syntactic-errors.ts index d5d5ce42ad97..0839409582c3 100644 --- a/packages/typescript-estree/src/semantic-or-syntactic-errors.ts +++ b/packages/typescript-estree/src/semantic-or-syntactic-errors.ts @@ -58,8 +58,8 @@ export function getFirstSemanticOrSyntacticError( } function allowlistSupportedDiagnostics( - diagnostics: readonly (DiagnosticWithLocation | Diagnostic)[], -): readonly (DiagnosticWithLocation | Diagnostic)[] { + diagnostics: readonly (Diagnostic | DiagnosticWithLocation)[], +): readonly (Diagnostic | DiagnosticWithLocation)[] { return diagnostics.filter(diagnostic => { switch (diagnostic.code) { case 1013: // "A rest parameter or binding pattern may not have a trailing comma." diff --git a/packages/typescript-estree/src/source-files.ts b/packages/typescript-estree/src/source-files.ts index 18cd45670907..8c4ae0fc87e1 100644 --- a/packages/typescript-estree/src/source-files.ts +++ b/packages/typescript-estree/src/source-files.ts @@ -12,6 +12,6 @@ export function isSourceFile(code: unknown): code is ts.SourceFile { ); } -export function getCodeText(code: string | ts.SourceFile): string { +export function getCodeText(code: ts.SourceFile | string): string { return isSourceFile(code) ? code.getFullText(code) : code; } diff --git a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts index c5c7eebef182..7fa66c609edd 100644 --- a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts +++ b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts @@ -7,15 +7,15 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.AccessorProperty]: ts.PropertyDeclaration; [AST_NODE_TYPES.ArrayExpression]: ts.ArrayLiteralExpression; [AST_NODE_TYPES.ArrayPattern]: - | ts.ArrayLiteralExpression - | ts.ArrayBindingPattern; + | ts.ArrayBindingPattern + | ts.ArrayLiteralExpression; [AST_NODE_TYPES.ArrowFunctionExpression]: ts.ArrowFunction; [AST_NODE_TYPES.AssignmentExpression]: ts.BinaryExpression; [AST_NODE_TYPES.AssignmentPattern]: - | ts.ShorthandPropertyAssignment - | ts.BindingElement | ts.BinaryExpression - | ts.ParameterDeclaration; + | ts.BindingElement + | ts.ParameterDeclaration + | ts.ShorthandPropertyAssignment; [AST_NODE_TYPES.AwaitExpression]: ts.AwaitExpression; [AST_NODE_TYPES.BinaryExpression]: ts.BinaryExpression; [AST_NODE_TYPES.BlockStatement]: ts.Block; @@ -24,9 +24,9 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.CatchClause]: ts.CatchClause; [AST_NODE_TYPES.ChainExpression]: | ts.CallExpression - | ts.PropertyAccessExpression | ts.ElementAccessExpression - | ts.NonNullExpression; + | ts.NonNullExpression + | ts.PropertyAccessExpression; [AST_NODE_TYPES.ClassBody]: ts.ClassDeclaration | ts.ClassExpression; [AST_NODE_TYPES.ClassDeclaration]: ts.ClassDeclaration; [AST_NODE_TYPES.ClassExpression]: ts.ClassExpression; @@ -39,26 +39,26 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.EmptyStatement]: ts.EmptyStatement; [AST_NODE_TYPES.ExportAllDeclaration]: ts.ExportDeclaration; [AST_NODE_TYPES.ExportDefaultDeclaration]: + | ts.ClassDeclaration + | ts.ClassExpression + | ts.EnumDeclaration | ts.ExportAssignment | ts.FunctionDeclaration - | ts.VariableStatement + | ts.InterfaceDeclaration + | ts.ModuleDeclaration + | ts.TypeAliasDeclaration + | ts.VariableStatement; + [AST_NODE_TYPES.ExportNamedDeclaration]: | ts.ClassDeclaration | ts.ClassExpression - | ts.TypeAliasDeclaration - | ts.InterfaceDeclaration | ts.EnumDeclaration - | ts.ModuleDeclaration; - [AST_NODE_TYPES.ExportNamedDeclaration]: | ts.ExportDeclaration | ts.FunctionDeclaration - | ts.VariableStatement - | ts.ClassDeclaration - | ts.ClassExpression - | ts.TypeAliasDeclaration | ts.ImportEqualsDeclaration | ts.InterfaceDeclaration - | ts.EnumDeclaration - | ts.ModuleDeclaration; + | ts.ModuleDeclaration + | ts.TypeAliasDeclaration + | ts.VariableStatement; [AST_NODE_TYPES.ExportSpecifier]: ts.ExportSpecifier; [AST_NODE_TYPES.ExpressionStatement]: ts.ExpressionStatement; [AST_NODE_TYPES.ForInStatement]: ts.ForInStatement; @@ -66,15 +66,15 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.ForStatement]: ts.ForStatement; [AST_NODE_TYPES.FunctionDeclaration]: ts.FunctionDeclaration; [AST_NODE_TYPES.FunctionExpression]: - | ts.FunctionExpression | ts.ConstructorDeclaration + | ts.FunctionExpression | ts.GetAccessorDeclaration - | ts.SetAccessorDeclaration - | ts.MethodDeclaration; + | ts.MethodDeclaration + | ts.SetAccessorDeclaration; [AST_NODE_TYPES.Identifier]: - | ts.Identifier | ts.ConstructorDeclaration - | ts.Token; + | ts.Identifier + | ts.Token; [AST_NODE_TYPES.PrivateIdentifier]: ts.PrivateIdentifier; [AST_NODE_TYPES.IfStatement]: ts.IfStatement; [AST_NODE_TYPES.ImportAttribute]: ts.AssertEntry; @@ -102,43 +102,43 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.JSXText]: ts.JsxText; [AST_NODE_TYPES.LabeledStatement]: ts.LabeledStatement; [AST_NODE_TYPES.Literal]: - | ts.StringLiteral + | ts.BigIntLiteral + | ts.BooleanLiteral + | ts.NullLiteral | ts.NumericLiteral | ts.RegularExpressionLiteral - | ts.NullLiteral - | ts.BooleanLiteral - | ts.BigIntLiteral; + | ts.StringLiteral; [AST_NODE_TYPES.LogicalExpression]: ts.BinaryExpression; [AST_NODE_TYPES.MemberExpression]: - | ts.PropertyAccessExpression - | ts.ElementAccessExpression; + | ts.ElementAccessExpression + | ts.PropertyAccessExpression; [AST_NODE_TYPES.MetaProperty]: ts.MetaProperty; [AST_NODE_TYPES.MethodDefinition]: + | ts.ConstructorDeclaration | ts.GetAccessorDeclaration - | ts.SetAccessorDeclaration | ts.MethodDeclaration - | ts.ConstructorDeclaration; + | ts.SetAccessorDeclaration; [AST_NODE_TYPES.NewExpression]: ts.NewExpression; [AST_NODE_TYPES.ObjectExpression]: ts.ObjectLiteralExpression; [AST_NODE_TYPES.ObjectPattern]: - | ts.ObjectLiteralExpression - | ts.ObjectBindingPattern; + | ts.ObjectBindingPattern + | ts.ObjectLiteralExpression; [AST_NODE_TYPES.Program]: ts.SourceFile; [AST_NODE_TYPES.Property]: - | ts.PropertyAssignment - | ts.ShorthandPropertyAssignment + | ts.BindingElement | ts.GetAccessorDeclaration - | ts.SetAccessorDeclaration | ts.MethodDeclaration - | ts.BindingElement; + | ts.PropertyAssignment + | ts.SetAccessorDeclaration + | ts.ShorthandPropertyAssignment; [AST_NODE_TYPES.RestElement]: | ts.BindingElement + | ts.ParameterDeclaration | ts.SpreadAssignment - | ts.SpreadElement - | ts.ParameterDeclaration; + | ts.SpreadElement; [AST_NODE_TYPES.ReturnStatement]: ts.ReturnStatement; [AST_NODE_TYPES.SequenceExpression]: ts.BinaryExpression; - [AST_NODE_TYPES.SpreadElement]: ts.SpreadElement | ts.SpreadAssignment; + [AST_NODE_TYPES.SpreadElement]: ts.SpreadAssignment | ts.SpreadElement; [AST_NODE_TYPES.StaticBlock]: ts.ClassStaticBlockDeclaration; [AST_NODE_TYPES.Super]: ts.SuperExpression; [AST_NODE_TYPES.SwitchCase]: ts.CaseClause | ts.DefaultClause; @@ -153,18 +153,18 @@ export interface EstreeToTsNodeTypes { | ts.NoSubstitutionTemplateLiteral | ts.TemplateExpression; [AST_NODE_TYPES.ThisExpression]: - | ts.ThisExpression + | ts.Identifier | ts.KeywordTypeNode - | ts.Identifier; + | ts.ThisExpression; [AST_NODE_TYPES.ThrowStatement]: ts.ThrowStatement; [AST_NODE_TYPES.TryStatement]: ts.TryStatement; [AST_NODE_TYPES.TSAbstractAccessorProperty]: ts.PropertyDeclaration; [AST_NODE_TYPES.TSAbstractPropertyDefinition]: ts.PropertyDeclaration; [AST_NODE_TYPES.TSAbstractMethodDefinition]: + | ts.ConstructorDeclaration | ts.GetAccessorDeclaration - | ts.SetAccessorDeclaration | ts.MethodDeclaration - | ts.ConstructorDeclaration; + | ts.SetAccessorDeclaration; [AST_NODE_TYPES.TSArrayType]: ts.ArrayTypeNode; [AST_NODE_TYPES.TSAsExpression]: ts.AsExpression; [AST_NODE_TYPES.TSCallSignatureDeclaration]: ts.CallSignatureDeclaration; @@ -192,8 +192,8 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.TSLiteralType]: ts.LiteralTypeNode; [AST_NODE_TYPES.TSMappedType]: ts.MappedTypeNode; [AST_NODE_TYPES.TSMethodSignature]: - | ts.MethodSignature | ts.GetAccessorDeclaration + | ts.MethodSignature | ts.SetAccessorDeclaration; [AST_NODE_TYPES.TSModuleBlock]: ts.ModuleBlock; [AST_NODE_TYPES.TSModuleDeclaration]: ts.ModuleDeclaration; @@ -205,9 +205,8 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.TSPropertySignature]: ts.PropertySignature; [AST_NODE_TYPES.TSQualifiedName]: ts.Identifier | ts.QualifiedName; [AST_NODE_TYPES.TSRestType]: - | ts.RestTypeNode - // for consistency and following babel's choices, a named tuple member with a rest gets converted to a TSRestType - | ts.NamedTupleMember; + | ts.NamedTupleMember // for consistency and following babel's choices, a named tuple member with a rest gets converted to a TSRestType + | ts.RestTypeNode; [AST_NODE_TYPES.TSThisType]: ts.ThisTypeNode; [AST_NODE_TYPES.TSTupleType]: ts.TupleTypeNode; [AST_NODE_TYPES.TSTemplateLiteralType]: ts.TemplateLiteralTypeNode; @@ -219,28 +218,28 @@ export interface EstreeToTsNodeTypes { [AST_NODE_TYPES.TSTypeParameter]: ts.TypeParameterDeclaration; [AST_NODE_TYPES.TSTypeParameterDeclaration]: undefined; [AST_NODE_TYPES.TSTypeParameterInstantiation]: - | ts.TaggedTemplateExpression - | ts.ImportTypeNode + | ts.CallExpression | ts.ExpressionWithTypeArguments - | ts.TypeReferenceNode + | ts.ImportTypeNode | ts.JsxOpeningElement | ts.JsxSelfClosingElement | ts.NewExpression - | ts.CallExpression - | ts.TypeQueryNode; + | ts.TaggedTemplateExpression + | ts.TypeQueryNode + | ts.TypeReferenceNode; [AST_NODE_TYPES.TSTypePredicate]: ts.TypePredicateNode; - [AST_NODE_TYPES.TSTypeQuery]: ts.TypeQueryNode | ts.ImportTypeNode; + [AST_NODE_TYPES.TSTypeQuery]: ts.ImportTypeNode | ts.TypeQueryNode; [AST_NODE_TYPES.TSTypeReference]: ts.TypeReferenceNode; [AST_NODE_TYPES.TSUnionType]: ts.UnionTypeNode; [AST_NODE_TYPES.UpdateExpression]: - | ts.PrefixUnaryExpression - | ts.PostfixUnaryExpression; - [AST_NODE_TYPES.UnaryExpression]: - | ts.PrefixUnaryExpression | ts.PostfixUnaryExpression + | ts.PrefixUnaryExpression; + [AST_NODE_TYPES.UnaryExpression]: | ts.DeleteExpression - | ts.VoidExpression - | ts.TypeOfExpression; + | ts.PostfixUnaryExpression + | ts.PrefixUnaryExpression + | ts.TypeOfExpression + | ts.VoidExpression; [AST_NODE_TYPES.VariableDeclaration]: | ts.VariableDeclarationList | ts.VariableStatement; @@ -252,15 +251,15 @@ export interface EstreeToTsNodeTypes { // Added by parser // Should be same as AST_NODE_TYPES.FunctionExpression [AST_NODE_TYPES.TSEmptyBodyFunctionExpression]: - | ts.FunctionExpression | ts.ConstructorDeclaration + | ts.FunctionExpression | ts.GetAccessorDeclaration - | ts.SetAccessorDeclaration - | ts.MethodDeclaration; + | ts.MethodDeclaration + | ts.SetAccessorDeclaration; // Keywords [AST_NODE_TYPES.TSAbstractKeyword]: ts.Token; - [AST_NODE_TYPES.TSNullKeyword]: ts.NullLiteral | ts.KeywordTypeNode; + [AST_NODE_TYPES.TSNullKeyword]: ts.KeywordTypeNode | ts.NullLiteral; [AST_NODE_TYPES.TSAnyKeyword]: ts.KeywordTypeNode; [AST_NODE_TYPES.TSBigIntKeyword]: ts.KeywordTypeNode; @@ -291,7 +290,7 @@ export interface EstreeToTsNodeTypes { * This mapping is based on the internal logic of the parser. */ export type TSESTreeToTSNode = Extract< - TSNode | ts.Token, + ts.Token | TSNode, // if this errors, it means that one of the AST_NODE_TYPES is not defined in the above interface EstreeToTsNodeTypes[T['type']] >; diff --git a/packages/typescript-estree/src/ts-estree/ts-nodes.ts b/packages/typescript-estree/src/ts-estree/ts-nodes.ts index ad668baf6f6a..570ae9e80a7a 100644 --- a/packages/typescript-estree/src/ts-estree/ts-nodes.ts +++ b/packages/typescript-estree/src/ts-estree/ts-nodes.ts @@ -19,6 +19,7 @@ declare module 'typescript' { export type TSToken = ts.Token; +/* eslint-disable @typescript-eslint/sort-type-constituents */ export type TSNode = | ts.AssertClause | ts.AssertEntry @@ -213,3 +214,4 @@ export type TSNode = | ts.JSDocOptionalType | ts.JSDocVariadicType | ts.JSDocAuthorTag; +/* eslint-enable @typescript-eslint/sort-type-constituents */ diff --git a/packages/typescript-estree/tests/lib/convert.test.ts b/packages/typescript-estree/tests/lib/convert.test.ts index 3e7991683e85..b9ec249d67bf 100644 --- a/packages/typescript-estree/tests/lib/convert.test.ts +++ b/packages/typescript-estree/tests/lib/convert.test.ts @@ -103,7 +103,7 @@ describe('convert', () => { instance.convertProgram(); const maps = instance.getASTMaps(); - function checkMaps(child: ts.SourceFile | ts.Node): void { + function checkMaps(child: ts.Node | ts.SourceFile): void { child.forEachChild(node => { if ( node.kind !== ts.SyntaxKind.EndOfFileToken && @@ -135,7 +135,7 @@ describe('convert', () => { instance.convertProgram(); const maps = instance.getASTMaps(); - function checkMaps(child: ts.SourceFile | ts.Node): void { + function checkMaps(child: ts.Node | ts.SourceFile): void { child.forEachChild(node => { if ( node.kind !== ts.SyntaxKind.EndOfFileToken && @@ -166,7 +166,7 @@ describe('convert', () => { const program = instance.convertProgram(); const maps = instance.getASTMaps(); - function checkMaps(child: ts.SourceFile | ts.Node): void { + function checkMaps(child: ts.Node | ts.SourceFile): void { child.forEachChild(node => { if (node.kind !== ts.SyntaxKind.EndOfFileToken) { expect(ast).toBe( diff --git a/packages/typescript-estree/tests/lib/parse.test.ts b/packages/typescript-estree/tests/lib/parse.test.ts index 7b4503513345..02bacdfadf3a 100644 --- a/packages/typescript-estree/tests/lib/parse.test.ts +++ b/packages/typescript-estree/tests/lib/parse.test.ts @@ -177,7 +177,7 @@ describe('parseAndGenerateServices', () => { jsxSetting, shouldThrow = false, }: { - ext: '.js' | '.jsx' | '.ts' | '.tsx' | '.vue' | '.json'; + ext: '.js' | '.json' | '.jsx' | '.ts' | '.tsx' | '.vue'; jsxContent: boolean; jsxSetting: boolean; shouldThrow?: boolean; diff --git a/packages/utils/src/ast-utils/eslint-utils/ReferenceTracker.ts b/packages/utils/src/ast-utils/eslint-utils/ReferenceTracker.ts index 9e0841fb4de4..e71c75d6d51a 100644 --- a/packages/utils/src/ast-utils/eslint-utils/ReferenceTracker.ts +++ b/packages/utils/src/ast-utils/eslint-utils/ReferenceTracker.ts @@ -50,7 +50,7 @@ interface ReferenceTrackerStatic { * If this is `"strict"`, the method binds CommonJS modules to the default export. Otherwise, the method binds * CommonJS modules to both the default export and named exports. Optional. Default is `"strict"`. */ - mode?: 'strict' | 'legacy'; + mode?: 'legacy' | 'strict'; /** * The name list of Global Object. Optional. Default is `["global", "globalThis", "self", "window"]`. */ @@ -69,7 +69,7 @@ namespace ReferenceTracker { export type CALL = ReferenceTrackerStatic['CALL']; export type CONSTRUCT = ReferenceTrackerStatic['CONSTRUCT']; export type ESM = ReferenceTrackerStatic['ESM']; - export type ReferenceType = READ | CALL | CONSTRUCT; + export type ReferenceType = CALL | CONSTRUCT | READ; // eslint-disable-next-line @typescript-eslint/no-explicit-any export type TraceMap = Record>; export interface TraceMapElement { diff --git a/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts b/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts index e57046ca12d1..797585f34a5d 100644 --- a/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts +++ b/packages/utils/src/ast-utils/eslint-utils/astUtilities.ts @@ -10,9 +10,9 @@ import type { TSESTree } from '../../ts-estree'; */ const getFunctionHeadLocation = eslintUtils.getFunctionHeadLocation as ( node: + | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression - | TSESTree.ArrowFunctionExpression, + | TSESTree.FunctionExpression, sourceCode: TSESLint.SourceCode, ) => TSESTree.SourceLocation; @@ -23,9 +23,9 @@ const getFunctionHeadLocation = eslintUtils.getFunctionHeadLocation as ( */ const getFunctionNameWithKind = eslintUtils.getFunctionNameWithKind as ( node: + | TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclaration - | TSESTree.FunctionExpression - | TSESTree.ArrowFunctionExpression, + | TSESTree.FunctionExpression, sourceCode?: TSESLint.SourceCode, ) => string; @@ -39,8 +39,8 @@ const getFunctionNameWithKind = eslintUtils.getFunctionNameWithKind as ( const getPropertyName = eslintUtils.getPropertyName as ( node: | TSESTree.MemberExpression - | TSESTree.Property | TSESTree.MethodDefinition + | TSESTree.Property | TSESTree.PropertyDefinition, initialScope?: TSESLint.Scope.Scope, ) => string | null; diff --git a/packages/utils/src/ast-utils/eslint-utils/scopeAnalysis.ts b/packages/utils/src/ast-utils/eslint-utils/scopeAnalysis.ts index 563c51c7782b..43199ce05533 100644 --- a/packages/utils/src/ast-utils/eslint-utils/scopeAnalysis.ts +++ b/packages/utils/src/ast-utils/eslint-utils/scopeAnalysis.ts @@ -10,7 +10,7 @@ import type { TSESTree } from '../../ts-estree'; */ const findVariable = eslintUtils.findVariable as ( initialScope: TSESLint.Scope.Scope, - nameOrNode: string | TSESTree.Identifier, + nameOrNode: TSESTree.Identifier | string, ) => TSESLint.Scope.Variable | null; /** diff --git a/packages/utils/src/ast-utils/helpers.ts b/packages/utils/src/ast-utils/helpers.ts index 8184e1475506..afe8a6fede89 100644 --- a/packages/utils/src/ast-utils/helpers.ts +++ b/packages/utils/src/ast-utils/helpers.ts @@ -28,12 +28,12 @@ export const isNodeOfTypeWithConditions = < conditions: Conditions, ): (( node: TSESTree.Node | null | undefined, -) => node is ExtractedNode & Conditions) => { +) => node is Conditions & ExtractedNode) => { const entries = Object.entries(conditions) as ObjectEntries; return ( node: TSESTree.Node | null | undefined, - ): node is ExtractedNode & Conditions => + ): node is Conditions & ExtractedNode => node?.type === nodeType && entries.every(([key, value]) => node[key as keyof TSESTree.Node] === value); }; @@ -47,12 +47,12 @@ export const isTokenOfTypeWithConditions = < conditions: Conditions, ): (( token: TSESTree.Token | null | undefined, -) => token is ExtractedToken & Conditions) => { +) => token is Conditions & ExtractedToken) => { const entries = Object.entries(conditions) as ObjectEntries; return ( token: TSESTree.Token | null | undefined, - ): token is ExtractedToken & Conditions => + ): token is Conditions & ExtractedToken => token?.type === tokenType && entries.every( ([key, value]) => token[key as keyof TSESTree.Token] === value, @@ -69,6 +69,6 @@ export const isNotTokenOfTypeWithConditions = conditions: Conditions, ): (( token: TSESTree.Token | null | undefined, - ) => token is Exclude) => - (token): token is Exclude => + ) => token is Exclude) => + (token): token is Exclude => !isTokenOfTypeWithConditions(tokenType, conditions)(token); diff --git a/packages/utils/src/ast-utils/predicates.ts b/packages/utils/src/ast-utils/predicates.ts index 36e08ee5c42f..2d0c3831a877 100644 --- a/packages/utils/src/ast-utils/predicates.ts +++ b/packages/utils/src/ast-utils/predicates.ts @@ -116,7 +116,7 @@ const isConstructor = isNodeOfTypeWithConditions( */ function isSetter( node: TSESTree.Node | undefined, -): node is (TSESTree.MethodDefinition | TSESTree.Property) & { kind: 'set' } { +): node is { kind: 'set' } & (TSESTree.MethodDefinition | TSESTree.Property) { return ( !!node && (node.type === AST_NODE_TYPES.MethodDefinition || diff --git a/packages/utils/src/eslint-utils/RuleCreator.ts b/packages/utils/src/eslint-utils/RuleCreator.ts index 527ae36307b5..51784d7cf765 100644 --- a/packages/utils/src/eslint-utils/RuleCreator.ts +++ b/packages/utils/src/eslint-utils/RuleCreator.ts @@ -9,9 +9,12 @@ import { applyDefault } from './applyDefault'; // we automatically add the url export type NamedCreateRuleMetaDocs = Omit; -export type NamedCreateRuleMeta = { +export type NamedCreateRuleMeta = Omit< + RuleMetaData, + 'docs' +> & { docs: NamedCreateRuleMetaDocs; -} & Omit, 'docs'>; +}; export interface RuleCreateAndOptions< TOptions extends readonly unknown[], diff --git a/packages/utils/src/json-schema.ts b/packages/utils/src/json-schema.ts index f022791c2f81..b641637745ae 100644 --- a/packages/utils/src/json-schema.ts +++ b/packages/utils/src/json-schema.ts @@ -13,19 +13,19 @@ * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1 */ export type JSONSchema4TypeName = - | 'string' - | 'number' - | 'integer' - | 'boolean' - | 'object' + | 'any' | 'array' + | 'boolean' + | 'integer' | 'null' - | 'any'; + | 'number' + | 'object' + | 'string'; /** * @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-3.5 */ -export type JSONSchema4Type = string | number | boolean | null; +export type JSONSchema4Type = boolean | number | string | null; /** * Meta schema @@ -47,18 +47,18 @@ export type JSONSchema4Version = string; * @see https://tools.ietf.org/html/draft-zyp-json-schema-04 */ export type JSONSchema4 = - | JSONSchema4ObjectSchema + | JSONSchema4AllOfSchema + | JSONSchema4AnyOfSchema + | JSONSchema4AnySchema | JSONSchema4ArraySchema - | JSONSchema4StringSchema - | JSONSchema4NumberSchema | JSONSchema4BoleanSchema + | JSONSchema4MultiSchema | JSONSchema4NullSchema - | JSONSchema4AnySchema - | JSONSchema4RefSchema - | JSONSchema4AllOfSchema - | JSONSchema4AnyOfSchema + | JSONSchema4NumberSchema + | JSONSchema4ObjectSchema | JSONSchema4OneOfSchema - | JSONSchema4MultiSchema; + | JSONSchema4RefSchema + | JSONSchema4StringSchema; interface JSONSchema4Base { id?: string | undefined; @@ -136,7 +136,7 @@ interface JSONSchema4Base { * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.26 */ - extends?: string | string[] | undefined; + extends?: string[] | string | undefined; /** * The default value for the item if not present @@ -150,7 +150,7 @@ interface JSONSchema4Base { * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7 */ - required?: boolean | string[] | undefined; + required?: string[] | boolean | undefined; /** * (NOT) Must not be valid against the given schema @@ -191,13 +191,13 @@ export interface JSONSchema4OneOfSchema extends JSONSchema4Base { } export interface JSONSchema4MultiSchema - extends Omit, - Omit, - Omit, - Omit, - Omit, - Omit, - Omit { + extends Omit, + Omit, + Omit, + Omit, + Omit, + Omit, + Omit { type: JSONSchema4TypeName[]; /** * This provides an enumeration of all possible values that are valid @@ -227,7 +227,7 @@ export interface JSONSchema4ObjectSchema extends JSONSchema4Base { * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.4 */ - additionalProperties?: boolean | JSONSchema4 | undefined; + additionalProperties?: JSONSchema4 | boolean | undefined; /** * This attribute is an object with property definitions that define the @@ -302,7 +302,7 @@ export interface JSONSchema4ArraySchema extends JSONSchema4Base { * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.6 */ - additionalItems?: boolean | JSONSchema4 | undefined; + additionalItems?: JSONSchema4 | boolean | undefined; /** * This attribute defines the allowed items in an instance array, and @@ -384,22 +384,22 @@ export interface JSONSchema4StringSchema extends JSONSchema4Base { * to throw during schema compilation */ format?: - | 'date' - | 'time' | 'date-time' - | 'uri' - | 'uri-reference' - | 'uri-template' - | 'url' + | 'date' | 'email' | 'hostname' | 'ipv4' | 'ipv6' - | 'regex' - | 'uuid' - | 'json-pointer' | 'json-pointer-uri-fragment' + | 'json-pointer' + | 'regex' | 'relative-json-pointer' + | 'time' + | 'uri-reference' + | 'uri-template' + | 'uri' + | 'url' + | 'uuid' | undefined; enum?: string[] | undefined; @@ -409,7 +409,7 @@ export interface JSONSchema4StringSchema extends JSONSchema4Base { * @see https://json-schema.org/understanding-json-schema/reference/numeric.html */ export interface JSONSchema4NumberSchema extends JSONSchema4Base { - type: 'number' | 'integer'; + type: 'integer' | 'number'; /** * Numbers can be restricted to a multiple of a given number, using the diff --git a/packages/utils/src/ts-eslint/CLIEngine.ts b/packages/utils/src/ts-eslint/CLIEngine.ts index 65629fbbec7d..15a58754ec93 100644 --- a/packages/utils/src/ts-eslint/CLIEngine.ts +++ b/packages/utils/src/ts-eslint/CLIEngine.ts @@ -119,7 +119,7 @@ namespace CLIEngine { globals?: string[]; ignore?: boolean; ignorePath?: string; - ignorePattern?: string | string[]; + ignorePattern?: string[] | string; useEslintrc?: boolean; parser?: string; parserOptions?: Linter.ParserOptions; diff --git a/packages/utils/src/ts-eslint/ESLint.ts b/packages/utils/src/ts-eslint/ESLint.ts index d5e0420a56f3..a7aa2daec98d 100644 --- a/packages/utils/src/ts-eslint/ESLint.ts +++ b/packages/utils/src/ts-eslint/ESLint.ts @@ -36,7 +36,7 @@ declare class ESLintBase { * @param patterns The lint target files. This can contain any of file paths, directory paths, and glob patterns. * @returns The promise that will be fulfilled with an array of LintResult objects. */ - lintFiles(patterns: string | string[]): Promise; + lintFiles(patterns: string[] | string): Promise; /** * This method lints the given source code text and then returns the results. * @@ -145,7 +145,7 @@ namespace ESLint { /** * The types of the rules that the eslint.lintFiles() and eslint.lintText() methods use for autofix. */ - fixTypes?: ('directive' | 'problem' | 'suggestion' | 'layout')[] | null; + fixTypes?: ('directive' | 'layout' | 'problem' | 'suggestion')[] | null; /** * If false is present, the eslint.lintFiles() method doesn't interpret glob patterns. */ @@ -379,7 +379,7 @@ namespace ESLint { * The method to convert the LintResult objects to text. * Promise return supported since 8.4.0 */ - format(results: LintResult[]): string | Promise; + format(results: LintResult[]): Promise | string; } } diff --git a/packages/utils/src/ts-eslint/Linter.ts b/packages/utils/src/ts-eslint/Linter.ts index 171335c5dd8c..59274a7e6fc4 100644 --- a/packages/utils/src/ts-eslint/Linter.ts +++ b/packages/utils/src/ts-eslint/Linter.ts @@ -16,8 +16,8 @@ import type { SourceCode } from './SourceCode'; export type MinimalRuleModule< TMessageIds extends string = string, TOptions extends readonly unknown[] = [], -> = Pick, 'create'> & - Partial, 'create'>>; +> = Partial, 'create'>> & + Pick, 'create'>; declare class LinterBase { /** @@ -79,7 +79,7 @@ declare class LinterBase { verify( textOrSourceCode: SourceCode | string, config: Linter.Config, - filenameOrOptions?: string | Linter.VerifyOptions, + filenameOrOptions?: Linter.VerifyOptions | string, ): Linter.LintMessage[]; /** @@ -119,7 +119,7 @@ namespace Linter { } export type Severity = 0 | 1 | 2; - export type SeverityString = 'off' | 'warn' | 'error'; + export type SeverityString = 'error' | 'off' | 'warn'; export type RuleLevel = Severity | SeverityString; export type RuleLevelAndOptions = [RuleLevel, ...unknown[]]; @@ -127,7 +127,7 @@ namespace Linter { export type RuleEntry = RuleLevel | RuleLevelAndOptions; export type RulesRecord = Partial>; - export type GlobalVariableOptionBase = 'readonly' | 'writable' | 'off'; + export type GlobalVariableOptionBase = 'off' | 'readonly' | 'writable'; export type GlobalVariableOption = GlobalVariableOptionBase | boolean; export interface GlobalsConfig { @@ -147,7 +147,7 @@ namespace Linter { /** * The path to other config files or the package name of shareable configs. */ - extends?: string | string[]; + extends?: string[] | string; /** * The global variable settings. */ @@ -191,15 +191,15 @@ namespace Linter { } export interface ConfigOverride extends BaseConfig { - excludedFiles?: string | string[]; - files: string | string[]; + excludedFiles?: string[] | string; + files: string[] | string; } export interface Config extends BaseConfig { /** * The glob patterns that ignore to lint. */ - ignorePatterns?: string | string[]; + ignorePatterns?: string[] | string; /** * The root flag. */ @@ -242,7 +242,7 @@ namespace Linter { /** * Adds reported errors for unused `eslint-disable` directives. */ - reportUnusedDisableDirectives?: boolean | SeverityString; + reportUnusedDisableDirectives?: SeverityString | boolean; } export interface FixOptions extends VerifyOptions { diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts index f798e6e8cce2..16d34a67fc2a 100644 --- a/packages/utils/src/ts-eslint/Rule.ts +++ b/packages/utils/src/ts-eslint/Rule.ts @@ -63,7 +63,7 @@ interface RuleMetaData { * - `"suggestion"` means the rule is identifying something that could be done in a better way but no errors will occur if the code isn’t changed. * - `"layout"` means the rule cares primarily about whitespace, semicolons, commas, and parentheses, all the parts of the program that determine how the code looks rather than how it executes. These rules work on parts of the code that aren’t specified in the AST. */ - type: 'suggestion' | 'problem' | 'layout'; + type: 'layout' | 'problem' | 'suggestion'; /** * The name of the rule this rule was replaced by, if it was deprecated. */ @@ -113,7 +113,7 @@ interface SuggestionReportDescriptor type ReportFixFunction = ( fixer: RuleFixer, -) => null | RuleFix | readonly RuleFix[] | IterableIterator; +) => IterableIterator | RuleFix | readonly RuleFix[] | null; type ReportSuggestionArray = SuggestionReportDescriptor[]; @@ -153,18 +153,18 @@ interface ReportDescriptorNodeOptionalLoc { * An override of the location of the report */ readonly loc?: - | Readonly - | Readonly; + | Readonly + | Readonly; } interface ReportDescriptorLocOnly { /** * An override of the location of the report */ - loc: Readonly | Readonly; + loc: Readonly | Readonly; } type ReportDescriptor = ReportDescriptorWithSuggestion & - (ReportDescriptorNodeOptionalLoc | ReportDescriptorLocOnly); + (ReportDescriptorLocOnly | ReportDescriptorNodeOptionalLoc); /** * Plugins can add their settings using declaration @@ -435,8 +435,8 @@ interface RuleListenerCatchAllBaseCase { interface RuleListenerExtension {} type RuleListener = RuleListenerBaseSelectors & - RuleListenerExitSelectors & - RuleListenerCatchAllBaseCase; + RuleListenerCatchAllBaseCase & + RuleListenerExitSelectors; interface RuleModule< TMessageIds extends string, diff --git a/packages/utils/src/ts-eslint/RuleTester.ts b/packages/utils/src/ts-eslint/RuleTester.ts index 51f7840fc363..5e2af43d59b5 100644 --- a/packages/utils/src/ts-eslint/RuleTester.ts +++ b/packages/utils/src/ts-eslint/RuleTester.ts @@ -31,7 +31,7 @@ interface ValidTestCase> { /** * The additional global variables. */ - readonly globals?: Record; + readonly globals?: Record; /** * Options for the test case. */ @@ -195,8 +195,8 @@ declare class RuleTesterBase { defineRule>( name: string, rule: - | RuleModule - | RuleCreateFunction, + | RuleCreateFunction + | RuleModule, ): void; } diff --git a/packages/utils/src/ts-eslint/Scope.ts b/packages/utils/src/ts-eslint/Scope.ts index bc3db012216c..8a89ca02bd59 100644 --- a/packages/utils/src/ts-eslint/Scope.ts +++ b/packages/utils/src/ts-eslint/Scope.ts @@ -6,8 +6,8 @@ namespace Scope { export type ScopeManager = scopeManager.ScopeManager; export type Reference = scopeManager.Reference; export type Variable = - | scopeManager.Variable - | scopeManager.ESLintScopeVariable; + | scopeManager.ESLintScopeVariable + | scopeManager.Variable; export type Scope = scopeManager.Scope; export const ScopeType = scopeManager.ScopeType; // TODO - in the next major, clean this up with a breaking change diff --git a/packages/utils/src/ts-eslint/SourceCode.ts b/packages/utils/src/ts-eslint/SourceCode.ts index a44cdee3676b..3d7f33dd93c2 100644 --- a/packages/utils/src/ts-eslint/SourceCode.ts +++ b/packages/utils/src/ts-eslint/SourceCode.ts @@ -295,8 +295,8 @@ declare class SourceCodeBase extends TokenStore { * @returns True if there is a whitespace character between any of the tokens found between the two given nodes or tokens. */ isSpaceBetween?( - first: TSESTree.Token | TSESTree.Node, - second: TSESTree.Token | TSESTree.Node, + first: TSESTree.Node | TSESTree.Token, + second: TSESTree.Node | TSESTree.Token, ): boolean; /** * Determines if two nodes or tokens have at least one whitespace character @@ -410,8 +410,8 @@ namespace SourceCode { >; export type CursorWithSkipOptions = - | number | FilterPredicate + | number | { /** * The predicate function to choose tokens. @@ -428,8 +428,8 @@ namespace SourceCode { }; export type CursorWithCountOptions = - | number | FilterPredicate + | number | { /** * The predicate function to choose tokens. diff --git a/packages/visitor-keys/src/visitor-keys.ts b/packages/visitor-keys/src/visitor-keys.ts index d6b264350008..eaff7e7ccc26 100644 --- a/packages/visitor-keys/src/visitor-keys.ts +++ b/packages/visitor-keys/src/visitor-keys.ts @@ -7,18 +7,18 @@ interface VisitorKeys { type GetNodeTypeKeys = Exclude< keyof Extract, - 'type' | 'loc' | 'range' | 'parent' + 'loc' | 'parent' | 'range' | 'type' >; type KeysDefinedInESLintVisitorKeysCore = - | AST_NODE_TYPES.AssignmentExpression - | AST_NODE_TYPES.AssignmentPattern | AST_NODE_TYPES.ArrayExpression | AST_NODE_TYPES.ArrayPattern | AST_NODE_TYPES.ArrowFunctionExpression + | AST_NODE_TYPES.AssignmentExpression + | AST_NODE_TYPES.AssignmentPattern | AST_NODE_TYPES.AwaitExpression - | AST_NODE_TYPES.BlockStatement | AST_NODE_TYPES.BinaryExpression + | AST_NODE_TYPES.BlockStatement | AST_NODE_TYPES.BreakStatement | AST_NODE_TYPES.CallExpression | AST_NODE_TYPES.CatchClause @@ -36,11 +36,9 @@ type KeysDefinedInESLintVisitorKeysCore = | AST_NODE_TYPES.ExportNamedDeclaration | AST_NODE_TYPES.ExportSpecifier | AST_NODE_TYPES.ExpressionStatement - // | AST_NODE_TYPES.ExperimentalRestProperty - // | AST_NODE_TYPES.ExperimentalSpreadProperty - | AST_NODE_TYPES.ForStatement | AST_NODE_TYPES.ForInStatement | AST_NODE_TYPES.ForOfStatement + | AST_NODE_TYPES.ForStatement | AST_NODE_TYPES.FunctionDeclaration | AST_NODE_TYPES.FunctionExpression | AST_NODE_TYPES.Identifier @@ -52,20 +50,20 @@ type KeysDefinedInESLintVisitorKeysCore = | AST_NODE_TYPES.ImportSpecifier | AST_NODE_TYPES.JSXAttribute | AST_NODE_TYPES.JSXClosingElement + | AST_NODE_TYPES.JSXClosingFragment | AST_NODE_TYPES.JSXElement | AST_NODE_TYPES.JSXEmptyExpression | AST_NODE_TYPES.JSXExpressionContainer + | AST_NODE_TYPES.JSXFragment | AST_NODE_TYPES.JSXIdentifier | AST_NODE_TYPES.JSXMemberExpression | AST_NODE_TYPES.JSXNamespacedName | AST_NODE_TYPES.JSXOpeningElement + | AST_NODE_TYPES.JSXOpeningFragment | AST_NODE_TYPES.JSXSpreadAttribute | AST_NODE_TYPES.JSXText - | AST_NODE_TYPES.JSXFragment - | AST_NODE_TYPES.JSXClosingFragment - | AST_NODE_TYPES.JSXOpeningFragment - | AST_NODE_TYPES.Literal | AST_NODE_TYPES.LabeledStatement + | AST_NODE_TYPES.Literal | AST_NODE_TYPES.LogicalExpression | AST_NODE_TYPES.MemberExpression | AST_NODE_TYPES.MetaProperty @@ -83,8 +81,8 @@ type KeysDefinedInESLintVisitorKeysCore = | AST_NODE_TYPES.SpreadElement | AST_NODE_TYPES.StaticBlock | AST_NODE_TYPES.Super - | AST_NODE_TYPES.SwitchStatement | AST_NODE_TYPES.SwitchCase + | AST_NODE_TYPES.SwitchStatement | AST_NODE_TYPES.TaggedTemplateExpression | AST_NODE_TYPES.TemplateElement | AST_NODE_TYPES.TemplateLiteral @@ -101,14 +99,14 @@ type KeysDefinedInESLintVisitorKeysCore = // strictly type the arrays of keys provided to make sure we keep this config in sync with the type defs type AdditionalKeys = { + // optionally allow keys for all nodes defined in `eslint-visitor-keys` + readonly [T in KeysDefinedInESLintVisitorKeysCore]?: readonly GetNodeTypeKeys[]; +} & { // require keys for all nodes NOT defined in `eslint-visitor-keys` readonly [T in Exclude< AST_NODE_TYPES, KeysDefinedInESLintVisitorKeysCore >]: readonly GetNodeTypeKeys[]; -} & { - // optionally allow keys for all nodes defined in `eslint-visitor-keys` - readonly [T in KeysDefinedInESLintVisitorKeysCore]?: readonly GetNodeTypeKeys[]; }; /** diff --git a/packages/website-eslint/build.ts b/packages/website-eslint/build.ts index ee24cee305a7..85fb695499b3 100644 --- a/packages/website-eslint/build.ts +++ b/packages/website-eslint/build.ts @@ -18,7 +18,7 @@ function requireMock(targetPath: string): Promise { return fs.readFile(requireResolved(targetPath), 'utf8'); } -function makeFilter(filePath: string | string[]): { filter: RegExp } { +function makeFilter(filePath: string[] | string): { filter: RegExp } { const paths = Array.isArray(filePath) ? filePath : [filePath]; const norm = paths.map(item => normalizePath(item).replace(/\//g, '[\\\\/]').replace(/\./g, '\\.'), diff --git a/packages/website/docusaurusConfig.ts b/packages/website/docusaurusConfig.ts index ad1900d8c17c..e92be50f6ac4 100644 --- a/packages/website/docusaurusConfig.ts +++ b/packages/website/docusaurusConfig.ts @@ -53,7 +53,7 @@ const pluginContentDocsOptions: PluginContentDocsOptions = { breadcrumbs: false, }; -const themeConfig: ThemeCommonConfig & AlgoliaThemeConfig = { +const themeConfig: AlgoliaThemeConfig & ThemeCommonConfig = { algolia: { appId: 'N1HUB2TU6A', apiKey: '74d42ed10d0f7b327d74d774570035c7', diff --git a/packages/website/src/components/RulesTable/index.tsx b/packages/website/src/components/RulesTable/index.tsx index 4a12f1bad2c6..6cb2a78e6c84 100644 --- a/packages/website/src/components/RulesTable/index.tsx +++ b/packages/website/src/components/RulesTable/index.tsx @@ -221,10 +221,10 @@ export default function RulesTable({ } type FilterCategory = + | 'fixable' | 'recommended' | 'strict' | 'stylistic' - | 'fixable' | 'suggestions' | 'typeInformation'; type FiltersState = Record; diff --git a/packages/website/src/components/ast/selectedRange.ts b/packages/website/src/components/ast/selectedRange.ts index a17867acb69a..4fa89b843a52 100644 --- a/packages/website/src/components/ast/selectedRange.ts +++ b/packages/website/src/components/ast/selectedRange.ts @@ -17,7 +17,7 @@ function isIterable(key: string, value: unknown): boolean { return filterProperties(key, value, geNodeType(value)); } -function getRangeFromNode(value: object): null | [number, number] { +function getRangeFromNode(value: object): [number, number] | null { if (isESNode(value)) { return value.range; } else if (isTSNode(value)) { @@ -30,10 +30,10 @@ function findInObject( iter: object, cursorPosition: number, visited: Set, -): null | { +): { key: string[]; value: object; -} { +} | null { const children = Object.entries(iter); for (const [name, child] of children) { // we do not want to select parents in case if we do filter with esquery @@ -73,7 +73,7 @@ export function findSelectionPath( ): { path: string[]; node: object | null } { const nodePath = ['ast']; const visited = new Set(); - let currentNode: null | object = node; + let currentNode: object | null = node; while (currentNode) { // infinite loop guard if (visited.has(currentNode)) { diff --git a/packages/website/src/components/ast/tsUtils.ts b/packages/website/src/components/ast/tsUtils.ts index d5653380b0ca..6d4232a58c78 100644 --- a/packages/website/src/components/ast/tsUtils.ts +++ b/packages/website/src/components/ast/tsUtils.ts @@ -19,7 +19,7 @@ interface TsParsedEnums { * e.g. SyntaxKind.EqualsToken = 63, SyntaxKind.FirstAssignment = 63 */ export function extractEnum( - obj: Record, + obj: Record, ): Record { const result: Record = {}; const keys = Object.entries(obj); diff --git a/packages/website/src/components/ast/types.ts b/packages/website/src/components/ast/types.ts index a6a6b9ec6d16..308a2ba95251 100644 --- a/packages/website/src/components/ast/types.ts +++ b/packages/website/src/components/ast/types.ts @@ -2,14 +2,14 @@ export type OnHoverNodeFn = (node?: [number, number]) => void; export type ParentNodeType = | 'esNode' - | 'tsNode' - | 'tsType' - | 'tsSymbol' - | 'tsSignature' - | 'tsFlow' | 'scope' - | 'scopeManager' - | 'scopeVariable' | 'scopeDefinition' + | 'scopeManager' | 'scopeReference' + | 'scopeVariable' + | 'tsFlow' + | 'tsNode' + | 'tsSignature' + | 'tsSymbol' + | 'tsType' | undefined; diff --git a/packages/website/src/components/editor/types.ts b/packages/website/src/components/editor/types.ts index dd24562f5825..bc7b886f535f 100644 --- a/packages/website/src/components/editor/types.ts +++ b/packages/website/src/components/editor/types.ts @@ -7,9 +7,9 @@ export interface CommonEditorProps extends ConfigModel { readonly activeTab: TabType; readonly selectedRange?: SelectedRange; readonly onChange: (cfg: Partial) => void; - readonly onTsASTChange: (value: undefined | SourceFile) => void; - readonly onEsASTChange: (value: undefined | TSESTree.Program) => void; - readonly onScopeChange: (value: undefined | Record) => void; + readonly onTsASTChange: (value: SourceFile | undefined) => void; + readonly onEsASTChange: (value: TSESTree.Program | undefined) => void; + readonly onScopeChange: (value: Record | undefined) => void; readonly onMarkersChange: (value: ErrorGroup[]) => void; readonly onSelect: (position?: number) => void; } diff --git a/packages/website/src/components/inputs/Dropdown.tsx b/packages/website/src/components/inputs/Dropdown.tsx index cb3f78cd0d9a..a735361a0f7d 100644 --- a/packages/website/src/components/inputs/Dropdown.tsx +++ b/packages/website/src/components/inputs/Dropdown.tsx @@ -17,7 +17,7 @@ export interface DropdownProps { readonly disabled?: boolean; } -function Dropdown( +function Dropdown( props: DropdownProps, ): JSX.Element { const options: DropdownOption[] = props.options.map(option => diff --git a/packages/website/src/components/inputs/Text.tsx b/packages/website/src/components/inputs/Text.tsx index 9a2613193f83..d669620d9880 100644 --- a/packages/website/src/components/inputs/Text.tsx +++ b/packages/website/src/components/inputs/Text.tsx @@ -8,7 +8,7 @@ export interface DropdownProps { readonly value: string; readonly name: string; readonly className?: string; - readonly type?: 'text' | 'search'; + readonly type?: 'search' | 'text'; readonly placeholder?: string; } diff --git a/packages/website/src/components/inputs/Tooltip.tsx b/packages/website/src/components/inputs/Tooltip.tsx index fcef27e9dc29..9a6576395962 100644 --- a/packages/website/src/components/inputs/Tooltip.tsx +++ b/packages/website/src/components/inputs/Tooltip.tsx @@ -4,7 +4,7 @@ import React from 'react'; import styles from './Tooltip.module.css'; export interface TooltipProps { - readonly children: JSX.Element | (JSX.Element | false)[]; + readonly children: (JSX.Element | false)[] | JSX.Element; readonly text: string; readonly position?: 'left' | 'right'; readonly open?: boolean; diff --git a/packages/website/src/components/layout/AlertBlock.tsx b/packages/website/src/components/layout/AlertBlock.tsx index adfa071acdd8..bbf166c6f772 100644 --- a/packages/website/src/components/layout/AlertBlock.tsx +++ b/packages/website/src/components/layout/AlertBlock.tsx @@ -1,7 +1,7 @@ import React from 'react'; export interface AlertBlockProps { - readonly type: 'success' | 'info' | 'note' | 'warning' | 'danger'; + readonly type: 'danger' | 'info' | 'note' | 'success' | 'warning'; readonly children: React.ReactNode; } diff --git a/packages/website/src/components/layout/EditorTabs.tsx b/packages/website/src/components/layout/EditorTabs.tsx index 2890908cc554..5a4f9aa7131f 100644 --- a/packages/website/src/components/layout/EditorTabs.tsx +++ b/packages/website/src/components/layout/EditorTabs.tsx @@ -4,15 +4,15 @@ import React from 'react'; import styles from './EditorTabs.module.css'; -export interface EditorTabsProps { - readonly tabs: ({ value: T; label: string } | T)[]; +export interface EditorTabsProps { + readonly tabs: (T | { value: T; label: string })[]; readonly active: T; readonly showVisualEditor?: boolean; readonly change: (name: T) => void; readonly showModal?: (name: T) => void; } -function EditorTabs({ +function EditorTabs({ tabs, active, showVisualEditor, diff --git a/packages/website/src/components/lib/markdown.ts b/packages/website/src/components/lib/markdown.ts index 0081d973f54e..682378c5a5a6 100644 --- a/packages/website/src/components/lib/markdown.ts +++ b/packages/website/src/components/lib/markdown.ts @@ -4,7 +4,7 @@ import { parseESLintRC } from './parseConfig'; function createSummary( value: string, title: string, - type: 'ts' | 'json', + type: 'json' | 'ts', length: number, ): string { const code = `### ${title}\n\n\`\`\`${type}\n${value}\n\`\`\``; diff --git a/packages/website/src/components/lib/shallowEqual.ts b/packages/website/src/components/lib/shallowEqual.ts index 290ee147ae04..fc6909430cf8 100644 --- a/packages/website/src/components/lib/shallowEqual.ts +++ b/packages/website/src/components/lib/shallowEqual.ts @@ -2,8 +2,8 @@ * Shallowly compare two objects. */ export function shallowEqual( - object1: object | undefined | null, - object2: object | undefined | null, + object1: object | null | undefined, + object2: object | null | undefined, ): boolean { if (object1 === object2) { return true; diff --git a/packages/website/src/components/linter/bridge.ts b/packages/website/src/components/linter/bridge.ts index b0614fc4329d..4a4d52e44637 100644 --- a/packages/website/src/components/linter/bridge.ts +++ b/packages/website/src/components/linter/bridge.ts @@ -6,7 +6,7 @@ import type { ConfigModel } from '../types'; import type { PlaygroundSystem } from './types'; export function createFileSystem( - config: Pick, + config: Pick, vfs: typeof tsvfs, ): PlaygroundSystem { const files = new Map(); diff --git a/packages/website/src/components/linter/types.ts b/packages/website/src/components/linter/types.ts index 3623eb649ff7..540ad0e45218 100644 --- a/packages/website/src/components/linter/types.ts +++ b/packages/website/src/components/linter/types.ts @@ -22,8 +22,10 @@ export interface WebLinterModule { configs: Record; } -export type PlaygroundSystem = ts.System & - Required> & { +export type PlaygroundSystem = Required< + Pick +> & + ts.System & { removeFile: (fileName: string) => void; }; diff --git a/packages/website/src/components/types.ts b/packages/website/src/components/types.ts index deee8560f638..219443b6b952 100644 --- a/packages/website/src/components/types.ts +++ b/packages/website/src/components/types.ts @@ -13,11 +13,11 @@ export interface RuleDetails { url?: string; } -export type TabType = 'code' | 'tsconfig' | 'eslintrc'; +export type TabType = 'code' | 'eslintrc' | 'tsconfig'; export type ConfigFileType = `${ts.Extension}`; -export type ConfigShowAst = false | 'es' | 'ts' | 'scope'; +export type ConfigShowAst = 'es' | 'scope' | 'ts' | false; export interface ConfigModel { fileType?: ConfigFileType; diff --git a/packages/website/typings/esquery.d.ts b/packages/website/typings/esquery.d.ts index 3c425933e180..aca8d71c8bb8 100644 --- a/packages/website/typings/esquery.d.ts +++ b/packages/website/typings/esquery.d.ts @@ -27,33 +27,33 @@ declare module 'esquery' { // Unions // type Selector = + | Adjacent + | Attribute + | Child + | Class + | Descendant | Field - | Type - | Sequence + | Has | Identifier - | Wildcard - | Attribute + | Matches + | Negation | NthChild | NthLastChild - | Descendant - | Child + | Sequence | Sibling - | Adjacent - | Negation - | Matches - | Has - | Class; - type MultiSelector = Sequence | Negation | Matches | Has; - type BinarySelector = Descendant | Child | Sibling | Adjacent; + | Type + | Wildcard; + type MultiSelector = Has | Matches | Negation | Sequence; + type BinarySelector = Adjacent | Child | Descendant | Sibling; type NthSelector = NthChild | NthLastChild; type SubjectSelector = - | NthSelector + | Attribute | BinarySelector - | MultiSelector | Identifier - | Wildcard - | Attribute; - type Literal = StringLiteral | NumericLiteral; + | MultiSelector + | NthSelector + | Wildcard; + type Literal = NumericLiteral | StringLiteral; // // Base Atoms @@ -68,7 +68,7 @@ declare module 'esquery' { index: NumericLiteral; } interface BinarySelectorAtom extends SubjectSelectorAtom { - type: 'child' | 'sibling' | 'adjacent' | 'descendant'; + type: 'adjacent' | 'child' | 'descendant' | 'sibling'; left: SubjectSelector; right: SubjectSelector; } @@ -77,7 +77,7 @@ declare module 'esquery' { } interface LiteralAtom extends Atom { type: 'literal'; - value: string | number; + value: number | string; } // @@ -119,7 +119,7 @@ declare module 'esquery' { interface Attribute extends SubjectSelectorAtom { type: 'attribute'; name: string; - operator?: '=' | '!=' | '>' | '<' | '>=' | '<=' | undefined; + operator?: '!=' | '<' | '<=' | '=' | '>' | '>=' | undefined; value?: Literal | RegExpLiteral | Type | undefined; } interface NthChild extends NthSelectorAtom {