-
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
EditorConfig comments cannot follow a property value #51625
base: main
Are you sure you want to change the base?
Changes from 2 commits
3b98df1
1b6c125
ea18e2f
d797c32
bf03a75
be49e52
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 |
---|---|---|
|
@@ -21,7 +21,7 @@ public sealed partial class AnalyzerConfig | |
// Matches EditorConfig section header such as "[*.{js,py}]", see https://editorconfig.org for details | ||
private static readonly Regex s_sectionMatcher = new Regex(@"^\s*\[(([^#;]|\\#|\\;)+)\]\s*([#;].*)?$", RegexOptions.Compiled); | ||
// Matches EditorConfig property such as "indent_style = space", see https://editorconfig.org for details | ||
private static readonly Regex s_propertyMatcher = new Regex(@"^\s*([\w\.\-_]+)\s*[=:]\s*(.*?)\s*([#;].*)?$", RegexOptions.Compiled); | ||
private static readonly Regex s_propertyMatcher = new Regex(@"^\s*([\w\.\-_]+)\s*[=:]\s*(.*?)\s*$", RegexOptions.Compiled); | ||
sharwell marked this conversation as resolved.
Show resolved
Hide resolved
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.
Why are we considering both 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. ➡️ I have no idea, but that seems beyond the scope of this change. 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. Probably outside the scope of this PR, but should we be allowing whitespace within the key? eg: 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. It appears that we do not currently support whitespace inside the key, but according to the specification it should be allowed:
Can you file a new issue for this? 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. |
||
|
||
/// <summary> | ||
/// Key that indicates if this config is a global config | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,33 +337,40 @@ static void freeKey(List<Section> sectionKey, ObjectPool<List<Section>> pool) | |
|
||
internal static bool TryParseSeverity(string value, out ReportDiagnostic severity) | ||
{ | ||
ReadOnlySpan<char> commentStartCharacters = stackalloc char[] { ';', '#' }; | ||
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. nit: consider leaving a comment ("for backcompat, ...") |
||
var trimmed = value.AsSpan(); | ||
var commentStartIndex = trimmed.IndexOfAny(commentStartCharacters); | ||
if (commentStartIndex >= 0) | ||
trimmed = trimmed[0..commentStartIndex].TrimEnd(); | ||
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. As far as I understand, this change is to maintain the existing behavior and I assume we already have tests covering this. Is that right? #Closed 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. ➡️ Yes, and tests have now been added. |
||
|
||
var comparer = StringComparer.OrdinalIgnoreCase; | ||
if (comparer.Equals(value, "default")) | ||
if (trimmed.Equals("default".AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
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. The |
||
{ | ||
severity = ReportDiagnostic.Default; | ||
return true; | ||
} | ||
else if (comparer.Equals(value, "error")) | ||
else if (trimmed.Equals("error".AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
severity = ReportDiagnostic.Error; | ||
return true; | ||
} | ||
else if (comparer.Equals(value, "warning")) | ||
else if (trimmed.Equals("warning".AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
severity = ReportDiagnostic.Warn; | ||
return true; | ||
} | ||
else if (comparer.Equals(value, "suggestion")) | ||
else if (trimmed.Equals("suggestion".AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
severity = ReportDiagnostic.Info; | ||
return true; | ||
} | ||
else if (comparer.Equals(value, "silent") || comparer.Equals(value, "refactoring")) | ||
else if (trimmed.Equals("silent".AsSpan(), StringComparison.OrdinalIgnoreCase) | ||
|| trimmed.Equals("refactoring".AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
severity = ReportDiagnostic.Hidden; | ||
return true; | ||
} | ||
else if (comparer.Equals(value, "none")) | ||
else if (trimmed.Equals("none".AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
severity = ReportDiagnostic.Suppress; | ||
return true; | ||
|
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.
Please document the breaking change in https://github.com/dotnet/roslyn/blob/main/docs/compilers/CSharp/Compiler%20Breaking%20Changes%20-%20post%20DotNet%205.md #Closed
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.
➡️ Documented for .NET 9