-
Notifications
You must be signed in to change notification settings - Fork 511
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 SA1308CodeFixProvider creating empty identifier and add regression test #2338
Conversation
- Checking token.ValueText.Length <= 2 beforehand implies the text is not null or empty - Do not offer a code fix when a string consists entirely of multiple prefixes
Codecov Report
@@ Coverage Diff @@
## master #2338 +/- ##
==========================================
+ Coverage 96.79% 96.81% +0.02%
==========================================
Files 598 732 +134
Lines 84340 97117 +12777
Branches 3211 3834 +623
==========================================
+ Hits 81639 94028 +12389
- Misses 1785 2176 +391
+ Partials 916 913 -3
Continue to review full report at Codecov.
|
if (!string.IsNullOrEmpty(token.ValueText)) | ||
if (numberOfCharsToRemove == 0) | ||
{ | ||
continue; |
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 noticed from the code coverage report that this continue
statement isn't hit by the current tests. Is it possible to reach this if
statement and still have numberOfCharsToRemove
be 0?
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.
@sharwell I think I added this to maintain previous behavior if the name was 1 char, or 2 chars and not one of the prefixes; without this check, we would no longer hit the continue
below where we had before. However, if either of those were the case, then clearly the analyzer wouldn't have reported this in the first place. I'll remove this if
block.
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.
Awesome. BTW, I asked because I was using this pull request to demonstrate to someone how code coverage tools can be used to ask more specific questions during code review.
Fix SA1308CodeFixProvider creating empty identifier and add regression test
Had to close #2337 because I submitted from the wrong branch. Sorry about that.
SA1308CodeFixProvider
has a branch to prevent it from creating an empty identifier if the variable name consists solely of the offending prefix. However, if it consists only of multiple prefixes, e.g.m_s_t_
, then it will try to rename the variable to the empty string.This PR changes the logic to be more flexible, and adds regression tests. It also converts some existing tests for that analyzer to use
Theory
instead ofFact
.