-
-
Notifications
You must be signed in to change notification settings - Fork 91
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
False-positive for "error" causing issues in prefer-await-to-callbacks rule #212
Comments
Both of my example show using standard array methods like But I thin kit's fine, because the callback signature is different (callback is 3rd argument) |
I have similar scenario with a false positive: export const formatErrors = errors => errors.map((error) => {
...
} There is no promise involved in this piece of code, yet |
Thanks, would love any kind of PR support on this if you have time @pkuczynski or maybe @iamdarshshah ? |
I agree with @jturel, that checking for a param name is a poor linting. However, I am flooded with work so I would not be able to come up with PR anytime soon :( |
@xjamundx Sure, I can give it a try! I'll need your help alongside tho 😄
@pkuczynski IMO - (Just keeping your use-case in mind) It would be great to first check whether the piece of code involves a Promise or not. And on the basis of that, it will report the error if that's the promise otherwise it won't. Also, @xjamundx can you please provide the list of things that needs to be taken care of while thinking of any implementation? This is what we need to implement (correct me if I'm not wrong):
I agree with adding a JSX exception to this rule. But yes, we'll need to add a check for |
We're proposing two exceptions to this rule:
Ideally I'd like to exclude this library which has a similar, but not quite the same function signature as a lot of the normal array methods: https://caolan.github.io/async/v3/docs.html#map so basically these should not warn:
Also the lodash equivalents don't take callbacks
However these should complain
What about this ambiguous use case:
I'm going to say, we'll have a list of approved function/method names and if it's an exact match AND the callback is the only argument then it will not complain. For now I think both of these will have to be errors, unless we can come up with a clever way to exclude them without also missing the
We might be able to determine based on number of arguments, because the lodash versions would all have 2 arguments, but I think the async versions all have 3. Anyway, something to look into.
Now what about JSX? I bet this doesn't come up very often outside of the Any other thoughts/questions? |
Another class of false positive: an action creator using export const gapiClientUnavailable = createAction(
'GAPI_CLIENT_UNAVAILABLE',
error => ({error}),
); Since #202 is merely adding a new variant of the error param name, but does not introduce the overall strategy of using the param name as a heuristic for detecting callbacks, I’ll probably just disable the |
We just published Totally agree for many folks it may make sense to disable the rule as it's more relevant in node.js stacks. |
I know this will come up again, so I will re-open so people can find this issue easily. |
Published this with |
Works as expected in |
see: #202 (comment)
The way that this rule detects a callback function is anything with a function signature of:
The problem is plenty of people would do something like:
Especially in JSX/react land and possibly elsewhere.
I could also see:
This rule is definitely not meant to apply in these scenarios, because these aren't actually the async style callbacks we're worried about, but....is there a better way to differentiate them?
I'd be pretty ok adding a JSX exception to this rule, or just like disable the rule if it doesn't apply to your app. Mostly I had node.js in mind when I made this :D
The text was updated successfully, but these errors were encountered: