Skip to content

fix(utils): add missing entries to the RuleListener selectors list #9992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export default {
entry: ['src/use-at-your-own-risk.ts'],
ignore: ['tests/fixtures/**'],
},
'packages/utils': {
ignore: ['tests/**/*.type-test.ts'],
},
'packages/website': {
entry: [
'docusaurus.config.mts',
Expand Down
11 changes: 10 additions & 1 deletion packages/utils/src/ts-eslint/Rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ interface RuleListenerBaseSelectors {
AssignmentExpression?: RuleFunction<TSESTree.AssignmentExpression>;
AssignmentPattern?: RuleFunction<TSESTree.AssignmentPattern>;
AwaitExpression?: RuleFunction<TSESTree.AwaitExpression>;
BigIntLiteral?: RuleFunction<TSESTree.BigIntLiteral>;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no such node as BigIntLiteral, it is just an extension of LiteralBase which have type: AST_NODE_TYPES.Literal.

BinaryExpression?: RuleFunction<TSESTree.BinaryExpression>;
BlockStatement?: RuleFunction<TSESTree.BlockStatement>;
BreakStatement?: RuleFunction<TSESTree.BreakStatement>;
Expand Down Expand Up @@ -451,6 +450,7 @@ interface RuleListenerBaseSelectors {
FunctionExpression?: RuleFunction<TSESTree.FunctionExpression>;
Identifier?: RuleFunction<TSESTree.Identifier>;
IfStatement?: RuleFunction<TSESTree.IfStatement>;
ImportAttribute?: RuleFunction<TSESTree.ImportAttribute>;
ImportDeclaration?: RuleFunction<TSESTree.ImportDeclaration>;
ImportDefaultSpecifier?: RuleFunction<TSESTree.ImportDefaultSpecifier>;
ImportExpression?: RuleFunction<TSESTree.ImportExpression>;
Expand All @@ -465,6 +465,7 @@ interface RuleListenerBaseSelectors {
JSXFragment?: RuleFunction<TSESTree.JSXFragment>;
JSXIdentifier?: RuleFunction<TSESTree.JSXIdentifier>;
JSXMemberExpression?: RuleFunction<TSESTree.JSXMemberExpression>;
JSXNamespacedName?: RuleFunction<TSESTree.JSXNamespacedName>;
JSXOpeningElement?: RuleFunction<TSESTree.JSXOpeningElement>;
JSXOpeningFragment?: RuleFunction<TSESTree.JSXOpeningFragment>;
JSXSpreadAttribute?: RuleFunction<TSESTree.JSXSpreadAttribute>;
Expand All @@ -479,13 +480,15 @@ interface RuleListenerBaseSelectors {
NewExpression?: RuleFunction<TSESTree.NewExpression>;
ObjectExpression?: RuleFunction<TSESTree.ObjectExpression>;
ObjectPattern?: RuleFunction<TSESTree.ObjectPattern>;
PrivateIdentifier?: RuleFunction<TSESTree.PrivateIdentifier>;
Program?: RuleFunction<TSESTree.Program>;
Property?: RuleFunction<TSESTree.Property>;
PropertyDefinition?: RuleFunction<TSESTree.PropertyDefinition>;
RestElement?: RuleFunction<TSESTree.RestElement>;
ReturnStatement?: RuleFunction<TSESTree.ReturnStatement>;
SequenceExpression?: RuleFunction<TSESTree.SequenceExpression>;
SpreadElement?: RuleFunction<TSESTree.SpreadElement>;
StaticBlock?: RuleFunction<TSESTree.StaticBlock>;
Super?: RuleFunction<TSESTree.Super>;
SwitchCase?: RuleFunction<TSESTree.SwitchCase>;
SwitchStatement?: RuleFunction<TSESTree.SwitchStatement>;
Expand All @@ -495,6 +498,7 @@ interface RuleListenerBaseSelectors {
ThisExpression?: RuleFunction<TSESTree.ThisExpression>;
ThrowStatement?: RuleFunction<TSESTree.ThrowStatement>;
TryStatement?: RuleFunction<TSESTree.TryStatement>;
TSAbstractAccessorProperty?: RuleFunction<TSESTree.TSAbstractAccessorProperty>;
TSAbstractKeyword?: RuleFunction<TSESTree.TSAbstractKeyword>;
TSAbstractMethodDefinition?: RuleFunction<TSESTree.TSAbstractMethodDefinition>;
TSAbstractPropertyDefinition?: RuleFunction<TSESTree.TSAbstractPropertyDefinition>;
Expand All @@ -512,6 +516,7 @@ interface RuleListenerBaseSelectors {
TSDeclareFunction?: RuleFunction<TSESTree.TSDeclareFunction>;
TSDeclareKeyword?: RuleFunction<TSESTree.TSDeclareKeyword>;
TSEmptyBodyFunctionExpression?: RuleFunction<TSESTree.TSEmptyBodyFunctionExpression>;
TSEnumBody?: RuleFunction<TSESTree.TSEnumBody>;
TSEnumDeclaration?: RuleFunction<TSESTree.TSEnumDeclaration>;
TSEnumMember?: RuleFunction<TSESTree.TSEnumMember>;
TSExportAssignment?: RuleFunction<TSESTree.TSExportAssignment>;
Expand All @@ -523,15 +528,18 @@ interface RuleListenerBaseSelectors {
TSIndexedAccessType?: RuleFunction<TSESTree.TSIndexedAccessType>;
TSIndexSignature?: RuleFunction<TSESTree.TSIndexSignature>;
TSInferType?: RuleFunction<TSESTree.TSInferType>;
TSInstantiationExpression?: RuleFunction<TSESTree.TSInstantiationExpression>;
TSInterfaceBody?: RuleFunction<TSESTree.TSInterfaceBody>;
TSInterfaceDeclaration?: RuleFunction<TSESTree.TSInterfaceDeclaration>;
TSInterfaceHeritage?: RuleFunction<TSESTree.TSInterfaceHeritage>;
TSIntersectionType?: RuleFunction<TSESTree.TSIntersectionType>;
TSIntrinsicKeyword?: RuleFunction<TSESTree.TSIntrinsicKeyword>;
TSLiteralType?: RuleFunction<TSESTree.TSLiteralType>;
TSMappedType?: RuleFunction<TSESTree.TSMappedType>;
TSMethodSignature?: RuleFunction<TSESTree.TSMethodSignature>;
TSModuleBlock?: RuleFunction<TSESTree.TSModuleBlock>;
TSModuleDeclaration?: RuleFunction<TSESTree.TSModuleDeclaration>;
TSNamedTupleMember?: RuleFunction<TSESTree.TSNamedTupleMember>;
TSNamespaceExportDeclaration?: RuleFunction<TSESTree.TSNamespaceExportDeclaration>;
TSNeverKeyword?: RuleFunction<TSESTree.TSNeverKeyword>;
TSNonNullExpression?: RuleFunction<TSESTree.TSNonNullExpression>;
Expand All @@ -551,6 +559,7 @@ interface RuleListenerBaseSelectors {
TSStaticKeyword?: RuleFunction<TSESTree.TSStaticKeyword>;
TSStringKeyword?: RuleFunction<TSESTree.TSStringKeyword>;
TSSymbolKeyword?: RuleFunction<TSESTree.TSSymbolKeyword>;
TSTemplateLiteralType?: RuleFunction<TSESTree.TSTemplateLiteralType>;
TSThisType?: RuleFunction<TSESTree.TSThisType>;
TSTupleType?: RuleFunction<TSESTree.TSTupleType>;
TSTypeAliasDeclaration?: RuleFunction<TSESTree.TSTypeAliasDeclaration>;
Expand Down
37 changes: 37 additions & 0 deletions packages/utils/tests/ts-eslint/Rule.type-test.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, let's try this out 😄

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { TSESTree } from '@typescript-eslint/types';

import type { RuleListener } from '../../src/ts-eslint';

type RuleListenerKeysWithoutIndexSignature = {
[K in keyof RuleListener as string extends K ? never : K]: K;
};

type RuleListenerSelectors = NonNullable<
RuleListenerKeysWithoutIndexSignature[keyof RuleListenerKeysWithoutIndexSignature]
>;

type AllSelectors =
| `${TSESTree.AST_NODE_TYPES}`
| `${TSESTree.AST_NODE_TYPES}:exit`;

type ExpectNever<T extends never> = T;

type SelectorsWithWrongNodeType = {
[K in TSESTree.AST_NODE_TYPES]: Parameters<
NonNullable<RuleListener[K]>
>[0]['type'] extends K
? K extends Parameters<NonNullable<RuleListener[K]>>[0]['type']
? never
: K
: K;
}[TSESTree.AST_NODE_TYPES];
type _test_rule_listener_selectors_have_correct_node_types =
ExpectNever<SelectorsWithWrongNodeType>;

type ExtraSelectors = Exclude<RuleListenerSelectors, AllSelectors>;
type _test_rule_listener_does_not_define_extra_selectors =
ExpectNever<ExtraSelectors>;

type MissingSelectors = Exclude<AllSelectors, RuleListenerSelectors>;
type _test_rule_listener_has_selectors_for_all_node_types =
ExpectNever<MissingSelectors>;
Loading