From 4a8ba991b624b42682f6e26b6c70fc387ce2f755 Mon Sep 17 00:00:00 2001 From: Andrea Vassallo Date: Wed, 26 Oct 2022 14:32:14 +0200 Subject: [PATCH] Fix the exits with status 1 with disabled cops We should exit 1, that means error, only when the violations are valid. For valid we mean all the validations that have at least one offence that is not disabled. This will fix this issue: https://github.com/m4i/rubocop-git/issues/39 --- lib/rubocop/git/runner.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/rubocop/git/runner.rb b/lib/rubocop/git/runner.rb index a33d63e..7f1e593 100644 --- a/lib/rubocop/git/runner.rb +++ b/lib/rubocop/git/runner.rb @@ -12,7 +12,7 @@ def run(options) display_violations($stdout) - exit(1) if violations.any? + exit(1) if violations_with_valid_offences.any? end private @@ -21,11 +21,23 @@ def violations @violations ||= style_checker.violations end + def violations_with_valid_offences + @violations_with_valid_offences ||= begin + violations.map do |violation| + offenses = violation.offenses + offenses = offenses.reject(&:disabled?) if offenses.first.respond_to?(:disabled?) + offenses.any? ? violation : nil + end.compact + end + end + def style_checker - StyleChecker.new(pull_request.pull_request_files, - @options.rubocop, - @options.config_file, - pull_request.config) + StyleChecker.new( + pull_request.pull_request_files, + @options.rubocop, + @options.config_file, + pull_request.config + ) end def pull_request