Skip to content

Commit 00ecc1e

Browse files
pavel-mikula-sonarsourcesonartech
authored andcommitted
NET-879 Cleanup EditorConfigGenerator
1 parent e02c25d commit 00ecc1e

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

analyzers/tests/SonarAnalyzer.TestFramework.Test/Common/EditorConfigGeneratorTest.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ public void GenerateEditorConfig_EmptyCollection_ValidEditorConfig()
5252
{
5353
var rootPath = "C:/Users/Johnny/source/repos/WebApplication";
5454
var editorConfig = new EditorConfigGenerator(rootPath).Generate([]);
55-
editorConfig.Should().Be(
56-
$"""
57-
is_global = true
58-
""".Replace("\n", Environment.NewLine));
55+
editorConfig.Should().Be("is_global = true");
5956
}
6057

6158
[TestMethod]
@@ -64,12 +61,11 @@ public void GenerateEditorConfig_SingleFile_ValidEditorConfig()
6461
var rootPath = "C:/Users/Johnny/source/repos/WebApplication";
6562
var razorFile = "C:/Users/Johnny/source/repos/WebApplication/Component.razor";
6663
var editorConfig = new EditorConfigGenerator(rootPath).Generate([razorFile]);
67-
editorConfig.Should().Be(
68-
$"""
69-
is_global = true
70-
[C:/Users/Johnny/source/repos/WebApplication/Component.razor]
71-
build_metadata.AdditionalFiles.TargetPath = Q29tcG9uZW50LnJhem9y
72-
""".Replace("\n", Environment.NewLine));
64+
editorConfig.Should().BeIgnoringLineEndings("""
65+
is_global = true
66+
[C:/Users/Johnny/source/repos/WebApplication/Component.razor]
67+
build_metadata.AdditionalFiles.TargetPath = Q29tcG9uZW50LnJhem9y
68+
""");
7369
}
7470

7571
[TestMethod]
@@ -83,16 +79,15 @@ public void GenerateEditorConfig_MultipleFiles_ValidEditorConfig()
8379
"C:/Users/Johnny/source/repos/Parent.razor"
8480
};
8581
var editorConfig = new EditorConfigGenerator(rootPath).Generate(razorFiles);
86-
editorConfig.Should().Be(
87-
$"""
88-
is_global = true
89-
[C:/Users/Johnny/source/repos/WebApplication/Component.razor]
90-
build_metadata.AdditionalFiles.TargetPath = Q29tcG9uZW50LnJhem9y
91-
[C:/Users/Johnny/source/repos/WebApplication/Folder/Child.razor]
92-
build_metadata.AdditionalFiles.TargetPath = Rm9sZGVyXENoaWxkLnJhem9y
93-
[C:/Users/Johnny/source/repos/Parent.razor]
94-
build_metadata.AdditionalFiles.TargetPath = Li5cUGFyZW50LnJhem9y
95-
""".Replace("\n", Environment.NewLine));
82+
editorConfig.Should().BeIgnoringLineEndings("""
83+
is_global = true
84+
[C:/Users/Johnny/source/repos/WebApplication/Component.razor]
85+
build_metadata.AdditionalFiles.TargetPath = Q29tcG9uZW50LnJhem9y
86+
[C:/Users/Johnny/source/repos/WebApplication/Folder/Child.razor]
87+
build_metadata.AdditionalFiles.TargetPath = Rm9sZGVyXENoaWxkLnJhem9y
88+
[C:/Users/Johnny/source/repos/Parent.razor]
89+
build_metadata.AdditionalFiles.TargetPath = Li5cUGFyZW50LnJhem9y
90+
""");
9691
}
9792

9893
[TestMethod]
@@ -117,8 +112,7 @@ public void GenerateEditorConfig_EmptyFile_Throws(string element)
117112
public void GenerateEditorConfig_MixedFiles_Throws()
118113
{
119114
var rootPath = "C:/Users/Johnny/source/repos/WebApplication";
120-
var generateMixedWithNullElement = () => _ = new EditorConfigGenerator(rootPath)
121-
.Generate([null, "C:/Users/Johnny/source/repos/WebApplication/Component.razor", string.Empty]);
115+
var generateMixedWithNullElement = () => _ = new EditorConfigGenerator(rootPath).Generate([null, "C:/Users/Johnny/source/repos/WebApplication/Component.razor", string.Empty]);
122116
generateMixedWithNullElement.Should().Throw<NullReferenceException>();
123117
}
124118
}

analyzers/tests/SonarAnalyzer.TestFramework/Common/EditorConfigGenerator.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ public string Generate(IEnumerable<string> razorFiles) =>
3939
razorFiles.Select(x => x.Replace('\\', '/')).Select(ToConfigLine).Prepend("is_global = true").JoinStr(Environment.NewLine);
4040

4141
private string ToConfigLine(string file) =>
42-
TestHelper.ReplaceLineEndings(
43-
$"""
44-
[{file}]
45-
build_metadata.AdditionalFiles.TargetPath = {Convert.ToBase64String(Encoding.UTF8.GetBytes(TestHelper.GetRelativePath(rootPath, file)))}
46-
""", Environment.NewLine);
42+
$"""
43+
[{file}]
44+
build_metadata.AdditionalFiles.TargetPath = {Convert.ToBase64String(Encoding.UTF8.GetBytes(TestHelper.GetRelativePath(rootPath, file)))}
45+
""";
4746
}

analyzers/tests/SonarAnalyzer.TestFramework/Common/TestHelper.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,4 @@ public static string GetRelativePath(string relativeTo, string path)
179179
}
180180
return relativePath;
181181
}
182-
183-
public static string ReplaceLineEndings(string input, string replacement) =>
184-
Regex.Replace(input, @"\r\n?|\n", replacement, RegexOptions.None, RegexConstants.DefaultTimeout);
185182
}

0 commit comments

Comments
 (0)