Skip to content

Commit

Permalink
Merge pull request #48049 from dotnet/merges/release/dev16.8-to-master
Browse files Browse the repository at this point in the history
Merge release/dev16.8 to master
  • Loading branch information
msftbot[bot] authored Sep 25, 2020
2 parents 6521491 + b7e71f0 commit c8b3af5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ internal static ReportDiagnostic GetDiagnosticReport(
{
// 4. Global analyzer config level
isSpecified = true;

// '/warnaserror' should promote warnings configured in global analyzer config to error.
if (report == ReportDiagnostic.Warn && generalDiagnosticOption == ReportDiagnostic.Error)
{
report = ReportDiagnostic.Error;
}
}
else
{
Expand Down
38 changes: 38 additions & 0 deletions src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12826,6 +12826,44 @@ void M()
VerifyOutput(dir, src, additionalFlags: new[] { "/warnaserror+", "/analyzerconfig:" + globalConfig.Path }, includeCurrentAssemblyAsAnalyzerReference: false);
}

[Theory, CombinatorialData]
[WorkItem(43051, "https://github.com/dotnet/roslyn/issues/43051")]
public void WarnAsErrorIsRespectedForForWarningsConfiguredInRulesetOrGlobalConfig(bool useGlobalConfig)
{
var dir = Temp.CreateDirectory();
var src = dir.CreateFile("temp.cs").WriteAllText(@"
class C
{
void M()
{
label1:;
}
}");
var additionalFlags = new[] { "/warnaserror+" };
if (useGlobalConfig)
{
var globalConfig = dir.CreateFile(".globalconfig").WriteAllText($@"
is_global = true
dotnet_diagnostic.CS0164.severity = warning;
");
additionalFlags = additionalFlags.Append("/analyzerconfig:" + globalConfig.Path).ToArray();
}
else
{
string ruleSetSource = @"<?xml version=""1.0"" encoding=""utf-8""?>
<RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""15.0"">
<Rules AnalyzerId=""Compiler"" RuleNamespace=""Compiler"">
<Rule Id=""CS0164"" Action=""Warning"" />
</Rules>
</RuleSet>
";
_ = dir.CreateFile("Rules.ruleset").WriteAllText(ruleSetSource);
additionalFlags = additionalFlags.Append("/ruleset:Rules.ruleset").ToArray();
}

VerifyOutput(dir, src, additionalFlags: additionalFlags, expectedErrorCount: 1, includeCurrentAssemblyAsAnalyzerReference: false);
}

[Fact]
[WorkItem(44087, "https://github.com/dotnet/roslyn/issues/44804")]
public void GlobalAnalyzerConfigSectionsOverrideCommandLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ElseIf syntaxTreeOptions IsNot Nothing AndAlso syntaxTreeOptions.TryGetGlobalDiagnosticValue(id, cancellationToken, report) Then
' 4. Global analyzer config level
isSpecified = True

' '/warnaserror' should promote warnings configured in global analyzer config to error.
If report = ReportDiagnostic.Warn AndAlso generalDiagnosticOption = ReportDiagnostic.Error Then
report = ReportDiagnostic.Error
End If
Else
report = If(isEnabledByDefault, ReportDiagnostic.Default, ReportDiagnostic.Suppress)
End If
Expand Down
33 changes: 33 additions & 0 deletions src/Compilers/VisualBasic/Test/CommandLine/CommandLineTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -10091,6 +10091,39 @@ dotnet_diagnostic.BC42024.severity = warning;
VerifyOutput(dir, src, includeCurrentAssemblyAsAnalyzerReference:=False, expectedWarningCount:=1, additionalFlags:={"/nowarn:BC42024", globalOption, specificOption})
End Sub

<Theory, CombinatorialData>
<WorkItem(43051, "https://github.com/dotnet/roslyn/issues/43051")>
Public Sub WarnAsErrorIsRespectedForForWarningsConfiguredInRulesetOrGlobalConfig(useGlobalConfig As Boolean)
Dim dir = Temp.CreateDirectory()
Dim src = dir.CreateFile("temp.vb").WriteAllText("
Class C
Private Sub M()
Dim a As String
End Sub
End Class")
Dim additionalFlags = {"/warnaserror+"}

If useGlobalConfig Then
Dim globalConfig = dir.CreateFile(".globalconfig").WriteAllText($"
is_global = true
dotnet_diagnostic.BC42024.severity = warning;
")
additionalFlags = additionalFlags.Append("/analyzerconfig:" & globalConfig.Path).ToArray()
Else
Dim ruleSetSource As String = "<?xml version=""1.0"" encoding=""utf-8""?>
<RuleSet Name=""Ruleset1"" Description=""Test"" ToolsVersion=""15.0"">
<Rules AnalyzerId=""Compiler"" RuleNamespace=""Compiler"">
<Rule Id=""BC42024"" Action=""Warning"" />
</Rules>
</RuleSet>
"
dir.CreateFile("Rules.ruleset").WriteAllText(ruleSetSource)
additionalFlags = additionalFlags.Append("/ruleset:Rules.ruleset").ToArray()
End If

VerifyOutput(dir, src, additionalFlags:=additionalFlags, expectedErrorCount:=1, includeCurrentAssemblyAsAnalyzerReference:=False)
End Sub

<Fact>
<WorkItem(44087, "https://github.com/dotnet/roslyn/issues/44804")>
Public Sub GlobalAnalyzerConfigSpecificDiagnosticOptionsOverrideGeneralCommandLineOptions()
Expand Down

0 comments on commit c8b3af5

Please sign in to comment.