-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9f6edc4
commit d338d0d
Showing
11 changed files
with
237 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,7 +294,6 @@ | |
"S6797", | ||
"S6798", | ||
"S6800", | ||
"S6802", | ||
"S6803" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...narAnalyzer.UnitTest/TestCases/AvoidLambdaExpressionInLoopsInBlazor.LoopsWithNoBody.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
@* https://github.com/SonarSource/sonar-dotnet/issues/8394 *@ | ||
|
||
@foreach (var item in Buttons.Where(x => x.Id == "idToFind")) | ||
if (item.Id == "idToFind") | ||
{ | ||
<button @onclick="(e) => Reset(e)">Reset #3</button> @* FN *@ | ||
} | ||
|
||
@for (int i = 0; i < Buttons.Count; i++) | ||
@if (i % 2 == 0) | ||
{ | ||
var buttonNumber = i; | ||
<button @onclick="@(e => DoAction(e, Buttons[buttonNumber]))"> @* FN *@ | ||
Button #@buttonNumber | ||
</button> | ||
} | ||
|
||
@{ | ||
var j = 0; | ||
while (j < 5) | ||
if (j % 2 == 0) | ||
{ | ||
j += 2; | ||
<button @onclick="(e) => Reset(e)"> @* FN *@ | ||
Reset @j | ||
</button> | ||
j += 2; | ||
} | ||
|
||
do | ||
if (j % 2 == 0) | ||
{ | ||
<button @onclick="(e) => Reset(e)"> @* FN *@ | ||
Reset @j | ||
</button> | ||
j += 2; | ||
} | ||
while (j < 10); | ||
} | ||
|
||
@foreach (var item in Buttons.Where(x => x.Id == "idToFind")) | ||
@if (item.Id == "idToFind") | ||
{ | ||
<button @onclick="(e) => Reset(e)">Reset #3</button> @* FN *@ | ||
} | ||
else if (item.Id == "idToFind") | ||
{ | ||
<button @onclick="(e) => Reset(e)">Reset #3</button> @* FN *@ | ||
} | ||
else | ||
{ | ||
<button @onclick="(e) => Reset(e)">Reset #3</button> @* FN *@ | ||
} | ||
|
||
@foreach (var item in Buttons.Where(x => x.Id == "idToFind")) | ||
@if (true) | ||
@if (item.Id == "idToFind") | ||
{ | ||
<button @onclick="(e) => Reset(e)">Reset #3</button> @* FN *@ | ||
} | ||
|
||
@foreach (var item in Buttons.Where(x => x.Id == "idToFind")) | ||
@switch(item.Id) | ||
{ | ||
case "idToFind": | ||
<button @onclick="(e) => Reset(e)">Reset #3</button> @* FN *@ | ||
break; | ||
default: | ||
{ | ||
<button @onclick="(e) => Reset(e)">Reset #4</button> @* FN *@ | ||
break; | ||
} | ||
} | ||
|
||
@foreach (var button in Buttons) | ||
{ | ||
{ | ||
<button @key="button.Id" @onclick="(e) => button.Action(e)"> @* Noncompliant, there is a direct block for the loop *@ | ||
Button #@button.Id | ||
</button> | ||
} | ||
} | ||
|
||
@code { | ||
private List<Button> Buttons { get; } = new(); | ||
|
||
private void DoAction(MouseEventArgs e, Button button) { } | ||
|
||
private class Button | ||
{ | ||
public string? Id { get; } = Guid.NewGuid().ToString(); | ||
public Action<MouseEventArgs> Action { get; set; } = e => { }; | ||
} | ||
|
||
private void Reset(MouseEventArgs mouseEventArgs) | ||
{ | ||
foreach (var button in Buttons) | ||
{ | ||
button.Action = e => { }; // Compliant | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><!-- Generated by Sonar --> | ||
<profile> | ||
<name>blazor_rules</name> | ||
<language>cs</language> | ||
<rules> | ||
<rule> | ||
<repositoryKey>csharpsquid</repositoryKey> | ||
<key>S6797</key> | ||
<priority>MAJOR</priority> | ||
</rule> | ||
<rule> | ||
<repositoryKey>csharpsquid</repositoryKey> | ||
<key>S6798</key> | ||
<priority>MAJOR</priority> | ||
</rule> | ||
<rule> | ||
<repositoryKey>csharpsquid</repositoryKey> | ||
<key>S6800</key> | ||
<priority>MAJOR</priority> | ||
</rule> | ||
<rule> | ||
<repositoryKey>csharpsquid</repositoryKey> | ||
<key>S6802</key> | ||
<priority>MAJOR</priority> | ||
</rule> | ||
<rule> | ||
<repositoryKey>csharpsquid</repositoryKey> | ||
<key>S6803</key> | ||
<priority>MAJOR</priority> | ||
</rule> | ||
</rules> | ||
</profile> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters