From 1b6c125cc8783de44be40dce85917edb43dc8f42 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 3 Mar 2021 08:24:24 -0800 Subject: [PATCH] Update parsing of dotnet_diagnostic lines to ignore "trailing comments" --- .../Portable/CommandLine/AnalyzerConfigSet.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Compilers/Core/Portable/CommandLine/AnalyzerConfigSet.cs b/src/Compilers/Core/Portable/CommandLine/AnalyzerConfigSet.cs index b6ac8fe1ab9e2..cc9df629c5257 100644 --- a/src/Compilers/Core/Portable/CommandLine/AnalyzerConfigSet.cs +++ b/src/Compilers/Core/Portable/CommandLine/AnalyzerConfigSet.cs @@ -337,33 +337,40 @@ static void freeKey(List
sectionKey, ObjectPool> pool) internal static bool TryParseSeverity(string value, out ReportDiagnostic severity) { + ReadOnlySpan 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;