From bc50fb056bd1080f7751187868aa2eaa596dd443 Mon Sep 17 00:00:00 2001
From: Mary Georgiou
<89914005+mary-georgiou-sonarsource@users.noreply.github.com>
Date: Fri, 10 Mar 2023 14:56:39 +0100
Subject: [PATCH] Add SonarLint exclusion/inclusion IT (#6884)
---
...SonarAnalyzer.Testing.ImportBefore.targets | 2 +
.../config/SonarLintExclusions/SonarLint.xml | 40 +++++++++++++++++++
.../SonarLintExclusions--net7.0-S2094.json | 17 ++++++++
.../SonarLintExclusions--net7.0-S3990.json | 9 +++++
.../SonarLintExclusions--net7.0-S3992.json | 9 +++++
...SonarLintExclusionsTest--net7.0-S2699.json | 17 ++++++++
analyzers/its/regression-test.ps1 | 3 +-
.../SonarLintExclusions.sln | 36 +++++++++++++++++
.../Included/ExcludedByExclusion.cs | 4 ++
.../Included/ExcludedByExclusion2.cs | 4 ++
.../Included/ExcludedByGlobalExclusion.cs | 4 ++
.../SonarLintExclusions/Included/Included.cs | 4 ++
.../SonarLintExclusions/NotIncluded.cs | 4 ++
.../SonarLintExclusions.csproj | 8 ++++
.../IncludedTest/ExcludedByExclusionTest.cs | 10 +++++
.../ExcludedByGlobalExclusionTest.cs | 10 +++++
.../IncludedTest/IncludedTest.cs | 10 +++++
.../NotIncludedTest.cs | 10 +++++
.../SonarLintExclusionsTest.csproj | 15 +++++++
.../sources/SonarLintExclusions/global.json | 6 +++
20 files changed, 221 insertions(+), 1 deletion(-)
create mode 100644 analyzers/its/config/SonarLintExclusions/SonarLint.xml
create mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json
create mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json
create mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3992.json
create mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusionsTest--net7.0-S2699.json
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion2.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByGlobalExclusion.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/Included.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByExclusionTest.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByGlobalExclusionTest.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/IncludedTest.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/NotIncludedTest.cs
create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj
create mode 100644 analyzers/its/sources/SonarLintExclusions/global.json
diff --git a/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets b/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets
index f3fda742c51..ea85c04a441 100644
--- a/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets
+++ b/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets
@@ -11,6 +11,8 @@
Product
Test
+
+ Unknown
diff --git a/analyzers/its/config/SonarLintExclusions/SonarLint.xml b/analyzers/its/config/SonarLintExclusions/SonarLint.xml
new file mode 100644
index 00000000000..be8726ef80a
--- /dev/null
+++ b/analyzers/its/config/SonarLintExclusions/SonarLint.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+ sonar.cs.ignoreHeaderComments
+ true
+
+
+ sonar.vbnet.ignoreHeaderComments
+ true
+
+
+ sonar.inclusions
+ **/Included/*.cs
+
+
+ sonar.exclusions
+ **/ExcludedByExclusion.cs,**/ExcludedByExclusion2.cs
+
+
+ sonar.global.exclusions
+ **/ExcludedByGlobalExclusion.cs
+
+
+
+ sonar.test.inclusions
+ **/IncludedTest/*.cs
+
+
+ sonar.test.exclusions
+ **/ExcludedByExclusionTest.cs
+
+
+ sonar.global.test.exclusions
+ **/ExcludedByGlobalExclusionTest.cs
+
+
+
\ No newline at end of file
diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json
new file mode 100644
index 00000000000..e86aa12d401
--- /dev/null
+++ b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json
@@ -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
+}
+}
+}
+]
+}
diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json
new file mode 100644
index 00000000000..17786f2ed3f
--- /dev/null
+++ b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json
@@ -0,0 +1,9 @@
+{
+"issues": [
+{
+"id": "S3990",
+"message": "Provide a 'CLSCompliant' attribute for assembly 'SonarLintExclusions'.",
+"location": null
+}
+]
+}
diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3992.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3992.json
new file mode 100644
index 00000000000..dfd144e2a2e
--- /dev/null
+++ b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3992.json
@@ -0,0 +1,9 @@
+{
+"issues": [
+{
+"id": "S3992",
+"message": "Provide a 'ComVisible' attribute for assembly 'SonarLintExclusions'.",
+"location": null
+}
+]
+}
diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusionsTest--net7.0-S2699.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusionsTest--net7.0-S2699.json
new file mode 100644
index 00000000000..9a66c44306c
--- /dev/null
+++ b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusionsTest--net7.0-S2699.json
@@ -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
+}
+}
+}
+]
+}
diff --git a/analyzers/its/regression-test.ps1 b/analyzers/its/regression-test.ps1
index ad7cf9d8057..513681eedbc 100644
--- a/analyzers/its/regression-test.ps1
+++ b/analyzers/its/regression-test.ps1
@@ -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
)
@@ -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"
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln
new file mode 100644
index 00000000000..3e5bcbbe34b
--- /dev/null
+++ b/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
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion.cs
new file mode 100644
index 00000000000..c33727affc7
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion.cs
@@ -0,0 +1,4 @@
+namespace SonarLintExclusions
+{
+ public class ExcludedByExclusion { } // S2094
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion2.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion2.cs
new file mode 100644
index 00000000000..8366890afef
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion2.cs
@@ -0,0 +1,4 @@
+namespace SonarLintExclusions
+{
+ public class ExcludedByExclusion2 { } // S2094
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByGlobalExclusion.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByGlobalExclusion.cs
new file mode 100644
index 00000000000..8eafecd8f7f
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByGlobalExclusion.cs
@@ -0,0 +1,4 @@
+namespace SonarLintExclusions
+{
+ public class ExcludedByGlobalExclusion { } // S2094
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/Included.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/Included.cs
new file mode 100644
index 00000000000..6fba906c697
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/Included.cs
@@ -0,0 +1,4 @@
+namespace SonarLintExclusions
+{
+ public class Included { } // S2094
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs
new file mode 100644
index 00000000000..95a9911ce76
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs
@@ -0,0 +1,4 @@
+namespace SonarLintExclusions
+{
+ public class NotIncluded { } // S2094
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj
new file mode 100644
index 00000000000..15297210401
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj
@@ -0,0 +1,8 @@
+
+
+
+ net7.0
+ true
+
+
+
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByExclusionTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByExclusionTest.cs
new file mode 100644
index 00000000000..d3fcf14795b
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByExclusionTest.cs
@@ -0,0 +1,10 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+namespace SonarLintExclusionsTest
+{
+ [TestClass]
+ public class ExcludedByExclusionTest
+ {
+ [TestMethod]
+ public void TestMethod1() { }
+ }
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByGlobalExclusionTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByGlobalExclusionTest.cs
new file mode 100644
index 00000000000..b1aadee0880
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByGlobalExclusionTest.cs
@@ -0,0 +1,10 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+namespace SonarLintExclusionsTest
+{
+ [TestClass]
+ public class ExcludedByGlobalExclusionTest
+ {
+ [TestMethod]
+ public void TestMethod1() { }
+ }
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/IncludedTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/IncludedTest.cs
new file mode 100644
index 00000000000..cc364afdccc
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/IncludedTest.cs
@@ -0,0 +1,10 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+namespace SonarLintExclusionsTest
+{
+ [TestClass]
+ public class IncludedTest
+ {
+ [TestMethod]
+ public void TestMethod1() { }
+ }
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/NotIncludedTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/NotIncludedTest.cs
new file mode 100644
index 00000000000..8b81a00464c
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/NotIncludedTest.cs
@@ -0,0 +1,10 @@
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+namespace SonarLintExclusionsTest
+{
+ [TestClass]
+ public class NotIncludedTest
+ {
+ [TestMethod]
+ public void TestMethod1() { }
+ }
+}
diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj
new file mode 100644
index 00000000000..0d99fb1aff7
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net7.0
+ false
+ true
+
+
+
+
+
+
+
+
+
diff --git a/analyzers/its/sources/SonarLintExclusions/global.json b/analyzers/its/sources/SonarLintExclusions/global.json
new file mode 100644
index 00000000000..4037c7755e7
--- /dev/null
+++ b/analyzers/its/sources/SonarLintExclusions/global.json
@@ -0,0 +1,6 @@
+{
+ "sdk": {
+ "version": "7.0.100",
+ "rollForward": "latestMinor"
+ }
+}
\ No newline at end of file