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): [prefer-includes] ignore option chaining before indexOfs #3432

Conversation

JoshuaKGoldberg
Copy link
Member

Fixes #3341

I was on the fence of whether to just remove the fixer for ?.indexOf instead, but went with removing it altogether because of the subtle behavior differences:

Original x = undefined x = "" x = "y"
x?.indexOf("y") === -1 false true false
!x?.includes("y") true true false
x?.indexOf("y") !== -1 true false true
x?.includes("y") undefined false true

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @JoshuaKGoldberg!

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.

@codecov
Copy link

codecov bot commented May 23, 2021

Codecov Report

Merging #3432 (7041d15) into master (b814e63) will decrease coverage by 0.00%.
The diff coverage is 92.00%.

@@            Coverage Diff             @@
##           master    #3432      +/-   ##
==========================================
- Coverage   92.66%   92.65%   -0.01%     
==========================================
  Files         324      324              
  Lines       11188    11191       +3     
  Branches     3157     3158       +1     
==========================================
+ Hits        10367    10369       +2     
  Misses        365      365              
- Partials      456      457       +1     
Flag Coverage Δ
unittest 92.65% <92.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
...ackages/eslint-plugin/src/rules/prefer-includes.ts 97.87% <92.00%> (-1.03%) ⬇️

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review May 23, 2021 11:30
@bradzacher bradzacher added the bug Something isn't working label May 24, 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.

Question: Do we want to keep the reporting but remove the fixer only?

I.e. the user has to evaluate and fix the code as required

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label May 28, 2021

return acc;
}, []);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This addOptional wrapper was hiding the test cases from being checked by Prettier... although I could keep it in and remove the output field, it does feel weird to me to auto-generate them this way when the only difference between the two is checking callNode.parent.parent vs. callNode.parent?

Copy link
Member

Choose a reason for hiding this comment

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

this was just my lazy way of covering all the cases 😅

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Jun 1, 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.

LGTM - thanks for fixing this!


return acc;
}, []);
}
Copy link
Member

Choose a reason for hiding this comment

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

this was just my lazy way of covering all the cases 😅

@bradzacher bradzacher merged commit bf0cddb into typescript-eslint:master Jun 6, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 7, 2021
@JoshuaKGoldberg JoshuaKGoldberg deleted the prefer-includes-optional-chaining branch November 17, 2021 07:45
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.

[prefer-includes] Auto-fix incorrect when optional chaining
2 participants