From dd094c07b6a9fa537657c6dc519b8c637e51eeff Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Wed, 1 Mar 2023 12:09:33 +0100 Subject: [PATCH 01/30] SonarLint.xml file read base logic and tests --- .../Helpers/SonarLintXmlReader.cs | 1 + .../All_properties_cs/SonarLint.xml | 44 +++++++++---------- .../All_properties_vbnet/SonarLint.xml | 44 +++++++++---------- 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs index 8c717d7a31d..c625d1160be 100644 --- a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs +++ b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs @@ -79,6 +79,7 @@ private static SonarLintXml ParseContent(SourceText sonarLintXml) return SonarLintXml.Empty; } } +} private string ReadProperty(string property) => sonarLintXml is { Settings: { } settings } diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_cs/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_cs/SonarLint.xml index 0dc284bc00d..038a0279c01 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_cs/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_cs/SonarLint.xml @@ -17,30 +17,30 @@ sonar.cs.roslyn.ignoreIssues false - - sonar.exclusions - Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* - - - sonar.inclusions - Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* - - - sonar.global.exclusions - Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* - - - sonar.test.exclusions - Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* - - - sonar.test.inclusions - Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* - - + + sonar.exclusions + Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* + + + sonar.inclusions + Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* + + + sonar.global.exclusions + Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* + + + sonar.test.exclusions + Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* + + + sonar.test.inclusions + Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* + + sonar.global.test.exclusions Fake/GlobalTestExclusions/**/*,Fake/GlobalTestExclusions/Second*/**/* - + diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_vbnet/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_vbnet/SonarLint.xml index f848061efac..1cf0881fcaf 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_vbnet/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_vbnet/SonarLint.xml @@ -17,30 +17,30 @@ sonar.vbnet.roslyn.ignoreIssues false - - sonar.exclusions - Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* - - - sonar.inclusions - Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* - - - sonar.global.exclusions - Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* - - - sonar.test.exclusions - Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* - - - sonar.test.inclusions - Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* - - + + sonar.exclusions + Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* + + + sonar.inclusions + Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* + + + sonar.global.exclusions + Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* + + + sonar.test.exclusions + Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* + + + sonar.test.inclusions + Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* + + sonar.global.test.exclusions Fake/GlobalTestExclusions/**/*,Fake/GlobalTestExclusions/Second*/**/* - + From fd51b79107f6a1b019965f077a408d7eba890ffb Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Wed, 1 Mar 2023 12:10:06 +0100 Subject: [PATCH 02/30] Removing relativeRootFromSonarLintXml and deprecated 'Files' element --- analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs index d699d960638..53f5f090144 100644 --- a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs +++ b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs @@ -49,7 +49,7 @@ public class SonarLintXmlRule [XmlArray("Parameters")] [XmlArrayItem("Parameter")] - public List Parameters { get; set; } + public List Parameters { get; set; } = new List(); } public class SonarLintXmlKeyValuePair From bb7b52777b636dd23d7bee9bf3e73b2e4f124367 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Wed, 1 Mar 2023 12:10:26 +0100 Subject: [PATCH 03/30] Replaced Lazy initialization with null-coalescing assignment operator --- .../src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs index c625d1160be..196473b4af5 100644 --- a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs +++ b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs @@ -74,7 +74,7 @@ private static SonarLintXml ParseContent(SourceText sonarLintXml) using var reader = XmlReader.Create(sr); return (SonarLintXml)serializer.Deserialize(reader); } - catch + catch (Exception) { return SonarLintXml.Empty; } From db8681fd0337bda91d931ebd9775562211e2dcf5 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Thu, 2 Mar 2023 09:30:12 +0100 Subject: [PATCH 04/30] Removed empty list initializers --- analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs index 53f5f090144..d699d960638 100644 --- a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs +++ b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXml.cs @@ -49,7 +49,7 @@ public class SonarLintXmlRule [XmlArray("Parameters")] [XmlArrayItem("Parameter")] - public List Parameters { get; set; } = new List(); + public List Parameters { get; set; } } public class SonarLintXmlKeyValuePair From 1f43c31166a1665381a8ee21cfeda24bf22413a5 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Thu, 2 Mar 2023 15:43:32 +0100 Subject: [PATCH 05/30] Addressed PR review comments --- .../Helpers/SonarLintXmlReaderTest.cs | 7 +++++++ .../SonarLintXml/Invalid_Xml/SonarLint.xml | 2 +- .../SonarLint.xml | 20 +++++++++---------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlReaderTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlReaderTest.cs index b8502beb93f..46956e2e22e 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlReaderTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlReaderTest.cs @@ -101,6 +101,13 @@ private static void AssertArrayContent(string[] array, string folder) array[1].Should().BeEquivalentTo($"Fake/{folder}/Second*/**/*"); } + private static void AssertArrayContent(string[] array, string folder) + { + array.Should().HaveCount(2); + array[0].Should().BeEquivalentTo($"Fake/{folder}/**/*"); + array[1].Should().BeEquivalentTo($"Fake/{folder}/Second*/**/*"); + } + private static SonarLintXmlReader CreateSonarLintXmlReader(string relativePath, string language = LanguageNames.CSharp) => new(SourceText.From(File.ReadAllText(relativePath)), language); } diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Invalid_Xml/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Invalid_Xml/SonarLint.xml index 9a259cbeb32..318e9dd187d 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Invalid_Xml/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Invalid_Xml/SonarLint.xml @@ -1,7 +1,7 @@ - Setting> + Setting> sonar.nothing nothing diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Partially_missing_properties/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Partially_missing_properties/SonarLint.xml index ed671af08b6..e74b7f74d4f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Partially_missing_properties/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Partially_missing_properties/SonarLint.xml @@ -1,22 +1,22 @@ - + sonar.nothing nothing - + sonar.cs.analyzeGeneratedCode true - - sonar.exclusions - Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* - - - sonar.inclusions - Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* - + + sonar.exclusions + Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* + + + sonar.inclusions + Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* + From e3062512469f42d73c030642c51223d720867849 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Fri, 3 Mar 2023 09:34:16 +0100 Subject: [PATCH 06/30] Add SonarLintXml unit tests --- .../SonarLint.xml | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_small_template/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_small_template/SonarLint.xml index 70ca0115566..927db5288ee 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_small_template/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_small_template/SonarLint.xml @@ -17,36 +17,36 @@ sonar.cs.roslyn.ignoreIssues false - - sonar.exclusions - Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* - - - sonar.inclusions - Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* - - - sonar.global.exclusions - Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* - - - sonar.test.exclusions - Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* - - - sonar.test.inclusions - Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* - - - sonar.global.test.exclusions - Fake/GlobalTestExclusions/**/*,Fake/GlobalTestExclusions/Second*/**/* - + + sonar.exclusions + Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* + + + sonar.inclusions + Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* + + + sonar.global.exclusions + Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* + + + sonar.test.exclusions + Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* + + + sonar.test.inclusions + Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* + + + sonar.global.test.exclusions + Fake/GlobalTestExclusions/**/*,Fake/GlobalTestExclusions/Second*/**/* + S0001 - + S0002 @@ -62,7 +62,7 @@ - + S0004 From d35de5d23e0564706128319d214af71ebff8ff9b Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Fri, 3 Mar 2023 09:43:59 +0100 Subject: [PATCH 07/30] Replaced tabs with spaces --- .../SonarLint.xml | 52 +++++++++---------- .../SonarLintXml/Invalid_Xml/SonarLint.xml | 2 +- .../SonarLint.xml | 20 +++---- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_small_template/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_small_template/SonarLint.xml index 927db5288ee..70ca0115566 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_small_template/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_small_template/SonarLint.xml @@ -17,36 +17,36 @@ sonar.cs.roslyn.ignoreIssues false - - sonar.exclusions - Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* - - - sonar.inclusions - Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* - - - sonar.global.exclusions - Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* - - - sonar.test.exclusions - Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* - - - sonar.test.inclusions - Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* - - - sonar.global.test.exclusions - Fake/GlobalTestExclusions/**/*,Fake/GlobalTestExclusions/Second*/**/* - + + sonar.exclusions + Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* + + + sonar.inclusions + Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* + + + sonar.global.exclusions + Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* + + + sonar.test.exclusions + Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* + + + sonar.test.inclusions + Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* + + + sonar.global.test.exclusions + Fake/GlobalTestExclusions/**/*,Fake/GlobalTestExclusions/Second*/**/* + S0001 - + S0002 @@ -62,7 +62,7 @@ - + S0004 diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Invalid_Xml/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Invalid_Xml/SonarLint.xml index 318e9dd187d..9a259cbeb32 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Invalid_Xml/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Invalid_Xml/SonarLint.xml @@ -1,7 +1,7 @@ - Setting> + Setting> sonar.nothing nothing diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Partially_missing_properties/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Partially_missing_properties/SonarLint.xml index e74b7f74d4f..ed671af08b6 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Partially_missing_properties/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/Partially_missing_properties/SonarLint.xml @@ -1,22 +1,22 @@ - + sonar.nothing nothing - + sonar.cs.analyzeGeneratedCode true - - sonar.exclusions - Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* - - - sonar.inclusions - Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* - + + sonar.exclusions + Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* + + + sonar.inclusions + Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* + From 56db519e7290e616de93c9e2c2a638c1df8bf34b Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Fri, 3 Mar 2023 17:30:33 +0100 Subject: [PATCH 08/30] Add test cases --- ...alysisContextBaseTest.ShouldAnalyzeFile.cs | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs new file mode 100644 index 00000000000..ba868d01163 --- /dev/null +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs @@ -0,0 +1,99 @@ +/* + * SonarAnalyzer for .NET + * Copyright (C) 2015-2023 SonarSource SA + * mailto: contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +namespace SonarAnalyzer.UnitTest.AnalysisContext; + +public partial class SonarAnalysisContextBaseTest +{ + [DataTestMethod] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, false)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, true)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] + public void ShouldAnalyzeFile_Exclusions_ReturnExpected(string filePath, string[] exclusions, ProjectType projectType, bool shouldAnalyze) => + AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, exclusions: exclusions); + + [DataTestMethod] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, false)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, true)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] + public void ShouldAnalyzeFile_GlobalExclusions_ReturnExpected(string filePath, string[] globalExclusions, ProjectType projectType, bool shouldAnalyze) => + AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, globalExclusions: globalExclusions); + + [DataTestMethod] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, false)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] + public void ShouldAnalyzeFile_TestExclusions_ReturnExpected(string filePath, string[] testExclusions, ProjectType projectType, bool shouldAnalyze) => + AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, testExclusions: testExclusions); + + [DataTestMethod] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, false)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] + public void ShouldAnalyzeFile_GlobalTestExclusions_ReturnExpected(string filePath, string[] globalTestExclusions, ProjectType projectType, bool shouldAnalyze) => + AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, globalTestExclusions: globalTestExclusions); + + [DataTestMethod] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, false)] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, true)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] + public void ShouldAnalyzeFile_Inclusions_ReturnExpected(string filePath, string[] inclusions, ProjectType projectType, bool shouldAnalyze) => + AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, inclusions: inclusions); + + [DataTestMethod] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, true)] + [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, false)] + public void ShouldAnalyzeFile_TestInclusions_ReturnExpected(string filePath, string[] testInclusions, ProjectType projectType, bool shouldAnalyze) => + AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, testInclusions: testInclusions); + + private void AssertShouldAnalyzeFile( + string filePath, + ProjectType projectType, + bool shouldAnalyze, + string[] exclusions = null, + string[] inclusions = null, + string[] globalExclusions = null, + string[] testExclusions = null, + string[] testInclusions = null, + string[] globalTestExclusions = null) + { + var compilation = new SnippetCompiler("// Nothing to see here", TestHelper.ProjectTypeReference(projectType)).SemanticModel.Compilation; + var sonarLintXml = AnalysisScaffolding.CreateSonarLintXml( + TestContext, + exclusions: exclusions, + inclusions: inclusions, + globalExclusions: globalExclusions, + testExclusions: testExclusions, + testInclusions: testInclusions, + globalTestExclusions: + globalTestExclusions); + var options = AnalysisScaffolding.CreateOptions(sonarLintXml); + var sut = CreateSut(compilation, options); + + sut.ShouldAnalyzeFile(filePath).Should().Be(shouldAnalyze); + } +} From b0bab1c653d441672fc84a9ff9484e35ba700ea4 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Mon, 6 Mar 2023 09:31:11 +0100 Subject: [PATCH 09/30] Bump temporarily UTs ToStringCallCount --- .../SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index c667b8898e2..42d2f017b9f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -101,8 +101,8 @@ public void ShouldAnalyzeTree_GeneratedFile_ShouldAnalyzeGeneratedProvider_IsCac sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().BeTrue(); // GetText should be called every time ShouldAnalyzeGenerated is called... - additionalText.Verify(x => x.GetText(It.IsAny()), Times.Exactly(3)); - sonarLintXml.ToStringCallCount.Should().Be(1); // ... but we should only try to read the file once + additionalText.Verify(x => x.GetText(It.IsAny()), Times.Exactly(6)); // TEMPORARILY BUMPED TO 6 + sonarLintXml.ToStringCallCount.Should().Be(2); // ... but we should only try to read the file once // TEMPORARILY BUMPED TO 2 } [DataTestMethod] @@ -115,7 +115,7 @@ public void ShouldAnalyzeTree_GeneratedFile_InvalidSonarLintXml(string fileName, var sut = CreateSut(compilation, CreateOptions(sonarLintXml)); // 1. Read -> no error - sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); + sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); sonarLintXml.ToStringCallCount.Should().Be(1); // should have attempted to read the file // 2. Read again to check that the load error doesn't prevent caching from working From 7f3d726fef672900f3a0ccfe0c1978d99533c112 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Mon, 6 Mar 2023 10:28:50 +0100 Subject: [PATCH 10/30] Small merge fix --- .../src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs | 3 +-- .../Helpers/SonarLintXmlReaderTest.cs | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs index 196473b4af5..8c717d7a31d 100644 --- a/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs +++ b/analyzers/src/SonarAnalyzer.Common/Helpers/SonarLintXmlReader.cs @@ -74,12 +74,11 @@ private static SonarLintXml ParseContent(SourceText sonarLintXml) using var reader = XmlReader.Create(sr); return (SonarLintXml)serializer.Deserialize(reader); } - catch (Exception) + catch { return SonarLintXml.Empty; } } -} private string ReadProperty(string property) => sonarLintXml is { Settings: { } settings } diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlReaderTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlReaderTest.cs index 46956e2e22e..b8502beb93f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlReaderTest.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/SonarLintXmlReaderTest.cs @@ -101,13 +101,6 @@ private static void AssertArrayContent(string[] array, string folder) array[1].Should().BeEquivalentTo($"Fake/{folder}/Second*/**/*"); } - private static void AssertArrayContent(string[] array, string folder) - { - array.Should().HaveCount(2); - array[0].Should().BeEquivalentTo($"Fake/{folder}/**/*"); - array[1].Should().BeEquivalentTo($"Fake/{folder}/Second*/**/*"); - } - private static SonarLintXmlReader CreateSonarLintXmlReader(string relativePath, string language = LanguageNames.CSharp) => new(SourceText.From(File.ReadAllText(relativePath)), language); } From 1f58ae763e2c7eb8c01c7e4f5f11a42c31bd7f16 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Mon, 6 Mar 2023 10:34:47 +0100 Subject: [PATCH 11/30] Fix rebase issues 2 --- ...alysisContextBaseTest.ShouldAnalyzeTree.cs | 2 +- .../All_properties_cs/SonarLint.xml | 44 +++++++++---------- .../All_properties_vbnet/SonarLint.xml | 44 +++++++++---------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index 42d2f017b9f..9052cddfe3f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -115,7 +115,7 @@ public void ShouldAnalyzeTree_GeneratedFile_InvalidSonarLintXml(string fileName, var sut = CreateSut(compilation, CreateOptions(sonarLintXml)); // 1. Read -> no error - sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); + sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); sonarLintXml.ToStringCallCount.Should().Be(1); // should have attempted to read the file // 2. Read again to check that the load error doesn't prevent caching from working diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_cs/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_cs/SonarLint.xml index 038a0279c01..0dc284bc00d 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_cs/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_cs/SonarLint.xml @@ -17,30 +17,30 @@ sonar.cs.roslyn.ignoreIssues false - - sonar.exclusions - Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* - - - sonar.inclusions - Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* - - - sonar.global.exclusions - Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* - - - sonar.test.exclusions - Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* - - - sonar.test.inclusions - Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* - - + + sonar.exclusions + Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* + + + sonar.inclusions + Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* + + + sonar.global.exclusions + Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* + + + sonar.test.exclusions + Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* + + + sonar.test.inclusions + Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* + + sonar.global.test.exclusions Fake/GlobalTestExclusions/**/*,Fake/GlobalTestExclusions/Second*/**/* - + diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_vbnet/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_vbnet/SonarLint.xml index 1cf0881fcaf..f848061efac 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_vbnet/SonarLint.xml +++ b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/All_properties_vbnet/SonarLint.xml @@ -17,30 +17,30 @@ sonar.vbnet.roslyn.ignoreIssues false - - sonar.exclusions - Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* - - - sonar.inclusions - Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* - - - sonar.global.exclusions - Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* - - - sonar.test.exclusions - Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* - - - sonar.test.inclusions - Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* - - + + sonar.exclusions + Fake/Exclusions/**/*,Fake/Exclusions/Second*/**/* + + + sonar.inclusions + Fake/Inclusions/**/*,Fake/Inclusions/Second*/**/* + + + sonar.global.exclusions + Fake/GlobalExclusions/**/*,Fake/GlobalExclusions/Second*/**/* + + + sonar.test.exclusions + Fake/TestExclusions/**/*,Fake/TestExclusions/Second*/**/* + + + sonar.test.inclusions + Fake/TestInclusions/**/*,Fake/TestInclusions/Second*/**/* + + sonar.global.test.exclusions Fake/GlobalTestExclusions/**/*,Fake/GlobalTestExclusions/Second*/**/* - + From c78de16ac8a25b843083ba45db74446c3afe02e5 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Mon, 6 Mar 2023 11:18:32 +0100 Subject: [PATCH 12/30] Fix UTs --- .../SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index 9052cddfe3f..81d34e5a24e 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -116,11 +116,11 @@ public void ShouldAnalyzeTree_GeneratedFile_InvalidSonarLintXml(string fileName, // 1. Read -> no error sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); - sonarLintXml.ToStringCallCount.Should().Be(1); // should have attempted to read the file + sonarLintXml.ToStringCallCount.Should().Be(2); // should have attempted to read the file // TEMPORARILY BUMPED TO 2 // 2. Read again to check that the load error doesn't prevent caching from working sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); - sonarLintXml.ToStringCallCount.Should().Be(1); // should not have attempted to read the file again + sonarLintXml.ToStringCallCount.Should().Be(2); // should not have attempted to read the file again // TEMPORARILY BUMPED TO 2 } [DataTestMethod] From c3c3161da9146f10036eb0e3d6ce42a70727d5ea Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Mon, 6 Mar 2023 12:10:58 +0100 Subject: [PATCH 13/30] IgnoreAttribute for parametrized test. --- .../SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index 81d34e5a24e..0358e3a2d39 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -105,6 +105,7 @@ public void ShouldAnalyzeTree_GeneratedFile_ShouldAnalyzeGeneratedProvider_IsCac sonarLintXml.ToStringCallCount.Should().Be(2); // ... but we should only try to read the file once // TEMPORARILY BUMPED TO 2 } + [Ignore("Temporarely ignored until the new SonarLintXmlReader will be used to access all properties.")] [DataTestMethod] [DataRow(GeneratedFileName, false)] [DataRow(OtherFileName, true)] @@ -116,11 +117,11 @@ public void ShouldAnalyzeTree_GeneratedFile_InvalidSonarLintXml(string fileName, // 1. Read -> no error sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); - sonarLintXml.ToStringCallCount.Should().Be(2); // should have attempted to read the file // TEMPORARILY BUMPED TO 2 + sonarLintXml.ToStringCallCount.Should().Be(1); // should have attempted to read the file // 2. Read again to check that the load error doesn't prevent caching from working sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); - sonarLintXml.ToStringCallCount.Should().Be(2); // should not have attempted to read the file again // TEMPORARILY BUMPED TO 2 + sonarLintXml.ToStringCallCount.Should().Be(1); // should not have attempted to read the file again } [DataTestMethod] @@ -135,6 +136,7 @@ public void ShouldAnalyzeTree_GeneratedFile_AnalyzeGenerated_AnalyzeAllFiles(str sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().BeTrue(); } + [Ignore("Temporarely ignored until the new SonarLintXmlReader will be used to access all properties.")] [DataTestMethod] [DataRow(GeneratedFileName, LanguageNames.CSharp, false)] [DataRow(OtherFileName, LanguageNames.CSharp, true)] From 08f4e00ee977fbfdcd8580dccd92a82e17c94992 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Tue, 7 Mar 2023 12:32:00 +0100 Subject: [PATCH 14/30] Addressed PR comments --- ...rAnalysisContextBaseTest.ShouldAnalyzeFile.cs | 8 ++++++++ ...rAnalysisContextBaseTest.ShouldAnalyzeTree.cs | 8 ++++---- .../TestFramework/AnalysisScaffolding.cs | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs index ba868d01163..90c39be474e 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs @@ -70,6 +70,14 @@ public partial class SonarAnalysisContextBaseTest public void ShouldAnalyzeFile_TestInclusions_ReturnExpected(string filePath, string[] testInclusions, ProjectType projectType, bool shouldAnalyze) => AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, testInclusions: testInclusions); + [DataTestMethod] + [DataRow("Foo", new string[] { "Foo" }, new string[] { "Foo" }, ProjectType.Product, false)] + [DataRow("Foo", new string[] { "NotFoo" }, new string[] { "Foo" }, ProjectType.Product, false)] + [DataRow("Foo", new string[] { "Foo" }, new string[] { "NotFoo" }, ProjectType.Product, true)] + [DataRow("Foo", new string[] { "NotFoo" }, new string[] { "NotFoo" }, ProjectType.Product, false)] + public void ShouldAnalyzeFile_MixedInput_ReturnExpected(string filePath, string[] inclusions, string[] exclusions, ProjectType projectType, bool shouldAnalyze) => + AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, inclusions: inclusions, exclusions: exclusions); + private void AssertShouldAnalyzeFile( string filePath, ProjectType projectType, diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index 0358e3a2d39..4460c45da6a 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -101,11 +101,11 @@ public void ShouldAnalyzeTree_GeneratedFile_ShouldAnalyzeGeneratedProvider_IsCac sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().BeTrue(); // GetText should be called every time ShouldAnalyzeGenerated is called... - additionalText.Verify(x => x.GetText(It.IsAny()), Times.Exactly(6)); // TEMPORARILY BUMPED TO 6 - sonarLintXml.ToStringCallCount.Should().Be(2); // ... but we should only try to read the file once // TEMPORARILY BUMPED TO 2 + additionalText.Verify(x => x.GetText(It.IsAny()), Times.Exactly(6)); // ToDo - reduce this number when SonarLintXmlReader will be used to access all properties. + sonarLintXml.ToStringCallCount.Should().Be(2); // ... but we should only try to read the file once // ToDo - reduce this number when SonarLintXmlReader will be used to access all properties. } - [Ignore("Temporarely ignored until the new SonarLintXmlReader will be used to access all properties.")] + [Ignore("Temporarely ignored until the new SonarLintXmlReader will be used to access all properties.")] // ToDo - remove this when SonarLintXmlReader will be used to access all properties. [DataTestMethod] [DataRow(GeneratedFileName, false)] [DataRow(OtherFileName, true)] @@ -136,7 +136,7 @@ public void ShouldAnalyzeTree_GeneratedFile_AnalyzeGenerated_AnalyzeAllFiles(str sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().BeTrue(); } - [Ignore("Temporarely ignored until the new SonarLintXmlReader will be used to access all properties.")] + [Ignore("Temporarely ignored until the new SonarLintXmlReader will be used to access all properties.")] // ToDo - remove this when SonarLintXmlReader will be used to access all properties. [DataTestMethod] [DataRow(GeneratedFileName, LanguageNames.CSharp, false)] [DataRow(OtherFileName, LanguageNames.CSharp, true)] diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs index 5f518397a40..e9d6159dfe3 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs @@ -91,7 +91,23 @@ public static string CreateSonarProjectConfigWithFilesToAnalyze(TestContext cont string[] testExclusions = null, string[] testInclusions = null, string[] globalTestExclusions = null) => +<<<<<<< HEAD TestHelper.WriteFile(context, "SonarLint.xml", GenerateSonarLintXmlContent(language, analyzeGeneratedCode, exclusions, inclusions, globalExclusions, testExclusions, testInclusions, globalTestExclusions)); +======= + TestHelper.WriteFile(context, "SonarLint.xml", + new XDocument( + new XDeclaration("1.0", "utf-8", "yes"), + new XElement("AnalysisInput", + new XElement("Settings", + CreateKeyValuePair("Setting", "sonar.cs.ignoreHeaderComments", ignoreHeaderComments.ToString()), + CreateKeyValuePair("Setting", "sonar.cs.analyzeGeneratedCode", analyzeGeneratedCode.ToString()), + CreateKeyValuePair("Setting", "sonar.exclusions", string.Join(",", exclusions ?? Array.Empty())), + CreateKeyValuePair("Setting", "sonar.inclusions", string.Join(",", inclusions ?? Array.Empty())), + CreateKeyValuePair("Setting", "sonar.global.exclusions", string.Join(",", globalExclusions ?? Array.Empty())), + CreateKeyValuePair("Setting", "sonar.test.exclusions", string.Join(",", testExclusions ?? Array.Empty())), + CreateKeyValuePair("Setting", "sonar.test.inclusions", string.Join(",", testInclusions ?? Array.Empty())), + CreateKeyValuePair("Setting", "sonar.global.test.exclusions", string.Join(",", globalTestExclusions ?? Array.Empty()))))).ToString()); +>>>>>>> 11aa64900 (Addressed PR comments) public static string GenerateSonarLintXmlContent( string language = LanguageNames.CSharp, From 9b8cb0bfc49698010d6f5c6f0aeba5a5e62364df Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Tue, 7 Mar 2023 14:01:29 +0100 Subject: [PATCH 15/30] Rebase UTs fix --- .../SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index 4460c45da6a..182ba3a6170 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -101,11 +101,10 @@ public void ShouldAnalyzeTree_GeneratedFile_ShouldAnalyzeGeneratedProvider_IsCac sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().BeTrue(); // GetText should be called every time ShouldAnalyzeGenerated is called... - additionalText.Verify(x => x.GetText(It.IsAny()), Times.Exactly(6)); // ToDo - reduce this number when SonarLintXmlReader will be used to access all properties. - sonarLintXml.ToStringCallCount.Should().Be(2); // ... but we should only try to read the file once // ToDo - reduce this number when SonarLintXmlReader will be used to access all properties. + additionalText.Verify(x => x.GetText(It.IsAny()), Times.Exactly(6)); + sonarLintXml.ToStringCallCount.Should().Be(1); // ... but we should only try to read the file once } - [Ignore("Temporarely ignored until the new SonarLintXmlReader will be used to access all properties.")] // ToDo - remove this when SonarLintXmlReader will be used to access all properties. [DataTestMethod] [DataRow(GeneratedFileName, false)] [DataRow(OtherFileName, true)] @@ -136,7 +135,6 @@ public void ShouldAnalyzeTree_GeneratedFile_AnalyzeGenerated_AnalyzeAllFiles(str sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().BeTrue(); } - [Ignore("Temporarely ignored until the new SonarLintXmlReader will be used to access all properties.")] // ToDo - remove this when SonarLintXmlReader will be used to access all properties. [DataTestMethod] [DataRow(GeneratedFileName, LanguageNames.CSharp, false)] [DataRow(OtherFileName, LanguageNames.CSharp, true)] From 00b4a641e4f64d49c3ca2e5b6dd99823fc942926 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Wed, 8 Mar 2023 09:33:30 +0100 Subject: [PATCH 16/30] Second round of comments --- .../SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs | 4 +++- .../TestFramework/AnalysisScaffolding.cs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs index 90c39be474e..7aad69f4d09 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs @@ -82,6 +82,7 @@ public partial class SonarAnalysisContextBaseTest string filePath, ProjectType projectType, bool shouldAnalyze, + string language = LanguageNames.CSharp, string[] exclusions = null, string[] inclusions = null, string[] globalExclusions = null, @@ -92,6 +93,7 @@ public partial class SonarAnalysisContextBaseTest var compilation = new SnippetCompiler("// Nothing to see here", TestHelper.ProjectTypeReference(projectType)).SemanticModel.Compilation; var sonarLintXml = AnalysisScaffolding.CreateSonarLintXml( TestContext, + language: language, exclusions: exclusions, inclusions: inclusions, globalExclusions: globalExclusions, @@ -102,6 +104,6 @@ public partial class SonarAnalysisContextBaseTest var options = AnalysisScaffolding.CreateOptions(sonarLintXml); var sut = CreateSut(compilation, options); - sut.ShouldAnalyzeFile(filePath).Should().Be(shouldAnalyze); + sut.ShouldAnalyzeFile(sut.SonarLintFile(), filePath).Should().Be(shouldAnalyze); } } diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs index e9d6159dfe3..1003e7b7a3b 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs @@ -99,8 +99,8 @@ <<<<<<< HEAD new XDeclaration("1.0", "utf-8", "yes"), new XElement("AnalysisInput", new XElement("Settings", - CreateKeyValuePair("Setting", "sonar.cs.ignoreHeaderComments", ignoreHeaderComments.ToString()), - CreateKeyValuePair("Setting", "sonar.cs.analyzeGeneratedCode", analyzeGeneratedCode.ToString()), + CreateKeyValuePair("Setting", $"sonar.{(language == LanguageNames.CSharp ? "cs" : "vbnet")}.ignoreHeaderComments", ignoreHeaderComments.ToString()), + CreateKeyValuePair("Setting", $"sonar.{(language == LanguageNames.CSharp ? "cs" : "vbnet")}.analyzeGeneratedCode", analyzeGeneratedCode.ToString()), CreateKeyValuePair("Setting", "sonar.exclusions", string.Join(",", exclusions ?? Array.Empty())), CreateKeyValuePair("Setting", "sonar.inclusions", string.Join(",", inclusions ?? Array.Empty())), CreateKeyValuePair("Setting", "sonar.global.exclusions", string.Join(",", globalExclusions ?? Array.Empty())), From 0a0e8a9c947cad17798399b2877a288a1edbdf0e Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Wed, 8 Mar 2023 09:59:04 +0100 Subject: [PATCH 17/30] Last UT fix (revert to previous values) --- .../SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index 182ba3a6170..c667b8898e2 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -101,7 +101,7 @@ public void ShouldAnalyzeTree_GeneratedFile_ShouldAnalyzeGeneratedProvider_IsCac sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().BeTrue(); // GetText should be called every time ShouldAnalyzeGenerated is called... - additionalText.Verify(x => x.GetText(It.IsAny()), Times.Exactly(6)); + additionalText.Verify(x => x.GetText(It.IsAny()), Times.Exactly(3)); sonarLintXml.ToStringCallCount.Should().Be(1); // ... but we should only try to read the file once } From bfb582b80da94c01ceab92a170234dd2cf75cb99 Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Wed, 8 Mar 2023 16:29:34 +0100 Subject: [PATCH 18/30] Migrated ShouldAnalyzeFile test case to ShouldAnalyzeTree --- ...alysisContextBaseTest.ShouldAnalyzeFile.cs | 109 ------------------ ...alysisContextBaseTest.ShouldAnalyzeTree.cs | 3 +- 2 files changed, 1 insertion(+), 111 deletions(-) delete mode 100644 analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs deleted file mode 100644 index 7aad69f4d09..00000000000 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeFile.cs +++ /dev/null @@ -1,109 +0,0 @@ -/* - * SonarAnalyzer for .NET - * Copyright (C) 2015-2023 SonarSource SA - * mailto: contact AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -namespace SonarAnalyzer.UnitTest.AnalysisContext; - -public partial class SonarAnalysisContextBaseTest -{ - [DataTestMethod] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, false)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, true)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] - public void ShouldAnalyzeFile_Exclusions_ReturnExpected(string filePath, string[] exclusions, ProjectType projectType, bool shouldAnalyze) => - AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, exclusions: exclusions); - - [DataTestMethod] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, false)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, true)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] - public void ShouldAnalyzeFile_GlobalExclusions_ReturnExpected(string filePath, string[] globalExclusions, ProjectType projectType, bool shouldAnalyze) => - AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, globalExclusions: globalExclusions); - - [DataTestMethod] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, false)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] - public void ShouldAnalyzeFile_TestExclusions_ReturnExpected(string filePath, string[] testExclusions, ProjectType projectType, bool shouldAnalyze) => - AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, testExclusions: testExclusions); - - [DataTestMethod] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, false)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] - public void ShouldAnalyzeFile_GlobalTestExclusions_ReturnExpected(string filePath, string[] globalTestExclusions, ProjectType projectType, bool shouldAnalyze) => - AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, globalTestExclusions: globalTestExclusions); - - [DataTestMethod] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, false)] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, true)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, true)] - public void ShouldAnalyzeFile_Inclusions_ReturnExpected(string filePath, string[] inclusions, ProjectType projectType, bool shouldAnalyze) => - AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, inclusions: inclusions); - - [DataTestMethod] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "Foo" }, ProjectType.Test, true)] - [DataRow("Foo", new string[] { "NotFoo" }, ProjectType.Test, false)] - public void ShouldAnalyzeFile_TestInclusions_ReturnExpected(string filePath, string[] testInclusions, ProjectType projectType, bool shouldAnalyze) => - AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, testInclusions: testInclusions); - - [DataTestMethod] - [DataRow("Foo", new string[] { "Foo" }, new string[] { "Foo" }, ProjectType.Product, false)] - [DataRow("Foo", new string[] { "NotFoo" }, new string[] { "Foo" }, ProjectType.Product, false)] - [DataRow("Foo", new string[] { "Foo" }, new string[] { "NotFoo" }, ProjectType.Product, true)] - [DataRow("Foo", new string[] { "NotFoo" }, new string[] { "NotFoo" }, ProjectType.Product, false)] - public void ShouldAnalyzeFile_MixedInput_ReturnExpected(string filePath, string[] inclusions, string[] exclusions, ProjectType projectType, bool shouldAnalyze) => - AssertShouldAnalyzeFile(filePath, projectType, shouldAnalyze, inclusions: inclusions, exclusions: exclusions); - - private void AssertShouldAnalyzeFile( - string filePath, - ProjectType projectType, - bool shouldAnalyze, - string language = LanguageNames.CSharp, - string[] exclusions = null, - string[] inclusions = null, - string[] globalExclusions = null, - string[] testExclusions = null, - string[] testInclusions = null, - string[] globalTestExclusions = null) - { - var compilation = new SnippetCompiler("// Nothing to see here", TestHelper.ProjectTypeReference(projectType)).SemanticModel.Compilation; - var sonarLintXml = AnalysisScaffolding.CreateSonarLintXml( - TestContext, - language: language, - exclusions: exclusions, - inclusions: inclusions, - globalExclusions: globalExclusions, - testExclusions: testExclusions, - testInclusions: testInclusions, - globalTestExclusions: - globalTestExclusions); - var options = AnalysisScaffolding.CreateOptions(sonarLintXml); - var sut = CreateSut(compilation, options); - - sut.ShouldAnalyzeFile(sut.SonarLintFile(), filePath).Should().Be(shouldAnalyze); - } -} diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index c667b8898e2..c9d16ec337f 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -80,7 +80,6 @@ public void ShouldAnalyzeTree_GeneratedFile_NoSonarLintXml(string fileName, bool var sonarLintXml = new DummySourceText(AnalysisScaffolding.GenerateSonarLintXmlContent(analyzeGeneratedCode: true)); var (compilation, tree) = CreateDummyCompilation(AnalyzerLanguage.CSharp, fileName); var sut = CreateSut(compilation, CreateOptions(sonarLintXml, @"ResourceTests\Foo.xml")); - sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); sonarLintXml.ToStringCallCount.Should().Be(0, "this file doesn't have 'SonarLint.xml' name"); } @@ -479,5 +478,5 @@ public override string ToString() public override void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) => throw new NotImplementedException(); + } } -} From ec95a4b18f075f7bc51e02510d9e4e2554da1c3f Mon Sep 17 00:00:00 2001 From: Cristian Ambrosini Date: Thu, 9 Mar 2023 08:37:24 +0100 Subject: [PATCH 19/30] Third wave of comments --- .../SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs index c9d16ec337f..c667b8898e2 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/AnalysisContext/SonarAnalysisContextBaseTest.ShouldAnalyzeTree.cs @@ -80,6 +80,7 @@ public void ShouldAnalyzeTree_GeneratedFile_NoSonarLintXml(string fileName, bool var sonarLintXml = new DummySourceText(AnalysisScaffolding.GenerateSonarLintXmlContent(analyzeGeneratedCode: true)); var (compilation, tree) = CreateDummyCompilation(AnalyzerLanguage.CSharp, fileName); var sut = CreateSut(compilation, CreateOptions(sonarLintXml, @"ResourceTests\Foo.xml")); + sut.ShouldAnalyzeTree(tree, CSharpGeneratedCodeRecognizer.Instance).Should().Be(expected); sonarLintXml.ToStringCallCount.Should().Be(0, "this file doesn't have 'SonarLint.xml' name"); } @@ -478,5 +479,5 @@ public override string ToString() public override void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count) => throw new NotImplementedException(); - } } +} From 3282762a52e19c02543201370a3015f4177b8492 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Wed, 8 Mar 2023 15:24:05 +0100 Subject: [PATCH 20/30] Add new test project --- .../SonarLintExclusions.sln | 31 +++++++++++++++++++ .../SonarLintExclusions/Excluded.cs | 7 +++++ .../SonarLintExclusions/Included.cs | 7 +++++ .../SonarLintExclusions.csproj | 7 +++++ .../SonarLintExclusionsTest/ExcludedTest.cs | 11 +++++++ .../SonarLintExclusionsTest/IncludedTest.cs | 11 +++++++ .../SonarLintExclusionsTest.csproj | 15 +++++++++ .../SonarLintExclusionsTest/Usings.cs | 1 + 8 files changed, 90 insertions(+) create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/Usings.cs diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln new file mode 100644 index 00000000000..0bfb21e7b93 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33417.168 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SonarLintExclusions", "SonarLintExclusions\SonarLintExclusions.csproj", "{F5D0F2AC-2BED-42AA-B219-674F970E8400}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SonarLintExclusionsTest", "SonarLintExclusionsTest\SonarLintExclusionsTest.csproj", "{0F14329D-7A71-489B-BB85-2B257A866429}" +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/Excluded.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs new file mode 100644 index 00000000000..42650d246f4 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs @@ -0,0 +1,7 @@ +namespace SonarLintExclusions +{ + public class Excluded + { + + } +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs new file mode 100644 index 00000000000..cfd1c413c9d --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs @@ -0,0 +1,7 @@ +namespace SonarLintExclusions +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj new file mode 100644 index 00000000000..8268829b64b --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj @@ -0,0 +1,7 @@ + + + + net7.0 + + + diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs new file mode 100644 index 00000000000..be15069d844 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs @@ -0,0 +1,11 @@ +namespace SonarLintExclusionsTest +{ + [TestClass] + public class ExcludedTest + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs new file mode 100644 index 00000000000..2c30dbcb823 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs @@ -0,0 +1,11 @@ +namespace SonarLintExclusionsTest +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} \ No newline at end of file diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj new file mode 100644 index 00000000000..56ac14f2805 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj @@ -0,0 +1,15 @@ + + + + net7.0 + false + + + + + + + + + + diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/Usings.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/Usings.cs new file mode 100644 index 00000000000..ab67c7ea9df --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/Usings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file From 1697c10d3a582b4e09184762e22297004a304f05 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Wed, 8 Mar 2023 15:29:02 +0100 Subject: [PATCH 21/30] set up SonarProjectType to unknown for sonarlint exclusion test --- analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets | 1 + analyzers/its/regression-test.ps1 | 3 ++- .../SonarLintExclusions/SonarLintExclusions.csproj | 1 + analyzers/its/sources/SonarLintExclusions/global.json | 6 ++++++ 4 files changed, 10 insertions(+), 1 deletion(-) 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..7d1086f8e5f 100644 --- a/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets +++ b/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets @@ -11,6 +11,7 @@ Product Test + Unknown 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/SonarLintExclusions.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj index 8268829b64b..3d0888e0cdb 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj @@ -2,6 +2,7 @@ net7.0 + true diff --git a/analyzers/its/sources/SonarLintExclusions/global.json b/analyzers/its/sources/SonarLintExclusions/global.json new file mode 100644 index 00000000000..c98e02ccaf8 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "7.0.100-rc.1.22431.12", + "rollForward": "latestMinor" + } +} \ No newline at end of file From eb353ffe408f5e537370898d1784857b01fe94df Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Wed, 8 Mar 2023 15:37:42 +0100 Subject: [PATCH 22/30] Add sonarlint exclusions config --- .../config/SonarLintExclusions/SonarLint.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 analyzers/its/config/SonarLintExclusions/SonarLint.xml diff --git a/analyzers/its/config/SonarLintExclusions/SonarLint.xml b/analyzers/its/config/SonarLintExclusions/SonarLint.xml new file mode 100644 index 00000000000..be73495ca5e --- /dev/null +++ b/analyzers/its/config/SonarLintExclusions/SonarLint.xml @@ -0,0 +1,19 @@ + + + + + + + sonar.cs.ignoreHeaderComments + true + + + sonar.vbnet.ignoreHeaderComments + true + + + sonar.exclusions + **/Exclude.cs + + + \ No newline at end of file From 91a137b0a64d01d9ef2d9dd77fa5b6f8c17c3fcc Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Wed, 8 Mar 2023 16:09:06 +0100 Subject: [PATCH 23/30] modify project to reflect test --- analyzers/its/config/SonarLintExclusions/SonarLint.xml | 2 +- .../sources/SonarLintExclusions/SonarLintExclusions.sln | 5 +++++ .../SonarLintExclusions/SonarLintExclusions/Excluded.cs | 4 ++-- .../SonarLintExclusions/SonarLintExclusions/Included.cs | 7 ++----- .../SonarLintExclusions/SonarLintExclusions.csproj | 3 +++ .../SonarLintExclusionsTest/ExcludedTest.cs | 7 +++---- .../SonarLintExclusionsTest/IncludedTest.cs | 7 +++---- .../SonarLintExclusions/SonarLintExclusionsTest/Usings.cs | 1 - 8 files changed, 19 insertions(+), 17 deletions(-) delete mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/Usings.cs diff --git a/analyzers/its/config/SonarLintExclusions/SonarLint.xml b/analyzers/its/config/SonarLintExclusions/SonarLint.xml index be73495ca5e..f11e308746e 100644 --- a/analyzers/its/config/SonarLintExclusions/SonarLint.xml +++ b/analyzers/its/config/SonarLintExclusions/SonarLint.xml @@ -13,7 +13,7 @@ sonar.exclusions - **/Exclude.cs + **/Excluded.cs \ No newline at end of file diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln index 0bfb21e7b93..9fbfa803571 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln @@ -7,6 +7,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SonarLintExclusions", "Sona EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "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 diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs index 42650d246f4..7f2cbb6efe6 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs @@ -1,7 +1,7 @@ namespace SonarLintExclusions { - public class Excluded + public static class Excluded { - + public static async void S3168() { } } } diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs index cfd1c413c9d..6fba906c697 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs @@ -1,7 +1,4 @@ namespace SonarLintExclusions { - public class Class1 - { - - } -} \ No newline at end of file + public class Included { } // S2094 +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj index 3d0888e0cdb..ba22c26e861 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj @@ -2,6 +2,9 @@ net7.0 + + + true diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs index be15069d844..a0ea4149813 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs @@ -1,11 +1,10 @@ -namespace SonarLintExclusionsTest +using Microsoft.VisualStudio.TestTools.UnitTesting; +namespace SonarLintExclusionsTest { [TestClass] public class ExcludedTest { [TestMethod] - public void TestMethod1() - { - } + public void TestMethod1() { } } } diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs index 2c30dbcb823..533c0cad22d 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs @@ -1,11 +1,10 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace SonarLintExclusionsTest { [TestClass] public class UnitTest1 { [TestMethod] - public void TestMethod1() - { - } + public void TestMethod1(){ } } -} \ No newline at end of file +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/Usings.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/Usings.cs deleted file mode 100644 index ab67c7ea9df..00000000000 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/Usings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file From a05d226cb8e6677bc7ddbd00b7562ffe3cb69248 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Wed, 8 Mar 2023 17:13:22 +0100 Subject: [PATCH 24/30] add exclusion for test project --- analyzers/its/config/SonarLintExclusions/SonarLint.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/analyzers/its/config/SonarLintExclusions/SonarLint.xml b/analyzers/its/config/SonarLintExclusions/SonarLint.xml index f11e308746e..59c36d4fa81 100644 --- a/analyzers/its/config/SonarLintExclusions/SonarLint.xml +++ b/analyzers/its/config/SonarLintExclusions/SonarLint.xml @@ -15,5 +15,9 @@ sonar.exclusions **/Excluded.cs + + sonar.test.exclusions + **/ExcludedTest.cs + \ No newline at end of file From 40e6cb469dc2fff06e48c9d22f4379b1f77ace06 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Thu, 9 Mar 2023 08:57:02 +0100 Subject: [PATCH 25/30] add explanation about SonarUnknownProjectType property --- analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets | 1 + .../SonarLintExclusions/SonarLintExclusions.csproj | 5 +---- .../SonarLintExclusionsTest/SonarLintExclusionsTest.csproj | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets b/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets index 7d1086f8e5f..ea85c04a441 100644 --- a/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets +++ b/analyzers/its/SonarAnalyzer.Testing.ImportBefore.targets @@ -11,6 +11,7 @@ Product Test + Unknown diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj index ba22c26e861..15297210401 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/SonarLintExclusions.csproj @@ -2,10 +2,7 @@ net7.0 - - - true - + diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj index 56ac14f2805..0af8506579f 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj @@ -3,6 +3,7 @@ net7.0 false + true From 520ee39e762f702a3faa5e2ef19db193f62b023d Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Thu, 9 Mar 2023 13:39:38 +0100 Subject: [PATCH 26/30] fix project to test all SL parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Čaba Šagi <75226367+csaba-sagi-sonarsource@users.noreply.github.com> --- .../config/SonarLintExclusions/SonarLint.xml | 10 ++++++- .../SonarLintExclusions--net7.0-S1186.json | 17 +++++++++++ .../SonarLintExclusions--net7.0-S2094.json | 17 +++++++++++ .../SonarLintExclusions--net7.0-S3168.json | 17 +++++++++++ .../SonarLintExclusions--net7.0-S3990.json | 9 ++++++ .../SonarLintExclusions--net7.0-S3992.json | 9 ++++++ ...SonarLintExclusionsTest--net7.0-S2699.json | 30 +++++++++++++++++++ .../SonarLintExclusions.sln | 4 +-- .../SonarLintExclusions/Excluded.cs | 7 ----- .../Included/ExcludedByExclusion.cs | 4 +++ .../Included/ExcludedByGlobalExclusion.cs | 4 +++ .../{ => Included}/Included.cs | 0 .../SonarLintExclusions/NotIncluded.cs | 12 ++++++++ .../Exclude1.cs | 7 +++++ .../Exclude2.cs | 7 +++++ .../Exclude3.cs | 7 +++++ .../Include.cs | 7 +++++ ...SonarLintExclusionsExcludeAllButOne.csproj | 9 ++++++ 18 files changed, 167 insertions(+), 10 deletions(-) create mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S1186.json create mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json create mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3168.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 delete mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByGlobalExclusion.cs rename analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/{ => Included}/Included.cs (100%) create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude1.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude2.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude3.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Include.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/SonarLintExclusionsExcludeAllButOne.csproj diff --git a/analyzers/its/config/SonarLintExclusions/SonarLint.xml b/analyzers/its/config/SonarLintExclusions/SonarLint.xml index 59c36d4fa81..e42d6158029 100644 --- a/analyzers/its/config/SonarLintExclusions/SonarLint.xml +++ b/analyzers/its/config/SonarLintExclusions/SonarLint.xml @@ -11,9 +11,17 @@ sonar.vbnet.ignoreHeaderComments true + + sonar.inclusions + **/Included/*.cs + sonar.exclusions - **/Excluded.cs + **/ExcludedByExclusion.cs + + + sonar.global.exclusions + **/ExcludedByGlobalExclusion.cs sonar.test.exclusions diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S1186.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S1186.json new file mode 100644 index 00000000000..37edd4c9141 --- /dev/null +++ b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S1186.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S1186", +"message": "Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation.", +"location": { +"uri": "sources\SonarLintExclusions\SonarLintExclusions\Excluded.cs", +"region": { +"startLine": 5, +"startColumn": 34, +"endLine": 5, +"endColumn": 39 +} +} +} +] +} 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..0c32aed49c8 --- /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.cs", +"region": { +"startLine": 3, +"startColumn": 18, +"endLine": 3, +"endColumn": 26 +} +} +} +] +} diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3168.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3168.json new file mode 100644 index 00000000000..baa65b0af7f --- /dev/null +++ b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3168.json @@ -0,0 +1,17 @@ +{ +"issues": [ +{ +"id": "S3168", +"message": "Return 'Task' instead.", +"location": { +"uri": "sources\SonarLintExclusions\SonarLintExclusions\Excluded.cs", +"region": { +"startLine": 5, +"startColumn": 29, +"endLine": 5, +"endColumn": 33 +} +} +} +] +} 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..eec43ac315c --- /dev/null +++ b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusionsTest--net7.0-S2699.json @@ -0,0 +1,30 @@ +{ +"issues": [ +{ +"id": "S2699", +"message": "Add at least one assertion to this test case.", +"location": { +"uri": "sources\SonarLintExclusions\SonarLintExclusionsTest\ExcludedTest.cs", +"region": { +"startLine": 8, +"startColumn": 21, +"endLine": 8, +"endColumn": 32 +} +} +}, +{ +"id": "S2699", +"message": "Add at least one assertion to this test case.", +"location": { +"uri": "sources\SonarLintExclusions\SonarLintExclusionsTest\IncludedTest.cs", +"region": { +"startLine": 8, +"startColumn": 21, +"endLine": 8, +"endColumn": 32 +} +} +} +] +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln index 9fbfa803571..3e5bcbbe34b 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions.sln @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.6.33417.168 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SonarLintExclusions", "SonarLintExclusions\SonarLintExclusions.csproj", "{F5D0F2AC-2BED-42AA-B219-674F970E8400}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SonarLintExclusions", "SonarLintExclusions\SonarLintExclusions.csproj", "{F5D0F2AC-2BED-42AA-B219-674F970E8400}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SonarLintExclusionsTest", "SonarLintExclusionsTest\SonarLintExclusionsTest.csproj", "{0F14329D-7A71-489B-BB85-2B257A866429}" +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 diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs deleted file mode 100644 index 7f2cbb6efe6..00000000000 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Excluded.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SonarLintExclusions -{ - public static class Excluded - { - public static async void S3168() { } - } -} 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/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.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/Included.cs similarity index 100% rename from analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included.cs rename to analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/Included.cs diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs new file mode 100644 index 00000000000..a2cf83557c4 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SonarLintExclusions +{ + internal class NotIncluded + { + } +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude1.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude1.cs new file mode 100644 index 00000000000..61e1bcc6218 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude1.cs @@ -0,0 +1,7 @@ +namespace SonarLintExclusionsExcludeAllButOne +{ + public class Exclude1 + { + + } +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude2.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude2.cs new file mode 100644 index 00000000000..5955a0757a4 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude2.cs @@ -0,0 +1,7 @@ +namespace SonarLintExclusionsExcludeAllButOne +{ + public class Exclude2 + { + + } +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude3.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude3.cs new file mode 100644 index 00000000000..52d821f0b4b --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude3.cs @@ -0,0 +1,7 @@ +namespace SonarLintExclusionsExcludeAllButOne +{ + public class Exclude3 + { + + } +} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Include.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Include.cs new file mode 100644 index 00000000000..5946d1c42fc --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Include.cs @@ -0,0 +1,7 @@ +namespace SonarLintExclusionsExcludeAllButOne +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/SonarLintExclusionsExcludeAllButOne.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/SonarLintExclusionsExcludeAllButOne.csproj new file mode 100644 index 00000000000..132c02c59c2 --- /dev/null +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/SonarLintExclusionsExcludeAllButOne.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + From 7fe2b2943e4f5c53bd1077238b8bc6ea5087076f Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Thu, 9 Mar 2023 16:49:08 +0100 Subject: [PATCH 27/30] update expected --- .../SonarLintExclusions--net7.0-S1186.json | 17 ----------- .../SonarLintExclusions--net7.0-S2094.json | 17 ----------- .../SonarLintExclusions--net7.0-S3168.json | 17 ----------- .../SonarLintExclusions--net7.0-S3990.json | 9 ------ .../SonarLintExclusions--net7.0-S3992.json | 9 ------ ...SonarLintExclusionsTest--net7.0-S2699.json | 30 ------------------- .../Exclude1.cs | 7 ----- .../Exclude2.cs | 7 ----- .../Exclude3.cs | 7 ----- .../Include.cs | 7 ----- ...SonarLintExclusionsExcludeAllButOne.csproj | 9 ------ .../TestFramework/AnalysisScaffolding.cs | 16 ---------- 12 files changed, 152 deletions(-) delete mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S1186.json delete mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json delete mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3168.json delete mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json delete mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3992.json delete mode 100644 analyzers/its/expected/SonarLintExclusions/SonarLintExclusionsTest--net7.0-S2699.json delete mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude1.cs delete mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude2.cs delete mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude3.cs delete mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Include.cs delete mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/SonarLintExclusionsExcludeAllButOne.csproj diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S1186.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S1186.json deleted file mode 100644 index 37edd4c9141..00000000000 --- a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S1186.json +++ /dev/null @@ -1,17 +0,0 @@ -{ -"issues": [ -{ -"id": "S1186", -"message": "Add a nested comment explaining why this method is empty, throw a 'NotSupportedException' or complete the implementation.", -"location": { -"uri": "sources\SonarLintExclusions\SonarLintExclusions\Excluded.cs", -"region": { -"startLine": 5, -"startColumn": 34, -"endLine": 5, -"endColumn": 39 -} -} -} -] -} diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json deleted file mode 100644 index 0c32aed49c8..00000000000 --- a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S2094.json +++ /dev/null @@ -1,17 +0,0 @@ -{ -"issues": [ -{ -"id": "S2094", -"message": "Remove this empty class, write its code or make it an "interface".", -"location": { -"uri": "sources\SonarLintExclusions\SonarLintExclusions\Included.cs", -"region": { -"startLine": 3, -"startColumn": 18, -"endLine": 3, -"endColumn": 26 -} -} -} -] -} diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3168.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3168.json deleted file mode 100644 index baa65b0af7f..00000000000 --- a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3168.json +++ /dev/null @@ -1,17 +0,0 @@ -{ -"issues": [ -{ -"id": "S3168", -"message": "Return 'Task' instead.", -"location": { -"uri": "sources\SonarLintExclusions\SonarLintExclusions\Excluded.cs", -"region": { -"startLine": 5, -"startColumn": 29, -"endLine": 5, -"endColumn": 33 -} -} -} -] -} diff --git a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json b/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json deleted file mode 100644 index 17786f2ed3f..00000000000 --- a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3990.json +++ /dev/null @@ -1,9 +0,0 @@ -{ -"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 deleted file mode 100644 index dfd144e2a2e..00000000000 --- a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusions--net7.0-S3992.json +++ /dev/null @@ -1,9 +0,0 @@ -{ -"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 deleted file mode 100644 index eec43ac315c..00000000000 --- a/analyzers/its/expected/SonarLintExclusions/SonarLintExclusionsTest--net7.0-S2699.json +++ /dev/null @@ -1,30 +0,0 @@ -{ -"issues": [ -{ -"id": "S2699", -"message": "Add at least one assertion to this test case.", -"location": { -"uri": "sources\SonarLintExclusions\SonarLintExclusionsTest\ExcludedTest.cs", -"region": { -"startLine": 8, -"startColumn": 21, -"endLine": 8, -"endColumn": 32 -} -} -}, -{ -"id": "S2699", -"message": "Add at least one assertion to this test case.", -"location": { -"uri": "sources\SonarLintExclusions\SonarLintExclusionsTest\IncludedTest.cs", -"region": { -"startLine": 8, -"startColumn": 21, -"endLine": 8, -"endColumn": 32 -} -} -} -] -} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude1.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude1.cs deleted file mode 100644 index 61e1bcc6218..00000000000 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SonarLintExclusionsExcludeAllButOne -{ - public class Exclude1 - { - - } -} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude2.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude2.cs deleted file mode 100644 index 5955a0757a4..00000000000 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude2.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SonarLintExclusionsExcludeAllButOne -{ - public class Exclude2 - { - - } -} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude3.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude3.cs deleted file mode 100644 index 52d821f0b4b..00000000000 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Exclude3.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SonarLintExclusionsExcludeAllButOne -{ - public class Exclude3 - { - - } -} diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Include.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Include.cs deleted file mode 100644 index 5946d1c42fc..00000000000 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/Include.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SonarLintExclusionsExcludeAllButOne -{ - public class Class1 - { - - } -} \ No newline at end of file diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/SonarLintExclusionsExcludeAllButOne.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/SonarLintExclusionsExcludeAllButOne.csproj deleted file mode 100644 index 132c02c59c2..00000000000 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsExcludeAllButOne/SonarLintExclusionsExcludeAllButOne.csproj +++ /dev/null @@ -1,9 +0,0 @@ - - - - net6.0 - enable - enable - - - diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs b/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs index 1003e7b7a3b..5f518397a40 100644 --- a/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs +++ b/analyzers/tests/SonarAnalyzer.UnitTest/TestFramework/AnalysisScaffolding.cs @@ -91,23 +91,7 @@ public static string CreateSonarProjectConfigWithFilesToAnalyze(TestContext cont string[] testExclusions = null, string[] testInclusions = null, string[] globalTestExclusions = null) => -<<<<<<< HEAD TestHelper.WriteFile(context, "SonarLint.xml", GenerateSonarLintXmlContent(language, analyzeGeneratedCode, exclusions, inclusions, globalExclusions, testExclusions, testInclusions, globalTestExclusions)); -======= - TestHelper.WriteFile(context, "SonarLint.xml", - new XDocument( - new XDeclaration("1.0", "utf-8", "yes"), - new XElement("AnalysisInput", - new XElement("Settings", - CreateKeyValuePair("Setting", $"sonar.{(language == LanguageNames.CSharp ? "cs" : "vbnet")}.ignoreHeaderComments", ignoreHeaderComments.ToString()), - CreateKeyValuePair("Setting", $"sonar.{(language == LanguageNames.CSharp ? "cs" : "vbnet")}.analyzeGeneratedCode", analyzeGeneratedCode.ToString()), - CreateKeyValuePair("Setting", "sonar.exclusions", string.Join(",", exclusions ?? Array.Empty())), - CreateKeyValuePair("Setting", "sonar.inclusions", string.Join(",", inclusions ?? Array.Empty())), - CreateKeyValuePair("Setting", "sonar.global.exclusions", string.Join(",", globalExclusions ?? Array.Empty())), - CreateKeyValuePair("Setting", "sonar.test.exclusions", string.Join(",", testExclusions ?? Array.Empty())), - CreateKeyValuePair("Setting", "sonar.test.inclusions", string.Join(",", testInclusions ?? Array.Empty())), - CreateKeyValuePair("Setting", "sonar.global.test.exclusions", string.Join(",", globalTestExclusions ?? Array.Empty()))))).ToString()); ->>>>>>> 11aa64900 (Addressed PR comments) public static string GenerateSonarLintXmlContent( string language = LanguageNames.CSharp, From cb07cf7e76646031ebccce45c9cc5b6037a0abe9 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Thu, 9 Mar 2023 17:24:26 +0100 Subject: [PATCH 28/30] test all parameters also for test project --- .../SonarLintExclusions--net7.0-S2094.json | 17 +++++++++++++++++ .../SonarLintExclusions--net7.0-S3990.json | 9 +++++++++ .../SonarLintExclusions--net7.0-S3992.json | 9 +++++++++ .../SonarLintExclusionsTest--net7.0-S2699.json | 17 +++++++++++++++++ .../IncludedTest/ExcludedByExclusionTest.cs | 10 ++++++++++ .../ExcludedByGlobalExclusionTest.cs | 10 ++++++++++ .../IncludedTest.cs} | 2 +- .../{IncludedTest.cs => NotIncludedTest.cs} | 4 ++-- 8 files changed, 75 insertions(+), 3 deletions(-) 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/SonarLintExclusionsTest/IncludedTest/ExcludedByExclusionTest.cs create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/ExcludedByGlobalExclusionTest.cs rename analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/{ExcludedTest.cs => IncludedTest/IncludedTest.cs} (85%) rename analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/{IncludedTest.cs => NotIncludedTest.cs} (66%) 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/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/ExcludedTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/IncludedTest.cs similarity index 85% rename from analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs rename to analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/IncludedTest.cs index a0ea4149813..cc364afdccc 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/ExcludedTest.cs +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest/IncludedTest.cs @@ -2,7 +2,7 @@ namespace SonarLintExclusionsTest { [TestClass] - public class ExcludedTest + public class IncludedTest { [TestMethod] public void TestMethod1() { } diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/NotIncludedTest.cs similarity index 66% rename from analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs rename to analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/NotIncludedTest.cs index 533c0cad22d..8b81a00464c 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/IncludedTest.cs +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/NotIncludedTest.cs @@ -2,9 +2,9 @@ namespace SonarLintExclusionsTest { [TestClass] - public class UnitTest1 + public class NotIncludedTest { [TestMethod] - public void TestMethod1(){ } + public void TestMethod1() { } } } From c31ba4f068200a53ebdfeed19be8ef24361b4c82 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Thu, 9 Mar 2023 17:35:37 +0100 Subject: [PATCH 29/30] fix sonarlint xml --- .../its/config/SonarLintExclusions/SonarLint.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/analyzers/its/config/SonarLintExclusions/SonarLint.xml b/analyzers/its/config/SonarLintExclusions/SonarLint.xml index e42d6158029..685a79d1666 100644 --- a/analyzers/its/config/SonarLintExclusions/SonarLint.xml +++ b/analyzers/its/config/SonarLintExclusions/SonarLint.xml @@ -23,9 +23,18 @@ sonar.global.exclusions **/ExcludedByGlobalExclusion.cs + + + sonar.test.inclusions + **/IncludedTest/*.cs + sonar.test.exclusions - **/ExcludedTest.cs + **/ExcludedByExclusionTest.cs + + + sonar.global.test.exclusions + **/ExcludedByGlobalExclusionTest.cs \ No newline at end of file From 73f20d3e387a3a31c3ac69a3a478ac9aff52ee61 Mon Sep 17 00:00:00 2001 From: mary-georgiou-sonarsource Date: Fri, 10 Mar 2023 13:40:52 +0100 Subject: [PATCH 30/30] apply comments --- .../its/config/SonarLintExclusions/SonarLint.xml | 2 +- .../Included/ExcludedByExclusion2.cs | 4 ++++ .../SonarLintExclusions/NotIncluded.cs | 12 ++---------- .../SonarLintExclusionsTest.csproj | 1 - .../its/sources/SonarLintExclusions/global.json | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) create mode 100644 analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/Included/ExcludedByExclusion2.cs diff --git a/analyzers/its/config/SonarLintExclusions/SonarLint.xml b/analyzers/its/config/SonarLintExclusions/SonarLint.xml index 685a79d1666..be8726ef80a 100644 --- a/analyzers/its/config/SonarLintExclusions/SonarLint.xml +++ b/analyzers/its/config/SonarLintExclusions/SonarLint.xml @@ -17,7 +17,7 @@ sonar.exclusions - **/ExcludedByExclusion.cs + **/ExcludedByExclusion.cs,**/ExcludedByExclusion2.cs sonar.global.exclusions 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/NotIncluded.cs b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs index a2cf83557c4..95a9911ce76 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusions/NotIncluded.cs @@ -1,12 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SonarLintExclusions +namespace SonarLintExclusions { - internal class NotIncluded - { - } + public class NotIncluded { } // S2094 } diff --git a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj index 0af8506579f..0d99fb1aff7 100644 --- a/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj +++ b/analyzers/its/sources/SonarLintExclusions/SonarLintExclusionsTest/SonarLintExclusionsTest.csproj @@ -10,7 +10,6 @@ - diff --git a/analyzers/its/sources/SonarLintExclusions/global.json b/analyzers/its/sources/SonarLintExclusions/global.json index c98e02ccaf8..4037c7755e7 100644 --- a/analyzers/its/sources/SonarLintExclusions/global.json +++ b/analyzers/its/sources/SonarLintExclusions/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.100-rc.1.22431.12", + "version": "7.0.100", "rollForward": "latestMinor" } } \ No newline at end of file