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

Add SonarLint exclusion/inclusion IT #6884

Merged
merged 30 commits into from Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 29 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 Mar 1, 2023
fd51b79
Removing relativeRootFromSonarLintXml and deprecated 'Files' element
CristianAmbrosini Mar 1, 2023
bb7b527
Replaced Lazy initialization with null-coalescing assignment operator
CristianAmbrosini Mar 1, 2023
db8681f
Removed empty list initializers
CristianAmbrosini Mar 2, 2023
1f43c31
Addressed PR review comments
CristianAmbrosini Mar 2, 2023
e306251
Add SonarLintXml unit tests
CristianAmbrosini Mar 3, 2023
d35de5d
Replaced tabs with spaces
CristianAmbrosini Mar 3, 2023
56db519
Add test cases
CristianAmbrosini Mar 3, 2023
b0bab1c
Bump temporarily UTs ToStringCallCount
CristianAmbrosini Mar 6, 2023
7f3d726
Small merge fix
CristianAmbrosini Mar 6, 2023
1f58ae7
Fix rebase issues 2
CristianAmbrosini Mar 6, 2023
c78de16
Fix UTs
CristianAmbrosini Mar 6, 2023
c3c3161
IgnoreAttribute for parametrized test.
CristianAmbrosini Mar 6, 2023
08f4e00
Addressed PR comments
CristianAmbrosini Mar 7, 2023
9b8cb0b
Rebase UTs fix
CristianAmbrosini Mar 7, 2023
00b4a64
Second round of comments
CristianAmbrosini Mar 8, 2023
0a0e8a9
Last UT fix (revert to previous values)
CristianAmbrosini Mar 8, 2023
bfb582b
Migrated ShouldAnalyzeFile test case to ShouldAnalyzeTree
CristianAmbrosini Mar 8, 2023
ec95a4b
Third wave of comments
CristianAmbrosini Mar 9, 2023
3282762
Add new test project
mary-georgiou-sonarsource Mar 8, 2023
1697c10
set up SonarProjectType to unknown for sonarlint exclusion test
mary-georgiou-sonarsource Mar 8, 2023
eb353ff
Add sonarlint exclusions config
mary-georgiou-sonarsource Mar 8, 2023
91a137b
modify project to reflect test
mary-georgiou-sonarsource Mar 8, 2023
a05d226
add exclusion for test project
mary-georgiou-sonarsource Mar 8, 2023
40e6cb4
add explanation about SonarUnknownProjectType property
mary-georgiou-sonarsource Mar 9, 2023
520ee39
fix project to test all SL parameters
mary-georgiou-sonarsource Mar 9, 2023
7fe2b29
update expected
mary-georgiou-sonarsource Mar 9, 2023
cb07cf7
test all parameters also for test project
mary-georgiou-sonarsource Mar 9, 2023
c31ba4f
fix sonarlint xml
mary-georgiou-sonarsource Mar 9, 2023
73f20d3
apply comments
mary-georgiou-sonarsource Mar 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets
Expand Up @@ -11,6 +11,8 @@
<!-- Only projects with explicit SonarQubeTestProject=true will be classified as test ones. -->
<SonarProjectType Condition="$(SonarQubeTestProject) != 'true'">Product</SonarProjectType>
<SonarProjectType Condition="$(SonarQubeTestProject) == 'true'">Test</SonarProjectType>
<!-- When SonarUnknownProjectType is present and it's true, indicated that we emulate the SonarLint envirorment -->
<SonarProjectType Condition="$(SonarUnknownProjectType) == 'true'">Unknown</SonarProjectType>
</PropertyGroup>

<Error Text="Could not find '$(BinariesFolder)\SonarAnalyzer.dll'" Condition="!Exists('$(BinariesFolder)\SonarAnalyzer.dll')" />
Expand Down
40 changes: 40 additions & 0 deletions analyzers/its/config/SonarLintExclusions/SonarLint.xml
@@ -0,0 +1,40 @@
<?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>

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

Suggested change
<Key>sonar.vbnet.ignoreHeaderComments</Key>
<Key>sonar.cs.ignoreHeaderComments</Key>

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

