-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Change Request: Update RuleVisitor interface #134
Comments
The problem with I poked around a bit in
Mismatch! As I understand it, |
I think it's Apart from that it isn't clear to me how a Visitor would work if its properties aren't functions. Currently ESLint uses property keys of a Visitor object as selectors and property values as listeners. The listeners are called at some point: const ruleListenerReturn = ruleListener(...listenerArgs); So I was under the impression that the expectation was for a Visitor to be an object with callable functions as property values. Are you planning to change the way Visitors work? |
That's correct. So for
That's correct. The |
It looks like you're both in the mapped type camp, so put together a PR here: |
Which packages would you like to change?
@eslint/compat
@eslint/config-array
@eslint/core
@eslint/migrate-config
@eslint/object-schema
@eslint/plugin-kit
What problem do you want to solve?
The
RuleVisitor
interface is currently defined as follows:However, this is causing problems when trying to extend
RuleVisitor
understrict
TypeScript mode, as seen in these PRs:The errors take the form of the following:
What do you think is the correct solution?
The problem is that the method defined in
RuleVisitor
is not optional.I can see a few different options:
RuleVisitor
and leave essentially a blank interface:export interface RuleVisitor { /** * Called for each node in the AST or at specific times during the traversal. */ - [key: string]: (...args: any[]) => void; }
That would give consumers something to extend from so that it logically looks like there's some relationship between the core types and consumer types. I'm not sure it's valuable.
Defining all methods to be optional also seems to make
RuleVisitor
mostly useless.RuleVisitor
interface completely. Because we don't know what the visitor will look like for any particular language, maybe it's a bad idea to try and enforce anything in particular. We could just define theRuleDefinitionTypeOptions#Visitor
asObject
, which would allow any non-primitive type to be used, and then we don't needRuleVisitor
at all:I think this is my favorite approach, but I'd like some insights from @JoshuaKGoldberg and @fasttime on all of the options and their ramifications.
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: