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 SA1308CodeFixProvider creating empty identifier and add regression test #2338

Merged
merged 6 commits into from Jun 20, 2017

Conversation

jamesqo
Copy link
Contributor

@jamesqo jamesqo commented Apr 10, 2017

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 of Fact.

- 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
Copy link

codecov bot commented Apr 10, 2017

Codecov Report

Merging #2338 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
...eCop.Analyzers.Test/NamingRules/SA1308UnitTests.cs 100% <100%> (ø) ⬆️
...ers.CodeFixes/NamingRules/SA1308CodeFixProvider.cs 100% <100%> (+5.55%) ⬆️
...nalyzers.Test/Helpers/DiagnosticVerifier.Helper.cs 80.46% <0%> (-9.27%) ⬇️
...leCop.Analyzers.Test/Helpers/MetadataReferences.cs 94.11% <0%> (-5.89%) ⬇️
...nalyzers/SpecialRules/SA0002InvalidSettingsFile.cs 95.65% <0%> (-4.35%) ⬇️
...Analyzers/Settings/ObjectModel/StyleCopSettings.cs 98.07% <0%> (-1.93%) ⬇️
...zers/StyleCop.Analyzers/Settings/SettingsHelper.cs 76.13% <0%> (-1.25%) ⬇️
...zers/Settings/ObjectModel/DocumentationSettings.cs 99.2% <0%> (-0.8%) ⬇️
...ReadabilityRules/SA1115ParameterMustFollowComma.cs 93.22% <0%> (-0.24%) ⬇️
...SA1110OpeningParenthesisMustBeOnDeclarationLine.cs 75.22% <0%> (-0.02%) ⬇️
... and 221 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 841c0ac...b7e8a57. Read the comment docs.

if (!string.IsNullOrEmpty(token.ValueText))
if (numberOfCharsToRemove == 0)
{
continue;
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

@sharwell sharwell added this to the 1.1.0 Beta 4 milestone Jun 20, 2017
@sharwell sharwell self-assigned this Jun 20, 2017
@sharwell sharwell merged commit b7e8a57 into DotNetAnalyzers:master Jun 20, 2017
sharwell added a commit that referenced this pull request Jun 20, 2017
Fix SA1308CodeFixProvider creating empty identifier and add regression test
@sharwell sharwell added the fixed label Jun 20, 2017
@jamesqo jamesqo deleted the sa1308 branch June 20, 2017 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants