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
feat(eslint-plugin): [no-unneccessary-conditions] add option to check array predicate callbacks #1206
Conversation
Thanks for the PR, @Retsam! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
dd3f010
to
b27d7e3
Compare
b27d7e3
to
6024964
Compare
I improved the checking for whether the left-hand-side of (e.g.) |
6024964
to
4e9531d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM - RC on the comment and merge conflicts
Codecov Report
@@ Coverage Diff @@
## master #1206 +/- ##
==========================================
+ Coverage 94.58% 94.58% +<.01%
==========================================
Files 140 140
Lines 6034 6057 +23
Branches 1712 1723 +11
==========================================
+ Hits 5707 5729 +22
Misses 181 181
- Partials 146 147 +1
|
For backwards compatibility purposes, this is behind an option that defaults to false. I think it'd be good to change that for v3, either to have the option default to true, or else to remove the option and just have this be non-configurable behavior. Any thoughts on which would be better here? I think I'm leaning towards non-configurable: this seems pretty unopinionated and shouldn't impose too much runtime cost to check, but maybe letting it be an option is more in-line with eslint's configuration philosophy? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks for this
Implements #1038 for no-unnecessary-condition.
The flow is:
filter
,find
,some
, andevery
are being called, via syntax analysisx => something
), or if the body of the function is a single return statement (x => { return something; }
), reuse the existingcheckNode
on the returned value. (This way the linter can just underlinesomething
rather than the whole callback)The function is behind an option flag, default off. When the next major version rolls around, I think it could default to true (or maybe even just remove the flag).
Things to ideally resolve:
lastIndexOf
property.I think it's possible to fix the above, but it's getting deeper into the compiler API that I've been able to figure out.