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

Support exclusion and inclusion parameters when run by SonarLint #6870

Merged
merged 14 commits into from Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
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>
<Value>true</Value>
</Setting>
<Setting>
<Key>sonar.inclusions</Key>
<Value>**/Included/*.cs</Value>
</Setting>
<Setting>
<Key>sonar.exclusions</Key>
<Value>**/ExcludedByExclusion.cs,**/ExcludedByExclusion2.cs</Value>
</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": "S1451",
"message": "Add or update the header of this file.",
"location": {
"uri": "sources\SonarLintExclusions\SonarLintExclusions\Included\Included.cs",
"region": {
"startLine": 1,
"startColumn": 1,
"endLine": 1,
"endColumn": 1
}
}
}
]
}
@@ -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
4 changes: 2 additions & 2 deletions analyzers/its/sources/AnalyzeGenerated.CS/SonarLint.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<AnalysisInput>
<Settings>
<Setting>
Expand Down Expand Up @@ -27,4 +27,4 @@
</Rules>
<Files>
</Files>
</AnalysisInput>
</AnalysisInput>
4 changes: 2 additions & 2 deletions analyzers/its/sources/SkipGenerated.CS/SonarLint.xml
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<AnalysisInput>
<Settings>
<Setting>
Expand Down Expand Up @@ -27,4 +27,4 @@
</Rules>
<Files>
</Files>
</AnalysisInput>
</AnalysisInput>
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 ExcludedByExclusion2 { } // S2094
}
@@ -0,0 +1,4 @@
namespace SonarLintExclusions
{
public class ExcludedByGlobalExclusion { } // S2094
}
@@ -0,0 +1,4 @@
namespace SonarLintExclusions
{
public class Included { } // S2094
}
@@ -0,0 +1,4 @@
namespace SonarLintExclusions
{
public class NotIncluded { } // S2094
}
@@ -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,15 @@
<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" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions analyzers/its/sources/SonarLintExclusions/global.json
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "7.0.100",
"rollForward": "latestMinor"
}
}