Skip to content
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

Handle /warnaserror with Warning analyzer bulk configuration in edito… #58460

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12479,6 +12479,11 @@ public void TestCategoryBasedBulkAnalyzerDiagnosticConfiguration(DiagnosticSever
dotnet_analyzer_diagnostic.category-{category}.severity = error";
TestBulkAnalyzerConfigurationCore(analyzer, analyzerConfigText, errorlog, expectedDiagnosticSeverity: ReportDiagnostic.Warn);

// Verify category based configuration to warning + /warnaserror reports errors.
analyzerConfigText = $@"
[*.cs]
dotnet_analyzer_diagnostic.category-{category}.severity = warning";
TestBulkAnalyzerConfigurationCore(analyzer, analyzerConfigText, errorlog, warnAsError: true, expectedDiagnosticSeverity: ReportDiagnostic.Error);

// Verify disabled by default analyzer is not enabled by category based configuration.
analyzer = new NamedTypeAnalyzerWithConfigurableEnabledByDefault(isEnabledByDefault: false, defaultSeverity);
Expand Down Expand Up @@ -12559,6 +12564,12 @@ public void TestBulkAnalyzerDiagnosticConfiguration(DiagnosticSeverity defaultSe
dotnet_analyzer_diagnostic.severity = error";
TestBulkAnalyzerConfigurationCore(analyzer, analyzerConfigText, errorlog, expectedDiagnosticSeverity: ReportDiagnostic.Warn);

// Verify bulk configuration to warning + /warnaserror reports errors.
analyzerConfigText = $@"
[*.cs]
dotnet_analyzer_diagnostic.severity = warning";
TestBulkAnalyzerConfigurationCore(analyzer, analyzerConfigText, errorlog, warnAsError: true, expectedDiagnosticSeverity: ReportDiagnostic.Error);

// Verify disabled by default analyzer is not enabled by bulk configuration.
analyzer = new NamedTypeAnalyzerWithConfigurableEnabledByDefault(isEnabledByDefault: false, defaultSeverity);
analyzerConfigText = $@"
Expand Down Expand Up @@ -12636,7 +12647,8 @@ private void TestBulkAnalyzerConfigurationCore(
bool errorlog,
ReportDiagnostic expectedDiagnosticSeverity,
string rulesetText = null,
bool noWarn = false)
bool noWarn = false,
bool warnAsError = false)
{
var diagnosticId = analyzer.Descriptor.Id;
var dir = Temp.CreateDirectory();
Expand All @@ -12654,6 +12666,11 @@ private void TestBulkAnalyzerConfigurationCore(
arguments = arguments.Append($"/nowarn:{diagnosticId}");
}

if (warnAsError)
{
arguments = arguments.Append($"/warnaserror");
}

if (errorlog)
{
arguments = arguments.Append($"/errorlog:errorlog");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public static bool TryGetSeverityFromBulkConfiguration(
if (analyzerConfigOptions.TryGetValue(categoryBasedKey, out var value) &&
AnalyzerConfigSet.TryParseSeverity(value, out severity))
{
// '/warnaserror' should bump Warning bulk configuration to Error.
if (severity == ReportDiagnostic.Warn && compilation.Options.GeneralDiagnosticOption == ReportDiagnostic.Error)
severity = ReportDiagnostic.Error;

return true;
}

Expand All @@ -74,6 +78,10 @@ public static bool TryGetSeverityFromBulkConfiguration(
if (analyzerConfigOptions.TryGetValue(DotnetAnalyzerDiagnosticSeverityKey, out value) &&
AnalyzerConfigSet.TryParseSeverity(value, out severity))
{
// '/warnaserror' should bump Warning bulk configuration to Error.
if (severity == ReportDiagnostic.Warn && compilation.Options.GeneralDiagnosticOption == ReportDiagnostic.Error)
severity = ReportDiagnostic.Error;

return true;
}

Expand Down