-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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-unnec-cond] check optional chaining #1315
feat(eslint-plugin): [no-unnec-cond] check optional chaining #1315
Conversation
Thanks for the PR, @jridgewell! 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. |
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.
Thanks for the PR.
I think that this functionality would be better suited within the no-unnecessary-condition
rule.
Would you please be able to move it in there?
e74bea4
to
382164b
Compare
Done. |
382164b
to
07ad7a9
Compare
Updated the docs to get the tests to pass. |
Codecov Report
@@ Coverage Diff @@
## master #1315 +/- ##
==========================================
+ Coverage 93.92% 93.94% +0.01%
==========================================
Files 131 131
Lines 5847 5860 +13
Branches 1657 1661 +4
==========================================
+ Hits 5492 5505 +13
Misses 188 188
Partials 167 167
|
This adds type checking around the the new optional-chaining feature. With this, it becomes invalid to start an optional chain when the base value is known to be not-nullish. ```js // Good declare const foo: string | null; declare const bar: null : (() => {}); foo?.length; foo?.slice(); bar?.(); // Bad declare const baz: string; declare const qux: (() => {}); baz?.length; baz?.slice(); baz.slice?.(); qux?.(); ```
07ad7a9
to
9d9dee1
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.
LGTM - thanks for this
Nice work using nullThrows
, I hadn't documented it yet.
Please note: the release notes use the pull request title, so I updated my config to include |
Sorry, ESLint semi enforces commit message length when doing squash merges. It's also nice to keep things short enough (72 characters) so that the commit history on github doesn't truncate the message. It's one of the pains of using semantic commit messages; it takes a lot of the character budget to do |
No worries, we have the same issue ourselves :-) The way we solve it is when squash-merging a pull request, we edit the body of the commit message to make it match again |
This adds type checking around the the new optional-chaining feature. With this, it becomes invalid to start an optional chain when the base value is known to be not-nullish.