Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(eslint-plugin): [no-unnecessary-condition] improve optional chain handling#2111

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bradzacher merged 4 commits intotypescript-eslint:masterfromyeonjuan:unn-cond-false-negative
May 30, 2020
Merged

Conversation

yeonjuan
Copy link
Contributor

@yeonjuanyeonjuan commentedMay 26, 2020
edited
Loading

Hi, 😀
IMO, it's a false negative inno-unnecessary-condition

Repro

{"rules": {"@typescript-eslint/no-unnecessary-condition": ["error"]  }}
// case 1declareconstx:{a?:{b:string}};x?.a?.b;// case 2declareconstx:{a:{b?:{c:string}}};x.a?.b?.c;// case 3letx:{a?:string};x?.a;

Expected Result

// case 1declareconstx:{a?:{b:string}};x?.a?.b;^^// lint error// case 2declareconstx:{a:{b?:{c:string}}};x.a?.b?.c;^^// lint error// case 3letx:{a?:string};x?.a;^^// lint error

Actual Result

// case 1declareconstx:{a?:{b:string}};x?.a?.b;// no error// case 2declareconstx:{a:{b?:{c:string}}};x.a?.b?.c;// no error// case 3letx:{a?:string};x?.a;// no error

Additional Info

It seems "no-unnecessary-condition" checks whether the whole optional member expression type is nullable or not. so it just passed when the last member in the optional member expression is nullable.

I changed the target node to check. Am I miss something? 🤔

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@yeonjuan!

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 onhttps://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day.

@yeonjuanyeonjuan changed the titlefix(eslint-plugin): [no-unnecessary-condition] handling nullable targetfix(eslint-plugin): [no-unnecessary-condition] change nullable target to checkMay 26, 2020
@codecov
Copy link

codecovbot commentedMay 26, 2020
edited
Loading

Codecov Report

Merging#2111 intomaster willincrease coverage by0.00%.
The diff coverage is100.00%.

@@           Coverage Diff           @@##           master    #2111   +/-   ##=======================================  Coverage   93.42%   93.42%           =======================================  Files         171      171             Lines        7755     7757    +2       Branches     2215     2216    +1     =======================================+ Hits         7245     7247    +2  Misses        244      244             Partials      266      266
FlagCoverage Δ
#unittest93.42% <100.00%> (+<0.01%)⬆️
Impacted FilesCoverage Δ
...slint-plugin/src/rules/no-unnecessary-condition.ts97.01% <100.00%> (+0.04%)⬆️

@bradzacherbradzacher added the bugSomething isn't working labelMay 26, 2020
@bradzacher
Copy link
Member

Unless I'm mistaken, I believe this is addressing#1977. If I'm right, please add it to the OP 😄

@yeonjuan
Copy link
ContributorAuthor

yeonjuan commentedMay 27, 2020
edited
Loading

@bradzacher
Well, I found this issue while trying to solve#1977, but it's quite a different issue.
#1977 occurs when a node's nullable type is originated from its parent nullable, but this issue occurs when theOptionalMemberExpression's last member is nullable type. (In my thought)

so this pr can't fix#1977

letx:{a:{b:string}}|null;x?.a?.b;^^// a's nullable type is originated from x's type, so this case belong #1977letx:{a?:string};x?.a;// no error^^// IMO, we should check type of "x" not "a"
bradzacher reacted with thumbs up emoji

Copy link
Member

@bradzacherbradzacher left a 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!

@bradzacherbradzacher changed the titlefix(eslint-plugin): [no-unnecessary-condition] change nullable target to checkfix(eslint-plugin): [no-unnecessary-condition] improve optional chain handlingMay 30, 2020
@bradzacherbradzacher merged commit9ee399b intotypescript-eslint:masterMay 30, 2020
@yeonjuanyeonjuan deleted the unn-cond-false-negative branchMay 31, 2020 02:38
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsJul 1, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@bradzacherbradzacherbradzacher approved these changes

Assignees
No one assigned
Labels
bugSomething isn't working
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@yeonjuan@bradzacher

[8]ページ先頭

©2009-2025 Movatter.jp