Skip to content

Commit 1fc3e96

Browse files
committed
Merge pull request code-cracker#15 from vmrocha/master
Add documentation for CC0039, CC0042 and CC0043
2 parents 13e315d + a6cdd22 commit 1fc3e96

File tree

7 files changed

+134
-0
lines changed

7 files changed

+134
-0
lines changed

assets/images/CC0039/codefix0.png

31.6 KB
Loading

assets/images/CC0042/codefix0.png

15.8 KB
Loading

assets/images/CC0043/codefix0.png

18.9 KB
Loading

diagnostics.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ tagline: All our diagnostics, ordered by category
2727
|[CC0023](/diagnostics/CC0023.html)|SealedAttributeAnalyzer|
2828
|[CC0025](/diagnostics/CC0025.html)|EmptyFinalizerAnalyzer|
2929
|[CC0030](/diagnostics/CC0030.html)|MakeLocalVariableConstWhenItIsPossibleAnalyzer|
30+
|[CC0039](/diagnostics/CC0039.html)|StringBuilderInLoopAnalyzer|
3031

3132
## Style
3233

@@ -61,3 +62,9 @@ tagline: All our diagnostics, ordered by category
6162
|[CC0052](/diagnostics/CC0052.html)|ReadonlyFieldAnalyzer|
6263
|[CC0057](/diagnostics/CC0057.html)|UnusedParametersAnalyzer|
6364
|[CC0089](/diagnostics/CC0089.html)|RemoveRedundantElseClauseAnalyzer|
65+
66+
## Refactoring
67+
68+
|Diagnostic Id| Name |
69+
|[CC0042](/diagnostics/CC0042.html)|InvertForAnalyzer|
70+
|[CC0043](/diagnostics/CC0043.html)|ChangeAnyToAllAnalyzer|

diagnostics/CC0039.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
layout: page
3+
title: CC0039
4+
tagline: StringBuilderInLoopAnalyzer
5+
---
6+
7+
|TypeName|StringBuilderInLoopAnalyzer |
8+
|Check Id | CC0039 |
9+
|Category | Performance |
10+
|Severity | Warning |
11+
12+
# Cause
13+
14+
Do not concatenate a string on a loop. It will alocate a lot of memory. Use a StringBuilder instead. It will will require less allocation, less garbage collector work, less CPU cycles, and less overall time.
15+
16+
# Example
17+
18+
{% highlight csharp %}
19+
var values = "";
20+
foreach (var item in Enum.GetValues(typeof(LoaderOptimization)))
21+
{
22+
values += item.ToString();
23+
}
24+
{% endhighlight %}
25+
26+
# Code fix
27+
28+
A code fix will be presented to you that will transform the code, it will use StringBuilder to concatenate the string.
29+
30+
{% highlight csharp %}
31+
var values = "";
32+
var builder = new StringBuilder();
33+
builder.Append(values);
34+
foreach (var item in Enum.GetValues(typeof(LoaderOptimization)))
35+
{
36+
builder.Append(item.ToString());
37+
}
38+
values = builder.ToString();
39+
{% endhighlight %}
40+
41+
![Code fix]({{ BASE_PATH }}/assets/images/CC0039/codefix0.png)
42+
43+
# Related rules
44+
45+
TBD
46+
47+
# See also
48+
49+
TBD

diagnostics/CC0042.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
layout: page
3+
title: CC0042
4+
tagline: InvertForAnalyzer
5+
---
6+
7+
|TypeName|InvertForAnalyzer |
8+
|Check Id | CC0042 |
9+
|Category | Refactoring |
10+
|Severity | Hidden |
11+
12+
# Cause
13+
14+
Inverts the sequence of a for loop.
15+
16+
# Example
17+
18+
{% highlight csharp %}
19+
for (var i = 0; i < 10; i++) { }
20+
{% endhighlight %}
21+
22+
# Code fix
23+
24+
A code fix will be presented to you that will transform the code, it will invert the sequence of the for loop.
25+
26+
{% highlight csharp %}
27+
for (var i = 10 - 1; i >= 0; i--) { }
28+
{% endhighlight %}
29+
30+
![Code fix]({{ BASE_PATH }}/assets/images/CC0042/codefix0.png)
31+
32+
# Related rules
33+
34+
TBD
35+
36+
# See also
37+
38+
TBD

diagnostics/CC0043.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
layout: page
3+
title: CC0043
4+
tagline: ChangeAnyToAllAnalyzer
5+
---
6+
7+
|TypeName|ChangeAnyToAllAnalyzer |
8+
|Check Id | CC0043 |
9+
|Category | Refactoring |
10+
|Severity | Hidden |
11+
12+
# Cause
13+
14+
Changes Any to All or All to Any.
15+
16+
# Example
17+
18+
{% highlight csharp %}
19+
var ints = new[] { 1, 2 }.AsQueryable();
20+
var query = !ints.Any(i => i > 0);
21+
{% endhighlight %}
22+
23+
# Code fix
24+
25+
A code fix will be presented to you that will transform the code, it will change Any to All or All to Any.
26+
27+
{% highlight csharp %}
28+
var ints = new[] { 1, 2 }.AsQueryable();
29+
var query = ints.All(i => i <= 0);
30+
{% endhighlight %}
31+
32+
![Code fix]({{ BASE_PATH }}/assets/images/CC0043/codefix0.png)
33+
34+
# Related rules
35+
36+
TBD
37+
38+
# See also
39+
40+
TBD

0 commit comments

Comments
 (0)