-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: Support CodePath rule listener methods #6993
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
Comments
The reason we never added these is two fold:
See existing Pr: #2930 Because the usecase is so very rare and it's a difficult problem to solve - we've just opted to not solve it yet. If you can think of a way to add the definitions without harming the DevX of node selectors then I'm more than happy to have them added to the types! I must really stress that it's important that we do not impact the DevX of selectors - there are thousands of node selectors written with our types - so we mustn't make them less safe, nor must we make them harder to use just to add types for this fraction of a fraction of a percent case. |
Just chiming in here to say that code paths are pretty nice to have. Code paths are used in a few official ESLint rules, namely This functionality is also used in other rules that have to do with switch statements. For example, look at the source code for the Of course, code paths are not just useful for rules about switch statements, but for other situations too. They are nice because we can detect certain kinds of situations without having the rule to be type aware, which obviously greatly hinders a rule's performance impact. As a first baby step, I think that this project should export a import type { TSESTree } from "@typescript-eslint/utils";
export const myRule = createRule<Options, MessageIds>({
create(context) {
return {
// We must type assert `never` to `CodePath` because using the nodes
// inside of a code path can cause problems with TypeScript.
onCodePathStart(codePath as TSESTree.CodePath) {}
};
}, |
To clarify - it's not that we don't think it's useful - there are some rare usecase for them and they can help solve some problems or simplify others! Instead what were saying is that unfortunately TS isn't designed to support this usecase well - you can't define an index signature that has one value but also define members with a different, incompatible value. So in order for us to add the signatures we'd have to break all the existing code that relies on the index signature - which is obviously an intractable solution - breaking 99.99% of cases to support 0.01% isn't good! I'd welcome someone adding the codepath types - but we just can't add the signatures. |
few months ago i tried to add it, but i got stuck with exactly same issue, see #6679 |
@armano2 What about a PR for just the interfaces? |
@JoshuaKGoldberg I don't think this issue should be closed actually, since I only added the |
We can't add the listener method definitions to the types without big changes in how TS works. So unless TS adds a way for us to support both without degrading the experience of esquery selectors - we will have to close this as "fixed as best as we can for now". |
Before You File a Proposal Please Confirm You Have Done The Following...
Relevant Package
utils
My proposal is suitable for this project
Description
Rules created using
createRule
currently don't have TypeScript support for the Code Path Analysis events. This would be great to add since they still work fine, its just that TypeScript complains.I'd like to be able to use
onCodePathStart
,onCodePathEnd
,onCodePathSegmentStart
,onCodePathSegmentEnd
, andonCodePathSegmentLoop
as well as use an interface for CodePath and CodePathSegment,Fail
Pass
Additional Info
No response
The text was updated successfully, but these errors were encountered: