Skip to content
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
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- [CLI] Suppress error code from Roslynator when it detects issues in code but runs successfully ([PR](https://github.com/dotnet/roslynator/pull/1756) by @mdrybak)

### Fixed

- Fix analyzer [RCS1074](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1074) ([PR](https://github.com/dotnet/roslynator/pull/1768) by @cbersch)
Expand Down
7 changes: 4 additions & 3 deletions src/CommandLine/Commands/AnalyzeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ public override async Task<AnalyzeCommandResult> ExecuteAsync(ProjectOrSolution
results = await codeAnalyzer.AnalyzeSolutionAsync(solution, f => IsMatch(f), cancellationToken);
}

return new AnalyzeCommandResult(
(results.Any(f => f.Diagnostics.Length > 0 || f.CompilerDiagnostics.Length > 0)) ? CommandStatus.NotSuccess : CommandStatus.Success,
results);
return new AnalyzeCommandResult(GetCommandStatus(Options, results), results);
}

private static CommandStatus GetCommandStatus(AnalyzeCommandLineOptions options, ImmutableArray<ProjectAnalysisResult> results)
=> (options.ReturnSuccessOnDiagnostics || !results.Any(f => f.Diagnostics.Length > 0 || f.CompilerDiagnostics.Length > 0)) ? CommandStatus.Success : CommandStatus.NotSuccess;

protected override void ProcessResults(IList<AnalyzeCommandResult> results)
{
IEnumerable<ProjectAnalysisResult> analysisResults = results.SelectMany(f => f.AnalysisResults);
Expand Down
5 changes: 5 additions & 0 deletions src/CommandLine/Options/AnalyzeCommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class AnalyzeCommandLineOptions : AbstractAnalyzeCommandLineOptions
HelpText = "Indicates whether suppressed diagnostics should be reported.")]
public bool ReportSuppressedDiagnostics { get; set; }

[Option(
longName: "return-success-on-diagnostics",
HelpText = "Indicates whether to return exit code 0 on runs when diagnostics are reported.")]
public bool ReturnSuccessOnDiagnostics { get; set; }

internal bool ValidateOutputFormat()
{
return ParseHelpers.TryParseOutputFormat(OutputFormat);
Expand Down
Loading