From 5c316c12f09d58aee6ee634a8055533f361f1589 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Mon, 31 Oct 2022 05:58:30 -0700 Subject: [PATCH] fix(ast-spec): add TSQualifiedName to TypeNode union (#5906) * fix(ast-spec): add TSQualifiedName to TypeNode union * fix rule with missing type --- packages/ast-spec/src/unions/TypeNode.ts | 2 ++ packages/eslint-plugin/src/rules/sort-type-constituents.ts | 1 + .../src/rules/sort-type-union-intersection-members.ts | 1 + .../tests/rules/sort-type-constituents.test.ts | 6 +++++- .../rules/sort-type-union-intersection-members.test.ts | 6 +++++- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/ast-spec/src/unions/TypeNode.ts b/packages/ast-spec/src/unions/TypeNode.ts index 461281cd4ce..f1859d7d347 100644 --- a/packages/ast-spec/src/unions/TypeNode.ts +++ b/packages/ast-spec/src/unions/TypeNode.ts @@ -25,6 +25,7 @@ import type { TSOptionalType } from '../type/TSOptionalType/spec'; import type { TSPrivateKeyword } from '../type/TSPrivateKeyword/spec'; import type { TSProtectedKeyword } from '../type/TSProtectedKeyword/spec'; import type { TSPublicKeyword } from '../type/TSPublicKeyword/spec'; +import type { TSQualifiedName } from '../type/TSQualifiedName/spec'; import type { TSReadonlyKeyword } from '../type/TSReadonlyKeyword/spec'; import type { TSRestType } from '../type/TSRestType/spec'; import type { TSStaticKeyword } from '../type/TSStaticKeyword/spec'; @@ -71,6 +72,7 @@ export type TypeNode = | TSPrivateKeyword | TSProtectedKeyword | TSPublicKeyword + | TSQualifiedName | TSReadonlyKeyword | TSRestType | TSStaticKeyword diff --git a/packages/eslint-plugin/src/rules/sort-type-constituents.ts b/packages/eslint-plugin/src/rules/sort-type-constituents.ts index 92b5e44c6f9..1abeddcf823 100644 --- a/packages/eslint-plugin/src/rules/sort-type-constituents.ts +++ b/packages/eslint-plugin/src/rules/sort-type-constituents.ts @@ -60,6 +60,7 @@ function getGroup(node: TSESTree.TypeNode): Group { case AST_NODE_TYPES.TSIndexedAccessType: case AST_NODE_TYPES.TSInferType: case AST_NODE_TYPES.TSTypeReference: + case AST_NODE_TYPES.TSQualifiedName: return Group.named; case AST_NODE_TYPES.TSMappedType: diff --git a/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts b/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts index 2a83b4b0525..1fbf91b9ae8 100644 --- a/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts +++ b/packages/eslint-plugin/src/rules/sort-type-union-intersection-members.ts @@ -60,6 +60,7 @@ function getGroup(node: TSESTree.TypeNode): Group { case AST_NODE_TYPES.TSIndexedAccessType: case AST_NODE_TYPES.TSInferType: case AST_NODE_TYPES.TSTypeReference: + case AST_NODE_TYPES.TSQualifiedName: return Group.named; case AST_NODE_TYPES.TSMappedType: 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 b9989c2cf87..2587375060e 100644 --- a/packages/eslint-plugin/tests/rules/sort-type-constituents.test.ts +++ b/packages/eslint-plugin/tests/rules/sort-type-constituents.test.ts @@ -45,6 +45,8 @@ const valid = (operator: '|' | '&'): TSESLint.ValidTestCase[] => [ type T = ${operator} A ${operator} B + ${operator} C.D + ${operator} D.E ${operator} intrinsic ${operator} number[] ${operator} string[] @@ -220,6 +222,8 @@ type T = ${operator} readonly number[] ${operator} string[] ${operator} number[] + ${operator} D.E + ${operator} C.D ${operator} B ${operator} A ${operator} undefined @@ -229,7 +233,7 @@ type T = `, output: ` type T = - A ${operator} B ${operator} number[] ${operator} string[] ${operator} any ${operator} string ${operator} readonly number[] ${operator} readonly string[] ${operator} 'a' ${operator} 'b' ${operator} "a" ${operator} "b" ${operator} (() => string) ${operator} (() => void) ${operator} { a: string } ${operator} { b: string } ${operator} [1, 2, 3] ${operator} [1, 2, 4] ${operator} null ${operator} undefined; + A ${operator} B ${operator} C.D ${operator} D.E ${operator} number[] ${operator} string[] ${operator} any ${operator} string ${operator} readonly number[] ${operator} readonly string[] ${operator} 'a' ${operator} 'b' ${operator} "a" ${operator} "b" ${operator} (() => string) ${operator} (() => void) ${operator} { a: string } ${operator} { b: string } ${operator} [1, 2, 3] ${operator} [1, 2, 4] ${operator} null ${operator} undefined; `, errors: [ { diff --git a/packages/eslint-plugin/tests/rules/sort-type-union-intersection-members.test.ts b/packages/eslint-plugin/tests/rules/sort-type-union-intersection-members.test.ts index 38ae67f1804..a24959d8b6a 100644 --- a/packages/eslint-plugin/tests/rules/sort-type-union-intersection-members.test.ts +++ b/packages/eslint-plugin/tests/rules/sort-type-union-intersection-members.test.ts @@ -45,6 +45,8 @@ const valid = (operator: '|' | '&'): TSESLint.ValidTestCase[] => [ type T = ${operator} A ${operator} B + ${operator} C.D + ${operator} D.E ${operator} intrinsic ${operator} number[] ${operator} string[] @@ -220,6 +222,8 @@ type T = ${operator} readonly number[] ${operator} string[] ${operator} number[] + ${operator} D.E + ${operator} C.D ${operator} B ${operator} A ${operator} undefined @@ -229,7 +233,7 @@ type T = `, output: ` type T = - A ${operator} B ${operator} number[] ${operator} string[] ${operator} any ${operator} string ${operator} readonly number[] ${operator} readonly string[] ${operator} 'a' ${operator} 'b' ${operator} "a" ${operator} "b" ${operator} (() => string) ${operator} (() => void) ${operator} { a: string } ${operator} { b: string } ${operator} [1, 2, 3] ${operator} [1, 2, 4] ${operator} null ${operator} undefined; + A ${operator} B ${operator} C.D ${operator} D.E ${operator} number[] ${operator} string[] ${operator} any ${operator} string ${operator} readonly number[] ${operator} readonly string[] ${operator} 'a' ${operator} 'b' ${operator} "a" ${operator} "b" ${operator} (() => string) ${operator} (() => void) ${operator} { a: string } ${operator} { b: string } ${operator} [1, 2, 3] ${operator} [1, 2, 4] ${operator} null ${operator} undefined; `, errors: [ {