forked from rubocop/rubocop
/
execute_runner.rb
85 lines (65 loc) · 2.61 KB
/
execute_runner.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true
module RuboCop
class CLI
module Command
# Run all the selected cops and report the result.
# @api private
class ExecuteRunner < Base
include Formatter::TextUtil
# Combination of short and long formatter names.
INTEGRATION_FORMATTERS = %w[h html j json ju junit].freeze
self.command_name = :execute_runner
def run
execute_runner(@paths)
end
private
def execute_runner(paths)
runner = Runner.new(@options, @config_store)
all_passed = runner.run(paths)
display_warning_summary(runner.warnings)
display_error_summary(runner.errors)
maybe_print_corrected_source
all_pass_or_excluded = all_passed || @options[:auto_gen_config]
if runner.aborting?
STATUS_INTERRUPTED
elsif all_pass_or_excluded && runner.errors.empty?
STATUS_SUCCESS
else
STATUS_OFFENSES
end
end
def display_warning_summary(warnings)
return if warnings.empty?
warn Rainbow("\n#{pluralize(warnings.size, 'warning')}:").yellow
warnings.each { |warning| warn warning }
end
def display_error_summary(errors)
return if errors.empty?
warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
errors.each { |error| warn error }
warn <<~WARNING
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
#{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}
Mention the following information in the issue report:
#{RuboCop::Version.version(debug: true)}
WARNING
end
def maybe_print_corrected_source
# Integration tools (like RubyMine) expect to have only the JSON result
# when specifying JSON format. Similar HTML and JUnit are targeted as well.
# See: https://github.com/rubocop-hq/rubocop/issues/8673
return if INTEGRATION_FORMATTERS.include?(@options[:format])
# If we are asked to autocorrect source code read from stdin, the only
# reasonable place to write it is to stdout
# Unfortunately, we also write other information to stdout
# So a delimiter is needed for tools to easily identify where the
# autocorrected source begins
return unless @options[:stdin] && @options[:auto_correct]
puts '=' * 20
print @options[:stdin]
end
end
end
end
end