-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [strict-boolean-expressions] check array predicate functions' return statements #10106
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): [strict-boolean-expressions] check array predicate functions' return statements #10106
Conversation
Thanks for the PR, @ronami! 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. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
View your CI Pipeline Execution ↗ for commit f17a05c.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #10106 +/- ##
==========================================
+ Coverage 86.84% 86.86% +0.02%
==========================================
Files 445 445
Lines 15427 15455 +28
Branches 4497 4507 +10
==========================================
+ Hits 13397 13425 +28
Misses 1675 1675
Partials 355 355
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
Nice! One discussion on implicit undefined return, and some requests around testing. Direction seems great to me! 🚀
x.filter(t => { | ||
return t ? 1 : 0; | ||
}); | ||
x.filter(t => !t); |
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.
[Testing] We generally try to stick to one thing under test for each test case. For this one, it looks like two things are being tested:
- That the
allowNullableBoolean
option still works... - ...and that general logic holds true for all three variations of something passed to
.filter
I don't think the latter is necessary. We can trim the tests down a bit:
x.filter(t => { | |
return t ? 1 : 0; | |
}); | |
x.filter(t => !t); |
Here and the other ones with several variations of the same, such as allowNullableString: true
.
packages/eslint-plugin/tests/rules/strict-boolean-expressions.test.ts
Outdated
Show resolved
Hide resolved
Co-authored-by: Kirk Waiblinger <kirk.waiblinger@gmail.com>
No problem, I appreciate your assistance with the PR, it's been very helpful 👍 |
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.
home stretch!
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.
I think we're there! Great work on this! I'm excited to get to use this feature ❤️
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.
So thorough, love it! 🚀
##### [v8.19.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8190-2024-12-30) ##### 🚀 Features - **eslint-plugin:** \[strict-boolean-expressions] check array predicate functions' return statements ([#10106](typescript-eslint/typescript-eslint#10106)) ##### 🩹 Fixes - **eslint-plugin:** \[member-ordering] ignore method overloading ([#10536](typescript-eslint/typescript-eslint#10536)) - **eslint-plugin:** \[consistent-indexed-object-style] don't report on indirect circular references ([#10537](typescript-eslint/typescript-eslint#10537)) - **eslint-plugin:** \[array-type] autofix with conditional types needs parentheses ([#10522](typescript-eslint/typescript-eslint#10522)) - **eslint-plugin:** add getConstraintInfo to handle generic constraints better ([#10496](typescript-eslint/typescript-eslint#10496)) ##### ❤️ Thank You - Karl Werner - Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger) - Ronen Amiel - YeonJuan [@yeonjuan](https://github.com/yeonjuan) You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
| datasource | package | from | to | | ---------- | -------------------------------- | ------ | ------ | | npm | @typescript-eslint/eslint-plugin | 8.18.2 | 8.19.0 | | npm | @typescript-eslint/parser | 8.18.2 | 8.19.0 | ## [v8.19.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8190-2024-12-30) ##### 🚀 Features - **eslint-plugin:** \[strict-boolean-expressions] check array predicate functions' return statements ([#10106](typescript-eslint/typescript-eslint#10106)) ##### 🩹 Fixes - **eslint-plugin:** \[member-ordering] ignore method overloading ([#10536](typescript-eslint/typescript-eslint#10536)) - **eslint-plugin:** \[consistent-indexed-object-style] don't report on indirect circular references ([#10537](typescript-eslint/typescript-eslint#10537)) - **eslint-plugin:** \[array-type] autofix with conditional types needs parentheses ([#10522](typescript-eslint/typescript-eslint#10522)) - **eslint-plugin:** add getConstraintInfo to handle generic constraints better ([#10496](typescript-eslint/typescript-eslint#10496)) ##### ❤️ Thank You - Karl Werner - Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger) - Ronen Amiel - YeonJuan [@yeonjuan](https://github.com/yeonjuan) You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
PR Checklist
Overview
This PR addresses #8016 and updates
strict-boolean-expressions
to check for array predicate return statements.Two things to note:
Doesn't handle implicit returns
I didn't handle implicit return types from array predicates since I'm not sure if the rule should cover this:
Please let me know if you think it should.
Somewhat of a breaking change
This is a breaking change, though the issue itself isn't marked as one, and according to the docs:
Alternatively, I can put this behind a flag, which can be removed in a later version.