denoland / deno_lint

Blazing fast linter for JavaScript and TypeScript written in Rust
https://lint.deno.land/
MIT License
1.53k stars 172 forks source link

Rule against redundant closures #1169

Closed not-my-profile closed 1 year ago

not-my-profile commented 1 year ago

E.g. invalid:

xs.map(x => foo(x))

Valid:

xs.map(foo)
magurotuna commented 1 year ago

This seems more difficult for me than it seems to be, because for example the following two examples behave differently:

['10', '10', '10'].map(parseInt);
// [ 10, NaN, 2 ]
['10', '10', '10'].map((x) => parseInt(x));
// [ 10, 10, 10 ]

I'd say 99.9% of the cases what people want to do is the second one, not first one. Also the linter should not suggest the change that affects the code behavior in runtime. So the linter would need to be smart enough to consider the second example to be not redundant - this sounds really hard.

not-my-profile commented 1 year ago

Ah, very good call! (explanation for others wondering what's happening).

You're right, doing this reliably would require type awareness, which is currently blocked as explained in #1138 ... so I'm closing this for now.