diff --git a/analyzers/its/sources/AnalyzeGenerated.CS/SonarLint.xml b/analyzers/its/sources/AnalyzeGenerated.CS/SonarLint.xml
deleted file mode 100644
index 15dbb76706c..00000000000
--- a/analyzers/its/sources/AnalyzeGenerated.CS/SonarLint.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
- sonar.cs.ignoreHeaderComments
- true
-
-
- sonar.cs.analyzeGeneratedCode
- true
-
-
- sonar.cs.file.suffixes
- .cs
-
-
-
-
- S1067
-
-
- max
- 1
-
-
-
-
-
-
-
diff --git a/analyzers/its/sources/SkipGenerated.CS/SonarLint.xml b/analyzers/its/sources/SkipGenerated.CS/SonarLint.xml
deleted file mode 100644
index b99df9c60f6..00000000000
--- a/analyzers/its/sources/SkipGenerated.CS/SonarLint.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
- sonar.cs.ignoreHeaderComments
- true
-
-
- sonar.cs.analyzeGeneratedCode
- false
-
-
- sonar.cs.file.suffixes
- .cs
-
-
-
-
- S1067
-
-
- max
- 1
-
-
-
-
-
-
-
diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/ParameterLoaderTest.cs b/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/ParameterLoaderTest.cs
index 5ed1026cd73..fb9a2ff026c 100644
--- a/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/ParameterLoaderTest.cs
+++ b/analyzers/tests/SonarAnalyzer.UnitTest/Helpers/ParameterLoaderTest.cs
@@ -34,7 +34,7 @@ public class ParameterLoaderTest
[TestMethod]
[DataRow("path//aSonarLint.xml")] // different name
[DataRow("path//SonarLint.xmla")] // different extension
- public void SetParameterValues_WhenNoSonarLintIsGiven_DoesNotPopulateParameters(string filePath)
+ public void SetParameterValues_WithInvalidSonarLintPath_DoesNotPopulateParameters(string filePath)
{
// Arrange
var compilation = CreateCompilationWithOption(filePath, SourceText.From(File.ReadAllText("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml")));
@@ -50,7 +50,7 @@ public void SetParameterValues_WhenNoSonarLintIsGiven_DoesNotPopulateParameters(
[TestMethod]
[DataRow("a/SonarLint.xml")] // unix path
[DataRow("a\\SonarLint.xml")]
- public void SetParameterValues_WhenGivenValidSonarLintFilePath_PopulatesProperties(string filePath)
+ public void SetParameterValues_WithValidSonarLintPath_PopulatesProperties(string filePath)
{
// Arrange
var compilation = CreateCompilationWithOption(filePath, SourceText.From(File.ReadAllText("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml")));
@@ -64,7 +64,7 @@ public void SetParameterValues_WhenGivenValidSonarLintFilePath_PopulatesProperti
}
[TestMethod]
- public void SetParameterValues_WhenGivenSonarLintFileHasIntParameterType_PopulatesProperties()
+ public void SetParameterValues_SonarLintFileWithIntParameterType_PopulatesProperties()
{
// Arrange
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml");
@@ -78,35 +78,39 @@ public void SetParameterValues_WhenGivenSonarLintFileHasIntParameterType_Populat
}
[TestMethod]
- public void SetParameterValues_WhenGivenSonarLintFileHasStringParameterType_OnlyOneParameter_PopulatesProperty()
+ public void SetParameterValues_SonarLintFileWithStringParameterType_PopulatesProperty()
{
// Arrange
- var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\RuleWithStringParameter\\SonarLint.xml");
+ var parameterValue = "1";
+ var filePath = GenerateSonarLintXmlWithParametrizedRule("S2342", "flagsAttributeFormat", parameterValue);
+ var compilation = CreateCompilationWithOption(filePath);
var analyzer = new EnumNameShouldFollowRegex(); // Cannot use mock because we use reflection to find properties.
// Act
ParameterLoader.SetParameterValues(analyzer, compilation.SonarLintFile());
// Assert
- analyzer.FlagsEnumNamePattern.Should().Be("1"); // value from XML file
+ analyzer.FlagsEnumNamePattern.Should().Be(parameterValue); // value from XML file
}
[TestMethod]
- public void SetParameterValues_WhenGivenSonarLintFileHasBooleanParameterType_OnlyOneParameter_PopulatesProperty()
+ public void SetParameterValues_SonarLintFileWithBooleanParameterType_PopulatesProperty()
{
// Arrange
- var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\RuleWithBooleanParameter\\SonarLint.xml");
+ var parameterValue = true;
+ var filePath = GenerateSonarLintXmlWithParametrizedRule("S1451", "isRegularExpression", parameterValue.ToString());
+ var compilation = CreateCompilationWithOption(filePath);
var analyzer = new CheckFileLicense(); // Cannot use mock because we use reflection to find properties.
// Act
ParameterLoader.SetParameterValues(analyzer, compilation.SonarLintFile());
// Assert
- analyzer.IsRegularExpression.Should().BeTrue(); // value from XML file
+ analyzer.IsRegularExpression.Should().Be(parameterValue); // value from XML file
}
[TestMethod]
- public void SetParameterValues_WhenGivenValidSonarLintFileAndDoesNotContainAnalyzerParameters_DoesNotPopulateProperties()
+ public void SetParameterValues_SonarLintFileWithoutRuleParameters_DoesNotPopulateProperties()
{
// Arrange
var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\All_properties_cs\\SonarLint.xml");
@@ -177,10 +181,12 @@ public void SetParameterValues_WithMalformedXml_DoesNotPopulateProperties(string
}
[TestMethod]
- public void SetParameterValues_WithWrongPropertyType_StringInsteadOfInt_DoesNotPopulateProperties()
+ public void SetParameterValues_SonarLintFileWithStringInsteadOfIntParameterType_PopulatesProperty()
{
// Arrange
- var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\StringInsteadOfInt\\SonarLint.xml");
+ var parameterValue = "fooBar";
+ var filePath = GenerateSonarLintXmlWithParametrizedRule("S1067", "max", parameterValue);
+ var compilation = CreateCompilationWithOption(filePath);
var analyzer = new ExpressionComplexity(); // Cannot use mock because we use reflection to find properties.
// Act
@@ -191,10 +197,12 @@ public void SetParameterValues_WithWrongPropertyType_StringInsteadOfInt_DoesNotP
}
[TestMethod]
- public void SetParameterValues_WithWrongPropertyType_StringInsteadOfBoolean_DoesNotPopulateProperties()
+ public void SetParameterValues_SonarLintFileWithStringInsteadOfBooleanParameterType_PopulatesProperty()
{
// Arrange
- var compilation = CreateCompilationWithOption("ResourceTests\\SonarLintXml\\StringInsteadOfBoolean\\SonarLint.xml");
+ var parameterValue = "fooBar";
+ var filePath = GenerateSonarLintXmlWithParametrizedRule("S1451", "isRegularExpression", parameterValue);
+ var compilation = CreateCompilationWithOption(filePath);
var analyzer = new CheckFileLicense(); // Cannot use mock because we use reflection to find properties.
// Act
@@ -213,5 +221,25 @@ private static SonarCompilationReportingContext CreateCompilationWithOption(stri
var compilationContext = new CompilationAnalysisContext(compilation, options, _ => { }, _ => true, default);
return new(AnalysisScaffolding.CreateSonarAnalysisContext(), compilationContext);
}
+
+ private string GenerateSonarLintXmlWithParametrizedRule(string ruleId, string key, string value)
+ {
+ var ruleParameters = new List()
+ {
+ new SonarLintXmlRule()
+ {
+ Key = ruleId,
+ Parameters = new List()
+ {
+ new SonarLintXmlKeyValuePair()
+ {
+ Key = key,
+ Value = value
+ }
+ }
+ }
+ };
+ return AnalysisScaffolding.CreateSonarLintXml(TestContext, rulesParameters: ruleParameters);
+ }
}
}
diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/RuleWithBooleanParameter/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/RuleWithBooleanParameter/SonarLint.xml
deleted file mode 100644
index 4170e60a90a..00000000000
--- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/RuleWithBooleanParameter/SonarLint.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
- sonar.cs.ignoreHeaderComments
- true
-
-
- sonar.cs.analyzeGeneratedCode
- false
-
-
- sonar.cs.file.suffixes
- .cs
-
-
-
-
- S1451
-
-
- isRegularExpression
- true
-
-
-
-
-
-
-
diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/RuleWithStringParameter/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/RuleWithStringParameter/SonarLint.xml
deleted file mode 100644
index d45ac7addb5..00000000000
--- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/RuleWithStringParameter/SonarLint.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
- sonar.cs.ignoreHeaderComments
- true
-
-
- sonar.cs.analyzeGeneratedCode
- false
-
-
- sonar.cs.file.suffixes
- .cs
-
-
-
-
- S2342
-
-
- flagsAttributeFormat
- 1
-
-
-
-
-
-
-
diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/StringInsteadOfBoolean/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/StringInsteadOfBoolean/SonarLint.xml
deleted file mode 100644
index 913b8886a2d..00000000000
--- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/StringInsteadOfBoolean/SonarLint.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
- sonar.cs.ignoreHeaderComments
- true
-
-
- sonar.cs.analyzeGeneratedCode
- false
-
-
- sonar.cs.file.suffixes
- .cs
-
-
-
-
- S1451
-
-
- isRegularExpression
- fooBar
-
-
-
-
-
-
-
diff --git a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/StringInsteadOfInt/SonarLint.xml b/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/StringInsteadOfInt/SonarLint.xml
deleted file mode 100644
index 4596b44be4b..00000000000
--- a/analyzers/tests/SonarAnalyzer.UnitTest/ResourceTests/SonarLintXml/StringInsteadOfInt/SonarLint.xml
+++ /dev/null
@@ -1,30 +0,0 @@
-
-
-
-
- sonar.cs.ignoreHeaderComments
- true
-
-
- sonar.cs.analyzeGeneratedCode
- false
-
-
- sonar.cs.file.suffixes
- .cs
-
-
-
-
- S1067
-
-
- max
- fooBar
-
-
-
-
-
-
-