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
Add SonarLint exclusion/inclusion IT #6884
Merged
pavel-mikula-sonarsource
merged 30 commits into
feature/SL-exclusions-inclusions
from
mary/add-it
Mar 10, 2023
Merged
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
dd094c0
SonarLint.xml file read base logic and tests
CristianAmbrosini fd51b79
Removing relativeRootFromSonarLintXml and deprecated 'Files' element
CristianAmbrosini bb7b527
Replaced Lazy initialization with null-coalescing assignment operator
CristianAmbrosini db8681f
Removed empty list initializers
CristianAmbrosini 1f43c31
Addressed PR review comments
CristianAmbrosini e306251
Add SonarLintXml unit tests
CristianAmbrosini d35de5d
Replaced tabs with spaces
CristianAmbrosini 56db519
Add test cases
CristianAmbrosini b0bab1c
Bump temporarily UTs ToStringCallCount
CristianAmbrosini 7f3d726
Small merge fix
CristianAmbrosini 1f58ae7
Fix rebase issues 2
CristianAmbrosini c78de16
Fix UTs
CristianAmbrosini c3c3161
IgnoreAttribute for parametrized test.
CristianAmbrosini 08f4e00
Addressed PR comments
CristianAmbrosini 9b8cb0b
Rebase UTs fix
CristianAmbrosini 00b4a64
Second round of comments
CristianAmbrosini 0a0e8a9
Last UT fix (revert to previous values)
CristianAmbrosini bfb582b
Migrated ShouldAnalyzeFile test case to ShouldAnalyzeTree
CristianAmbrosini ec95a4b
Third wave of comments
CristianAmbrosini 3282762
Add new test project
mary-georgiou-sonarsource 1697c10
set up SonarProjectType to unknown for sonarlint exclusion test
mary-georgiou-sonarsource eb353ff
Add sonarlint exclusions config
mary-georgiou-sonarsource 91a137b
modify project to reflect test
mary-georgiou-sonarsource a05d226
add exclusion for test project
mary-georgiou-sonarsource 40e6cb4
add explanation about SonarUnknownProjectType property
mary-georgiou-sonarsource 520ee39
fix project to test all SL parameters
mary-georgiou-sonarsource 7fe2b29
update expected
mary-georgiou-sonarsource cb07cf7
test all parameters also for test project
mary-georgiou-sonarsource c31ba4f
fix sonarlint xml
mary-georgiou-sonarsource 73f20d3
apply comments
mary-georgiou-sonarsource File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<AnalysisInput> | ||
<Rules> | ||
</Rules> | ||
<Settings> | ||
<Setting> | ||
<Key>sonar.cs.ignoreHeaderComments</Key> | ||
<Value>true</Value> | ||
</Setting> | ||
<Setting> | ||
<Key>sonar.vbnet.ignoreHeaderComments</Key> | ||
<Value>true</Value> | ||
</Setting> | ||
<Setting> | ||
<Key>sonar.inclusions</Key> | ||
<Value>**/Included/*.cs</Value> | ||
</Setting> | ||
<Setting> | ||
<Key>sonar.exclusions</Key> | ||
<Value>**/ExcludedByExclusion.cs</Value> | ||
cristian-ambrosini-sonarsource marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Setting> | ||
<Setting> | ||
<Key>sonar.global.exclusions</Key> | ||
<Value>**/ExcludedByGlobalExclusion.cs</Value> | ||
</Setting> | ||
<Setting> | ||
<Key>sonar.test.exclusions</Key> | ||
<Value>**/ExcludedTest.cs</Value> | ||
</Setting> | ||
</Settings> | ||
</AnalysisInput> |
17 changes: 17 additions & 0 deletions
17
analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json
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,17 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"id": "S2094", | ||
"message": "Remove this empty class, write its code or make it an "interface".", | ||
"location": { | ||
"uri": "sources\SonarLintExclusions\SonarLintExclusions\Included\Included.cs", | ||
"region": { | ||
"startLine": 3, | ||
"startColumn": 18, | ||
"endLine": 3, | ||
"endColumn": 26 | ||
} | ||
} | ||
} | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json
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,9 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"id": "S3990", | ||
"message": "Provide a 'CLSCompliant' attribute for assembly 'SonarLintExclusions'.", | ||
"location": null | ||
} | ||
] | ||
} |
9 changes: 9 additions & 0 deletions
9
analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3992.json
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,9 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"id": "S3992", | ||
"message": "Provide a 'ComVisible' attribute for assembly 'SonarLintExclusions'.", | ||
"location": null | ||
} | ||
] | ||
} |
17 changes: 17 additions & 0 deletions
17
analyzers/its/expected/SonarLintExclusions/SonarLintExclusionsTest--net7.0-S2699.json
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,17 @@ | ||
{ | ||
"issues": [ | ||
{ | ||
"id": "S2699", | ||
"message": "Add at least one assertion to this test case.", | ||
"location": { | ||
"uri": "sources\SonarLintExclusions\SonarLintExclusionsTest\IncludedTest\IncludedTest.cs", | ||
"region": { | ||
"startLine": 8, | ||
"startColumn": 21, | ||
"endLine": 8, | ||
"endColumn": 32 | ||
} | ||
} | ||
} | ||
] | ||
} |
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
36 changes: 36 additions & 0 deletions
36
analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln
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,36 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.6.33417.168 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SonarLintExclusions", "SonarLintExclusions\SonarLintExclusions.csproj", "{F5D0F2AC-2BED-42AA-B219-674F970E8400}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SonarLintExclusionsTest", "SonarLintExclusionsTest\SonarLintExclusionsTest.csproj", "{0F14329D-7A71-489B-BB85-2B257A866429}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1CF8B86B-6A00-4E05-931E-F278FCFDF1CF}" | ||
ProjectSection(SolutionItems) = preProject | ||
global.json = global.json | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{F5D0F2AC-2BED-42AA-B219-674F970E8400}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F5D0F2AC-2BED-42AA-B219-674F970E8400}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F5D0F2AC-2BED-42AA-B219-674F970E8400}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F5D0F2AC-2BED-42AA-B219-674F970E8400}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{0F14329D-7A71-489B-BB85-2B257A866429}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0F14329D-7A71-489B-BB85-2B257A866429}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0F14329D-7A71-489B-BB85-2B257A866429}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0F14329D-7A71-489B-BB85-2B257A866429}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {9FA0AE0B-19EB-4F4F-A69E-5AB50EE8240E} | ||
EndGlobalSection | ||
EndGlobal |
4 changes: 4 additions & 0 deletions
4
...yzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion.cs
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,4 @@ | ||
namespace SonarLintExclusions | ||
{ | ||
public class ExcludedByExclusion { } // S2094 | ||
} |
4 changes: 4 additions & 0 deletions
4
...its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByGlobalExclusion.cs
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,4 @@ | ||
namespace SonarLintExclusions | ||
{ | ||
public class ExcludedByGlobalExclusion { } // S2094 | ||
} |
4 changes: 4 additions & 0 deletions
4
analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/Included.cs
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,4 @@ | ||
namespace SonarLintExclusions | ||
{ | ||
public class Included { } // S2094 | ||
} |
12 changes: 12 additions & 0 deletions
12
analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs
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,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
cristian-ambrosini-sonarsource marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace SonarLintExclusions | ||
{ | ||
internal class NotIncluded | ||
cristian-ambrosini-sonarsource marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj
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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<SonarUnknownProjectType>true</SonarUnknownProjectType> | ||
</PropertyGroup> | ||
|
||
</Project> |
10 changes: 10 additions & 0 deletions
10
...urces/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByExclusionTest.cs
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,10 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
namespace SonarLintExclusionsTest | ||
{ | ||
[TestClass] | ||
public class ExcludedByExclusionTest | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() { } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByGlobalExclusionTest.cs
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,10 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
namespace SonarLintExclusionsTest | ||
{ | ||
[TestClass] | ||
public class ExcludedByGlobalExclusionTest | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() { } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...zers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/IncludedTest.cs
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,10 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
namespace SonarLintExclusionsTest | ||
{ | ||
[TestClass] | ||
public class IncludedTest | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() { } | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/NotIncludedTest.cs
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,10 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
namespace SonarLintExclusionsTest | ||
{ | ||
[TestClass] | ||
public class NotIncludedTest | ||
{ | ||
[TestMethod] | ||
public void TestMethod1() { } | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...rs/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<SonarUnknownProjectType>true</SonarUnknownProjectType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" /> | ||
<PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
cristian-ambrosini-sonarsource marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ItemGroup> | ||
|
||
</Project> |
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,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "7.0.100-rc.1.22431.12", | ||
cristian-ambrosini-sonarsource marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"rollForward": "latestMinor" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think that both of the properties should refer to a single language
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 see that this is how it is in all the SonarLint.xml config - I'll drop a question to understand if the vbnet case is really needed.
EDIT: This is the same property but for CS and VB.NET.
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.
We can leave as is - that's how it is in the SonarLint.xml