Skip to content

Commit

Permalink
fix(utils): add missing entries to the RuleListener selectors list (#…
Browse files Browse the repository at this point in the history
…9992)

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

* fix knip err
  • Loading branch information
auvred authored Sep 18, 2024
1 parent 343710e commit 385bedb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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>;
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
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>;

0 comments on commit 385bedb

Please sign in to comment.