<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>
<!-- Test parameters -->
<Setting>
<Key>sonar.test.inclusions</Key>
<Value>**/IncludedTest/*.cs</Value>
</Setting>
<Setting>
<Key>sonar.test.exclusions</Key>
<Value>**/ExcludedByExclusionTest.cs</Value>
</Setting>
<Setting>
<Key>sonar.global.test.exclusions</Key>
<Value>**/ExcludedByGlobalExclusionTest.cs</Value>
</Setting>
</Settings>
</AnalysisInput>
@@ -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
}
}
}
]
}
@@ -0,0 +1,9 @@
{
"issues": [
{
"id": "S3990",
"message": "Provide a 'CLSCompliant' attribute for assembly 'SonarLintExclusions'.",
"location": null
}
]
}
@@ -0,0 +1,9 @@
{
"issues": [
{
"id": "S3992",
"message": "Provide a 'ComVisible' attribute for assembly 'SonarLintExclusions'.",
"location": null
}
]
}
@@ -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
}
}
}
]
}
3 changes: 2 additions & 1 deletion analyzers/its/regression-test.ps1
Expand Up @@ -12,7 +12,7 @@ param
$ruleId,

[Parameter(HelpMessage = "The name of single project to build. If ommited, all projects will be build.")]
[ValidateSet("AnalyzeGenerated.CS", "AnalyzeGenerated.VB", "akka.net", "Automapper", "Ember-MM", "Nancy", "NetCore31", "Net5", "Net6", "Net7", "NetCore31WithConfigurableRules" , "ManuallyAddedNoncompliantIssues.CS", "ManuallyAddedNoncompliantIssues.VB", "Roslyn.1.3.1", "SkipGenerated.CS", "SkipGenerated.VB", "WebConfig")]
[ValidateSet("AnalyzeGenerated.CS", "AnalyzeGenerated.VB", "akka.net", "Automapper", "Ember-MM", "Nancy", "NetCore31", "Net5", "Net6", "Net7", "NetCore31WithConfigurableRules" , "ManuallyAddedNoncompliantIssues.CS", "ManuallyAddedNoncompliantIssues.VB", "Roslyn.1.3.1", "SkipGenerated.CS", "SkipGenerated.VB", "SonarLintExclusions", "WebConfig")]
[string]
$project
)
Expand Down Expand Up @@ -499,6 +499,7 @@ try {
Build-Project-DotnetTool "NetCore31WithConfigurableRules" "NetCore31WithConfigurableRules.sln"
Build-Project-DotnetTool "akka.net" "src\Akka.sln"
Build-Project-DotnetTool "Automapper" "Automapper.sln"
Build-Project-DotnetTool "SonarLintExclusions" "SonarLintExclusions.sln"

Write-Header "Processing analyzer results"

Expand Down
36 changes: 36 additions & 0 deletions analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln
@@ -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
@@ -0,0 +1,4 @@
namespace SonarLintExclusions
{
public class ExcludedByExclusion { } // S2094
}
@@ -0,0 +1,4 @@
namespace SonarLintExclusions
{
public class ExcludedByGlobalExclusion { } // S2094
}
@@ -0,0 +1,4 @@
namespace SonarLintExclusions
{
public class Included { } // S2094
}
@@ -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
{
}
}
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<SonarUnknownProjectType>true</SonarUnknownProjectType>
</PropertyGroup>

</Project>
@@ -0,0 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace SonarLintExclusionsTest
{
[TestClass]
public class ExcludedByExclusionTest
{
[TestMethod]
public void TestMethod1() { }
}
}
@@ -0,0 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace SonarLintExclusionsTest
{
[TestClass]
public class ExcludedByGlobalExclusionTest
{
[TestMethod]
public void TestMethod1() { }
}
}
@@ -0,0 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace SonarLintExclusionsTest
{
[TestClass]
public class IncludedTest
{
[TestMethod]
public void TestMethod1() { }
}
}
@@ -0,0 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace SonarLintExclusionsTest
{
[TestClass]
public class NotIncludedTest
{
[TestMethod]
public void TestMethod1() { }
}
}
@@ -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>
6 changes: 6 additions & 0 deletions analyzers/its/sources/SonarLintExclusions/global.json
@@ -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"
}
}