Skip to content

Commit

Permalink
Update parsing of dotnet_diagnostic lines to ignore "trailing comments"
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Mar 3, 2021
1 parent 3b98df1 commit 1b6c125
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Compilers/Core/Portable/CommandLine/AnalyzerConfigSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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[] { ';', '#' };
var trimmed = value.AsSpan();
var commentStartIndex = trimmed.IndexOfAny(commentStartCharacters);
if (commentStartIndex >= 0)
trimmed = trimmed[0..commentStartIndex].TrimEnd();

var comparer = StringComparer.OrdinalIgnoreCase;
if (comparer.Equals(value, "default"))
if (trimmed.Equals("default".AsSpan(), StringComparison.OrdinalIgnoreCase))
{
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;
Expand Down

0 comments on commit 1b6c125

Please sign in to comment.