-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure source paths are comparable with editorconfig directory paths #73100
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -932,6 +932,33 @@ public void EditorConfigToDiagnostics() | |
}, options.Select(o => o.TreeOptions).ToArray()); | ||
} | ||
|
||
[Theory, WorkItem("https://github.com/dotnet/roslyn/issues/72657")] | ||
[InlineData("/", "/")] | ||
[InlineData("/a/b/c/", "/a/b/c/")] | ||
[InlineData("/a/b//c/", "/a/b/c/")] | ||
[InlineData("/a/b/c/", "/a/b//c/")] | ||
[InlineData("/a/b//c/", "/a/b//c/")] | ||
[InlineData("/a/b/c//", "/a/b/c/")] | ||
[InlineData("/a/b/c/", "/a/b/c//")] | ||
[InlineData("/a/b/c//", "/a/b/c//")] | ||
[InlineData("/a/b//c/", "/a/b///c/")] | ||
public void EditorConfigToDiagnostics_DoubleSlash(string prefix1, string prefix2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider naming these parameters based on how each prefix is being used. |
||
{ | ||
var configs = ArrayBuilder<AnalyzerConfig>.GetInstance(); | ||
configs.Add(Parse(""" | ||
[*.cs] | ||
dotnet_diagnostic.cs000.severity = none | ||
""", | ||
prefix1 + ".editorconfig")); | ||
|
||
var options = GetAnalyzerConfigOptions([prefix2 + "test.cs"], configs); | ||
configs.Free(); | ||
|
||
Assert.Equal([ | ||
CreateImmutableDictionary(("cs000", ReportDiagnostic.Suppress)) | ||
], options.Select(o => o.TreeOptions).ToArray()); | ||
} | ||
|
||
[Fact] | ||
public void LaterSectionOverrides() | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
|
||
|
@@ -780,6 +781,42 @@ public static bool IsValidFilePath([NotNullWhen(true)] string? fullPath) | |
public static string NormalizeWithForwardSlash(string p) | ||
=> DirectorySeparatorChar == '/' ? p : p.Replace(DirectorySeparatorChar, '/'); | ||
|
||
/// <summary> | ||
/// Replaces all sequences of '\' or '/' with a single '/' but preserves UNC prefix '//'. | ||
/// </summary> | ||
public static string CollapseWithForwardSlash(ReadOnlySpan<char> path) | ||
{ | ||
var sb = new StringBuilder(path.Length); | ||
|
||
int start = 0; | ||
if (path.Length > 1 && IsAnyDirectorySeparator(path[0]) && IsAnyDirectorySeparator(path[1])) | ||
{ | ||
// Preserve UNC paths. | ||
sb.Append("//"); | ||
start = 2; | ||
} | ||
|
||
bool wasDirectorySeparator = false; | ||
for (int i = start; i < path.Length; i++) | ||
{ | ||
if (IsAnyDirectorySeparator(path[i])) | ||
{ | ||
if (!wasDirectorySeparator) | ||
{ | ||
sb.Append('/'); | ||
} | ||
wasDirectorySeparator = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider an input string of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's intended, will add a test, thanks. |
||
} | ||
else | ||
{ | ||
sb.Append(path[i]); | ||
wasDirectorySeparator = false; | ||
} | ||
} | ||
|
||
return sb.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Takes an absolute path and attempts to expand any '..' or '.' into their equivalent representation. | ||
/// </summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consider naming these parameters based on which element we are introducing double slashes for, e.g.
bool doubleSlashAnalyzerConfig, bool doubleSlashSource