Skip to content
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

fix(eslint-plugin): false-positive/negative with array index in no-unnecessary-condition #3805

Merged
merged 3 commits into from Sep 20, 2021

Conversation

ypresto
Copy link
Contributor

@ypresto ypresto commented Aug 28, 2021

This PR fixes several false-positive/negatives in no-unnecessary-condition.

  • False-positive at nullish coalescing after array index access: arr[42]?.foo ?? 0
  • False-negative at arr[42] ?? 0 where arr[42] is always nullish or never.
  • False-negative at arr[0].foo?.bar where foo is not nullable.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @ypresto!

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.

@ypresto ypresto marked this pull request as draft August 28, 2021 20:34
@ypresto ypresto changed the title [no-unnecessary-condition] fix: false-positive with nullish coalescing + optional array index [no-unnecessary-condition] fix: false-positive/negative with array index Aug 28, 2021
@codecov
Copy link

codecov bot commented Aug 28, 2021

Codecov Report

Merging #3805 (caf350e) into master (055add0) will increase coverage by 0.89%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3805      +/-   ##
==========================================
+ Coverage   92.68%   93.57%   +0.89%     
==========================================
  Files         327      147     -180     
  Lines       11351     7865    -3486     
  Branches     3201     2492     -709     
==========================================
- Hits        10521     7360    -3161     
+ Misses        369      161     -208     
+ Partials      461      344     -117     
Flag Coverage Δ
unittest 93.57% <100.00%> (+0.89%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...n/src/rules/indent-new-do-not-use/OffsetStorage.ts 100.00% <100.00%> (ø)
...slint-plugin/src/rules/no-unnecessary-condition.ts 97.19% <100.00%> (+0.01%) ⬆️
...pe-manager/src/definition/CatchClauseDefinition.ts
packages/scope-manager/src/lib/esnext.ts
packages/scope-manager/src/lib/esnext.array.ts
packages/scope-manager/src/lib/esnext.string.ts
packages/scope-manager/src/scope/WithScope.ts
packages/scope-manager/src/lib/lib.ts
packages/scope-manager/src/lib/es2021.weakref.ts
packages/scope-manager/src/scope/BlockScope.ts
... and 168 more

@ypresto ypresto marked this pull request as ready for review August 29, 2021 14:30
@ypresto ypresto changed the title [no-unnecessary-condition] fix: false-positive/negative with array index feat(eslint-plugin): false-positive/negative with array index in no-unnecessary-condition Aug 30, 2021
@ypresto ypresto changed the title feat(eslint-plugin): false-positive/negative with array index in no-unnecessary-condition fix(eslint-plugin): false-positive/negative with array index in no-unnecessary-condition Aug 30, 2021
@bradzacher bradzacher added the bug Something isn't working label Sep 3, 2021
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants