-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[unbound-method] support an allowlist #2951
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 problem here is that the rule is actually right for some cases - Which is the inherent danger of an allowlist like this - it's contextless and can easily cause footguns. Don't get me wrong - I 100% understand that it's clunky and cumbersome to manually disable the rule around the place, but it's just a really hard problem to solve, and is an inherent problem with the dynamic nature of JS. Do we need a solution? Yes. Do I have a good solution? Nope. Perhaps a better solution is to fork this rule into something like Unsure... Just a random thought. |
I had the exact same though minutes after hitting "submit" 😅 Do you have any documentation or examples on how we could easily hook into the type info for our rules over at |
For that idea - it could actually be as simple as forking the rule and adding some additional checks using ESTree AST to look for jest patterns and then just prevent the eg: if (isExpectToThrow(node) || isExpectNotToThrow(node)) {
checkUnboundMethod();
} else {
return;
} |
So I've started forking the rule, but having trouble forking the tests - would you mind having a look? Initially I got That then gave me Finally, I'm now having a couple of tests fail 😬 So far the majority of our setup seems to be the same, except for Leara. It could be because of version differences, but I'd have thought that'd make for some pretty flakey tests if patch difference versions in packages like |
This comment has been minimized.
This comment has been minimized.
You want to use They're separate so that people don't get our stuff forced on them.
I would have thought that if you just fork the rule and make no changes, it should all "just work". |
As would I, but sadly no dice so far - I'll look into using |
(Slightly surprised my PR actually closed this issue - I'm guessing probably because I was the author of both) @bradzacher I've merged the new rule in |
Repro
Expected Result
No ESLint Error.
Actual Result
An ESLint Error.
Additional Info
Versions
@typescript-eslint/eslint-plugin
4.14.0
@typescript-eslint/parser
4.14.0
TypeScript
4.1.2
ESLint
7.15.0
node
14.2.2
I know this is technically a duplicate of #1776, but that's locked so I can't comment on that and I think this would be a useful addition that I'm happy to implement myself.
@bradzacher in response to your comment on the original issue:
Disabling the rule completely for test files means its completely disabled, whereas the allowlist lets us keep it enabled - we can also use it with overrides to target specific files (i.e just our test files).
While it's true we can use disable comments, they tend to stick out and for this rule in particular it just results in a lot of eslint-disable comments since its for a common testing pattern.
Finally, we can give it some nice context with a comment if we're using any config aside from
json
:The text was updated successfully, but these errors were encountered: