rjmurillo / EffectiveCSharp.Analyzers

Many of the recommendations in the book Effective C#: 50 Specific Ways to Improve Your C# can be validated by Roslyn-based analyzers and code fixes.
MIT License
2 stars 1 forks source link

Correct false positive with ECS0009 on string.Concat on string + int #47

Closed rjmurillo closed 2 months ago

rjmurillo commented 2 months ago

Fixes #45

public class C {
  public void M() {
    var i = 0;
    var name = "Foo" + i;  // This is lowered to string name = string.Concat("Foo", i.ToString());
  }
}

Two additional checks added to the analyzer:

  1. Analysis of the SyntaxKind.AddExpression and the BinaryExpressionSyntax to look for concat. This is more for defense in depth to stop additional special cased analysis that was there previously.
  2. Update to OperationKind.Conversion. When an IConversionOperation is analyzed, we need to consider a few things: there are safe operations where the compiler lowers the code to an optimal condition to avoid boxing, boxing depends on surrounding context, and last there are specific types that are special cased.
codacy-production[bot] commented 2 months ago

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
:white_check_mark: +0.53% (target: -1.00%) :white_check_mark: 96.55%
Coverage variation details | | Coverable lines | Covered lines | Coverage | | ------------- | ------------- | ------------- | ------------- | | Common ancestor commit (a8021f8a2e7cbdc4a16535c4e4cd2b646799d302) | 515 | 424 | 82.33% | | | Head commit (737d39a6163a4215b8cbd200512c16fea9733dae) | 531 (+16) | 440 (+16) | 82.86% (**+0.53%**) | **Coverage variation** is the difference between the coverage for the head and common ancestor commits of the pull request branch: ` - `
Diff coverage details | | Coverable lines | Covered lines | Diff coverage | | ------------- | ------------- | ------------- | ------------- | | Pull request (#47) | 29 | 28 | **96.55%** | **Diff coverage** is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: `/ * 100%`

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more