Skip to content
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

[eslint] Enhance Rule.NodeListener type #45821

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion types/eslint/eslint-tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Comment } from 'estree';
import { Comment, WhileStatement } from 'estree';
import { AST, SourceCode, Rule, Linter, ESLint, CLIEngine, RuleTester, Scope } from 'eslint';

const SOURCE = `var foo = bar;`;
Expand Down Expand Up @@ -381,6 +381,7 @@ rule = {
onCodePathSegmentEnd(segment, node) {},
onCodePathSegmentLoop(fromSegment, toSegment, node) {},
IfStatement(node) {},
WhileStatement(node: WhileStatement) {},
'Program:exit'() {},
};
},
Expand Down
72 changes: 71 additions & 1 deletion types/eslint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,76 @@ export namespace Rule {
}

type NodeTypes = ESTree.Node['type'];
type NodeListener = { [T in NodeTypes]?: (node: ESTree.Node) => void };
interface NodeListener {
ArrayExpression?: (node: ESTree.ArrayExpression) => void;
ArrayPattern?: (node: ESTree.ArrayPattern) => void;
ArrowFunctionExpression?: (node: ESTree.ArrowFunctionExpression) => void;
AssignmentExpression?: (node: ESTree.AssignmentExpression) => void;
AssignmentPattern?: (node: ESTree.AssignmentPattern) => void;
AwaitExpression?: (node: ESTree.AwaitExpression) => void;
BinaryExpression?: (node: ESTree.BinaryExpression) => void;
BlockStatement?: (node: ESTree.BlockStatement) => void;
BreakStatement?: (node: ESTree.BreakStatement) => void;
CallExpression?: (node: ESTree.CallExpression) => void;
CatchClause?: (node: ESTree.CatchClause) => void;
ChainExpression?: (node: ESTree.ChainExpression) => void;
ClassBody?: (node: ESTree.ClassBody) => void;
ClassDeclaration?: (node: ESTree.ClassDeclaration) => void;
ClassExpression?: (node: ESTree.ClassExpression) => void;
ConditionalExpression?: (node: ESTree.ConditionalExpression) => void;
ContinueStatement?: (node: ESTree.ContinueStatement) => void;
DebuggerStatement?: (node: ESTree.DebuggerStatement) => void;
DoWhileStatement?: (node: ESTree.DoWhileStatement) => void;
EmptyStatement?: (node: ESTree.EmptyStatement) => void;
ExportAllDeclaration?: (node: ESTree.ExportAllDeclaration) => void;
ExportDefaultDeclaration?: (node: ESTree.ExportDefaultDeclaration) => void;
ExportNamedDeclaration?: (node: ESTree.ExportNamedDeclaration) => void;
ExportSpecifier?: (node: ESTree.ExportSpecifier) => void;
ExpressionStatement?: (node: ESTree.ExpressionStatement) => void;
ForInStatement?: (node: ESTree.ForInStatement) => void;
ForOfStatement?: (node: ESTree.ForOfStatement) => void;
ForStatement?: (node: ESTree.ForStatement) => void;
FunctionDeclaration?: (node: ESTree.FunctionDeclaration) => void;
FunctionExpression?: (node: ESTree.FunctionExpression) => void;
Identifier?: (node: ESTree.Identifier) => void;
IfStatement?: (node: ESTree.IfStatement) => void;
ImportDeclaration?: (node: ESTree.ImportDeclaration) => void;
ImportDefaultSpecifier?: (node: ESTree.ImportDefaultSpecifier) => void;
ImportExpression?: (node: ESTree.ImportExpression) => void;
ImportNamespaceSpecifier?: (node: ESTree.ImportNamespaceSpecifier) => void;
ImportSpecifier?: (node: ESTree.ImportSpecifier) => void;
LabeledStatement?: (node: ESTree.LabeledStatement) => void;
Literal?: (node: ESTree.Literal) => void;
LogicalExpression?: (node: ESTree.LogicalExpression) => void;
MemberExpression?: (node: ESTree.MemberExpression) => void;
MetaProperty?: (node: ESTree.MetaProperty) => void;
MethodDefinition?: (node: ESTree.MethodDefinition) => void;
NewExpression?: (node: ESTree.NewExpression) => void;
ObjectExpression?: (node: ESTree.ObjectExpression) => void;
ObjectPattern?: (node: ESTree.ObjectPattern) => void;
Program?: (node: ESTree.Program) => void;
Property?: (node: ESTree.Property) => void;
RestElement?: (node: ESTree.RestElement) => void;
ReturnStatement?: (node: ESTree.ReturnStatement) => void;
SequenceExpression?: (node: ESTree.SequenceExpression) => void;
SpreadElement?: (node: ESTree.SpreadElement) => void;
Super?: (node: ESTree.Super) => void;
SwitchCase?: (node: ESTree.SwitchCase) => void;
SwitchStatement?: (node: ESTree.SwitchStatement) => void;
TaggedTemplateExpression?: (node: ESTree.TaggedTemplateExpression) => void;
TemplateElement?: (node: ESTree.TemplateElement) => void;
TemplateLiteral?: (node: ESTree.TemplateLiteral) => void;
ThisExpression?: (node: ESTree.ThisExpression) => void;
ThrowStatement?: (node: ESTree.ThrowStatement) => void;
TryStatement?: (node: ESTree.TryStatement) => void;
UnaryExpression?: (node: ESTree.UnaryExpression) => void;
UpdateExpression?: (node: ESTree.UpdateExpression) => void;
VariableDeclaration?: (node: ESTree.VariableDeclaration) => void;
VariableDeclarator?: (node: ESTree.VariableDeclarator) => void;
WhileStatement?: (node: ESTree.WhileStatement) => void;
WithStatement?: (node: ESTree.WithStatement) => void;
YieldExpression?: (node: ESTree.YieldExpression) => void;
}

interface RuleListener extends NodeListener {
onCodePathStart?(codePath: CodePath, node: ESTree.Node): void;
Expand All @@ -263,6 +332,7 @@ export namespace Rule {
| ((segment: CodePathSegment, node: ESTree.Node) => void)
| ((fromSegment: CodePathSegment, toSegment: CodePathSegment, node: ESTree.Node) => void)
| ((node: ESTree.Node) => void)
| NodeListener[keyof NodeListener]
| undefined;
}

Expand Down