rubocop 0.76.0 → 0.77.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +252 -239
  4. data/lib/rubocop.rb +27 -20
  5. data/lib/rubocop/ast/node.rb +1 -1
  6. data/lib/rubocop/ast/node/block_node.rb +2 -0
  7. data/lib/rubocop/cli.rb +11 -230
  8. data/lib/rubocop/cli/command.rb +21 -0
  9. data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
  10. data/lib/rubocop/cli/command/base.rb +33 -0
  11. data/lib/rubocop/cli/command/execute_runner.rb +76 -0
  12. data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
  13. data/lib/rubocop/cli/command/show_cops.rb +73 -0
  14. data/lib/rubocop/cli/command/version.rb +17 -0
  15. data/lib/rubocop/cli/environment.rb +21 -0
  16. data/lib/rubocop/config_obsoletion.rb +62 -9
  17. data/lib/rubocop/config_validator.rb +1 -3
  18. data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
  19. data/lib/rubocop/cop/cop.rb +19 -0
  20. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
  21. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  22. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
  23. data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
  24. data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
  25. data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +1 -1
  26. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -1
  27. data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +3 -3
  28. data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
  29. data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +3 -3
  30. data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
  31. data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +2 -2
  32. data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +1 -1
  33. data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
  34. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
  35. data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
  36. data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
  37. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  38. data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
  39. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
  40. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
  41. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  42. data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
  43. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  44. data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
  45. data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
  46. data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
  47. data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
  48. data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
  49. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  50. data/lib/rubocop/cop/metrics/line_length.rb +41 -38
  51. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  52. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
  53. data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
  54. data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
  55. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
  56. data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +3 -3
  57. data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
  58. data/lib/rubocop/cop/style/alias.rb +1 -1
  59. data/lib/rubocop/cop/style/array_join.rb +1 -1
  60. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  61. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  62. data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
  63. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  64. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
  65. data/lib/rubocop/cop/style/next.rb +5 -5
  66. data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
  67. data/lib/rubocop/cop/style/option_hash.rb +3 -3
  68. data/lib/rubocop/cop/style/redundant_parentheses.rb +3 -3
  69. data/lib/rubocop/cop/style/redundant_return.rb +2 -8
  70. data/lib/rubocop/cop/style/redundant_sort.rb +1 -1
  71. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
  72. data/lib/rubocop/cop/team.rb +5 -0
  73. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -3
  74. data/lib/rubocop/formatter/tap_formatter.rb +1 -3
  75. data/lib/rubocop/processed_source.rb +1 -1
  76. data/lib/rubocop/rake_task.rb +1 -0
  77. data/lib/rubocop/result_cache.rb +21 -7
  78. data/lib/rubocop/runner.rb +13 -1
  79. data/lib/rubocop/version.rb +1 -1
  80. metadata +30 -22
  81. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -24
@@ -118,7 +118,7 @@ require_relative 'rubocop/cop/mixin/end_keyword_alignment'
118
118
  require_relative 'rubocop/cop/mixin/enforce_superclass'
119
119
  require_relative 'rubocop/cop/mixin/first_element_line_break'
120
120
  require_relative 'rubocop/cop/mixin/frozen_string_literal'
121
- require_relative 'rubocop/cop/mixin/hash_alignment'
121
+ require_relative 'rubocop/cop/mixin/hash_alignment_styles'
122
122
  require_relative 'rubocop/cop/mixin/ignored_pattern'
123
123
  require_relative 'rubocop/cop/mixin/ignored_methods'
124
124
  require_relative 'rubocop/cop/mixin/integer_node'
@@ -144,7 +144,6 @@ require_relative 'rubocop/cop/mixin/preceding_following_alignment'
144
144
  require_relative 'rubocop/cop/mixin/preferred_delimiters'
145
145
  require_relative 'rubocop/cop/mixin/rescue_node'
146
146
  require_relative 'rubocop/cop/mixin/safe_assignment'
147
- require_relative 'rubocop/cop/mixin/safe_mode'
148
147
  require_relative 'rubocop/cop/mixin/space_after_punctuation'
149
148
  require_relative 'rubocop/cop/mixin/space_before_punctuation'
150
149
  require_relative 'rubocop/cop/mixin/surrounding_space'
@@ -189,10 +188,9 @@ require_relative 'rubocop/cop/gemspec/required_ruby_version'
189
188
  require_relative 'rubocop/cop/gemspec/ruby_version_globals_usage'
190
189
 
191
190
  require_relative 'rubocop/cop/layout/access_modifier_indentation'
192
- require_relative 'rubocop/cop/layout/align_arguments'
193
- require_relative 'rubocop/cop/layout/align_array'
194
- require_relative 'rubocop/cop/layout/align_hash'
195
- require_relative 'rubocop/cop/layout/align_parameters'
191
+ require_relative 'rubocop/cop/layout/argument_alignment'
192
+ require_relative 'rubocop/cop/layout/array_alignment'
193
+ require_relative 'rubocop/cop/layout/assignment_indentation'
196
194
  require_relative 'rubocop/cop/layout/block_alignment'
197
195
  require_relative 'rubocop/cop/layout/block_end_newline'
198
196
  require_relative 'rubocop/cop/layout/case_indentation'
@@ -220,22 +218,22 @@ require_relative 'rubocop/cop/layout/empty_lines'
220
218
  require_relative 'rubocop/cop/layout/end_alignment'
221
219
  require_relative 'rubocop/cop/layout/end_of_line'
222
220
  require_relative 'rubocop/cop/layout/extra_spacing'
221
+ require_relative 'rubocop/cop/layout/first_argument_indentation'
222
+ require_relative 'rubocop/cop/layout/first_array_element_indentation'
223
223
  require_relative 'rubocop/cop/layout/first_array_element_line_break'
224
+ require_relative 'rubocop/cop/layout/first_hash_element_indentation'
224
225
  require_relative 'rubocop/cop/layout/first_hash_element_line_break'
225
226
  require_relative 'rubocop/cop/layout/first_method_argument_line_break'
226
227
  require_relative 'rubocop/cop/layout/first_method_parameter_line_break'
228
+ require_relative 'rubocop/cop/layout/first_parameter_indentation'
229
+ require_relative 'rubocop/cop/layout/hash_alignment'
227
230
  require_relative 'rubocop/cop/layout/heredoc_argument_closing_parenthesis'
228
- require_relative 'rubocop/cop/layout/indent_assignment'
231
+ require_relative 'rubocop/cop/layout/heredoc_indentation'
229
232
  require_relative 'rubocop/cop/layout/indentation_consistency'
230
233
  require_relative 'rubocop/cop/layout/indentation_width'
231
- require_relative 'rubocop/cop/layout/indent_first_argument'
232
- require_relative 'rubocop/cop/layout/indent_first_array_element'
233
- require_relative 'rubocop/cop/layout/indent_first_hash_element'
234
- require_relative 'rubocop/cop/layout/indent_first_parameter'
235
- require_relative 'rubocop/cop/layout/indent_heredoc'
236
234
  require_relative 'rubocop/cop/layout/initial_indentation'
237
- require_relative 'rubocop/cop/layout/leading_blank_lines'
238
235
  require_relative 'rubocop/cop/layout/leading_comment_space'
236
+ require_relative 'rubocop/cop/layout/leading_empty_lines'
239
237
  require_relative 'rubocop/cop/layout/multiline_array_brace_layout'
240
238
  require_relative 'rubocop/cop/layout/multiline_array_line_breaks'
241
239
  require_relative 'rubocop/cop/layout/multiline_assignment_layout'
@@ -247,6 +245,7 @@ require_relative 'rubocop/cop/layout/multiline_method_call_brace_layout'
247
245
  require_relative 'rubocop/cop/layout/multiline_method_call_indentation'
248
246
  require_relative 'rubocop/cop/layout/multiline_method_definition_brace_layout'
249
247
  require_relative 'rubocop/cop/layout/multiline_operation_indentation'
248
+ require_relative 'rubocop/cop/layout/parameter_alignment'
250
249
  require_relative 'rubocop/cop/layout/rescue_ensure_alignment'
251
250
  require_relative 'rubocop/cop/layout/space_after_colon'
252
251
  require_relative 'rubocop/cop/layout/space_after_comma'
@@ -273,7 +272,7 @@ require_relative 'rubocop/cop/layout/space_inside_range_literal'
273
272
  require_relative 'rubocop/cop/layout/space_inside_reference_brackets'
274
273
  require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
275
274
  require_relative 'rubocop/cop/layout/tab'
276
- require_relative 'rubocop/cop/layout/trailing_blank_lines'
275
+ require_relative 'rubocop/cop/layout/trailing_empty_lines'
277
276
  require_relative 'rubocop/cop/layout/trailing_whitespace'
278
277
 
279
278
  require_relative 'rubocop/cop/lint/ambiguous_block_association'
@@ -287,8 +286,8 @@ require_relative 'rubocop/cop/lint/debugger'
287
286
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
288
287
  require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
289
288
  require_relative 'rubocop/cop/lint/duplicate_case_condition'
289
+ require_relative 'rubocop/cop/lint/duplicate_hash_key'
290
290
  require_relative 'rubocop/cop/lint/duplicate_methods'
291
- require_relative 'rubocop/cop/lint/duplicated_key'
292
291
  require_relative 'rubocop/cop/lint/each_with_object_argument'
293
292
  require_relative 'rubocop/cop/lint/else_layout'
294
293
  require_relative 'rubocop/cop/lint/empty_ensure'
@@ -301,7 +300,6 @@ require_relative 'rubocop/cop/lint/erb_new_arguments'
301
300
  require_relative 'rubocop/cop/lint/flip_flop'
302
301
  require_relative 'rubocop/cop/lint/float_out_of_range'
303
302
  require_relative 'rubocop/cop/lint/format_parameter_mismatch'
304
- require_relative 'rubocop/cop/lint/handle_exceptions'
305
303
  require_relative 'rubocop/cop/lint/heredoc_method_call_position'
306
304
  require_relative 'rubocop/cop/lint/implicit_string_concatenation'
307
305
  require_relative 'rubocop/cop/lint/inherit_exception'
@@ -311,7 +309,7 @@ require_relative 'rubocop/cop/lint/literal_as_condition'
311
309
  require_relative 'rubocop/cop/lint/literal_in_interpolation'
312
310
  require_relative 'rubocop/cop/lint/loop'
313
311
  require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
314
- require_relative 'rubocop/cop/lint/multiple_compare'
312
+ require_relative 'rubocop/cop/lint/multiple_comparison'
315
313
  require_relative 'rubocop/cop/lint/nested_method_definition'
316
314
  require_relative 'rubocop/cop/lint/nested_percent_literal'
317
315
  require_relative 'rubocop/cop/lint/next_without_accumulator'
@@ -326,6 +324,7 @@ require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
326
324
  require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
327
325
  require_relative 'rubocop/cop/lint/redundant_require_statement'
328
326
  require_relative 'rubocop/cop/lint/redundant_splat_expansion'
327
+ require_relative 'rubocop/cop/lint/redundant_string_coercion'
329
328
  require_relative 'rubocop/cop/lint/redundant_with_index'
330
329
  require_relative 'rubocop/cop/lint/redundant_with_object'
331
330
  require_relative 'rubocop/cop/lint/regexp_as_condition'
@@ -341,7 +340,7 @@ require_relative 'rubocop/cop/lint/send_with_mixin_argument'
341
340
  require_relative 'rubocop/cop/lint/shadowed_argument'
342
341
  require_relative 'rubocop/cop/lint/shadowed_exception'
343
342
  require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
344
- require_relative 'rubocop/cop/lint/string_conversion_in_interpolation'
343
+ require_relative 'rubocop/cop/lint/suppressed_exception'
345
344
  require_relative 'rubocop/cop/lint/syntax'
346
345
  require_relative 'rubocop/cop/lint/to_json'
347
346
  require_relative 'rubocop/cop/lint/underscore_prefixed_variable_name'
@@ -373,6 +372,7 @@ require_relative 'rubocop/cop/metrics/perceived_complexity'
373
372
 
374
373
  require_relative 'rubocop/cop/naming/accessor_method_name'
375
374
  require_relative 'rubocop/cop/naming/ascii_identifiers'
375
+ require_relative 'rubocop/cop/naming/block_parameter_name'
376
376
  require_relative 'rubocop/cop/naming/class_and_module_camel_case'
377
377
  require_relative 'rubocop/cop/naming/constant_name'
378
378
  require_relative 'rubocop/cop/naming/file_name'
@@ -380,11 +380,10 @@ require_relative 'rubocop/cop/naming/heredoc_delimiter_case'
380
380
  require_relative 'rubocop/cop/naming/heredoc_delimiter_naming'
381
381
  require_relative 'rubocop/cop/naming/memoized_instance_variable_name'
382
382
  require_relative 'rubocop/cop/naming/method_name'
383
+ require_relative 'rubocop/cop/naming/method_parameter_name'
383
384
  require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
384
385
  require_relative 'rubocop/cop/naming/predicate_name'
385
386
  require_relative 'rubocop/cop/naming/rescued_exceptions_variable_name'
386
- require_relative 'rubocop/cop/naming/uncommunicative_block_param_name'
387
- require_relative 'rubocop/cop/naming/uncommunicative_method_param_name'
388
387
  require_relative 'rubocop/cop/naming/variable_name'
389
388
  require_relative 'rubocop/cop/naming/variable_number'
390
389
 
@@ -604,6 +603,14 @@ require_relative 'rubocop/processed_source'
604
603
  require_relative 'rubocop/result_cache'
605
604
  require_relative 'rubocop/runner'
606
605
  require_relative 'rubocop/cli'
606
+ require_relative 'rubocop/cli/command'
607
+ require_relative 'rubocop/cli/environment'
608
+ require_relative 'rubocop/cli/command/base'
609
+ require_relative 'rubocop/cli/command/auto_genenerate_config'
610
+ require_relative 'rubocop/cli/command/execute_runner'
611
+ require_relative 'rubocop/cli/command/init_dotfile'
612
+ require_relative 'rubocop/cli/command/show_cops'
613
+ require_relative 'rubocop/cli/command/version'
607
614
  require_relative 'rubocop/options'
608
615
  require_relative 'rubocop/remote_config'
609
616
  require_relative 'rubocop/yaml_duplication_checker'
@@ -624,7 +624,7 @@ module RuboCop
624
624
  end
625
625
 
626
626
  def parent_module_name_for_block(ancestor)
627
- if ancestor.method_name == :class_eval
627
+ if ancestor.method?(:class_eval)
628
628
  # `class_eval` with no receiver applies to whatever module or class
629
629
  # we are currently in
630
630
  return unless (receiver = ancestor.receiver)
@@ -9,6 +9,8 @@ module RuboCop
9
9
  # A `block` node is essentially a method send with a block. Parser nests
10
10
  # the `send` node inside the `block` node.
11
11
  class BlockNode < Node
12
+ include MethodIdentifierPredicates
13
+
12
14
  VOID_CONTEXT_METHODS = %i[each tap].freeze
13
15
 
14
16
  # The `send` node associated with this block.
@@ -1,20 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # rubocop:disable Metrics/ClassLength
4
3
  module RuboCop
5
4
  # The CLI is a class responsible of handling all the command line interface
6
5
  # logic.
7
6
  class CLI
8
- include Formatter::TextUtil
9
-
10
- PHASE_1 = 'Phase 1 of 2: run Metrics/LineLength cop'
11
- PHASE_2 = 'Phase 2 of 2: run all cops'
12
-
13
- PHASE_1_OVERRIDDEN = '(skipped because the default Metrics/LineLength:Max' \
14
- ' is overridden)'
15
- PHASE_1_DISABLED = '(skipped because Metrics/LineLength is ' \
16
- 'disabled)'
17
-
18
7
  STATUS_SUCCESS = 0
19
8
  STATUS_OFFENSES = 1
20
9
  STATUS_ERROR = 2
@@ -41,14 +30,15 @@ module RuboCop
41
30
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
42
31
  def run(args = ARGV)
43
32
  @options, paths = Options.new.parse(args)
33
+ @env = Environment.new(@options, @config_store, paths)
44
34
 
45
35
  if @options[:init]
46
- init_dotfile
36
+ run_command(:init)
47
37
  else
48
38
  validate_options_vs_config
49
39
  act_on_options
50
40
  apply_default_formatter
51
- execute_runners(paths)
41
+ execute_runners
52
42
  end
53
43
  rescue ConfigNotFoundError, IncorrectCopNameError, OptionArgumentError => e
54
44
  warn e.message
@@ -71,113 +61,18 @@ module RuboCop
71
61
 
72
62
  private
73
63
 
74
- def execute_runners(paths)
75
- if @options[:auto_gen_config]
76
- reset_config_and_auto_gen_file
77
- line_length_contents = maybe_run_line_length_cop(paths)
78
- run_all_cops_auto_gen_config(line_length_contents, paths)
79
- else
80
- execute_runner(paths)
81
- end
82
- end
83
-
84
- def maybe_run_line_length_cop(paths)
85
- if !line_length_enabled?(@config_store.for(Dir.pwd))
86
- skip_line_length_cop(PHASE_1_DISABLED)
87
- elsif !same_max_line_length?(
88
- @config_store.for(Dir.pwd), ConfigLoader.default_configuration
89
- )
90
- skip_line_length_cop(PHASE_1_OVERRIDDEN)
91
- else
92
- run_line_length_cop_auto_gen_config(paths)
93
- end
94
- end
95
-
96
- def skip_line_length_cop(reason)
97
- puts Rainbow("#{PHASE_1} #{reason}").yellow
98
- ''
99
- end
100
-
101
- def line_length_enabled?(config)
102
- line_length_cop(config)['Enabled']
103
- end
104
-
105
- def same_max_line_length?(config1, config2)
106
- max_line_length(config1) == max_line_length(config2)
107
- end
108
-
109
- def max_line_length(config)
110
- line_length_cop(config)['Max']
111
- end
112
-
113
- def line_length_cop(config)
114
- config.for_cop('Metrics/LineLength')
64
+ def run_command(name)
65
+ @env.run(name)
115
66
  end
116
67
 
117
- # Do an initial run with only Metrics/LineLength so that cops that depend
118
- # on Metrics/LineLength:Max get the correct value for that parameter.
119
- def run_line_length_cop_auto_gen_config(paths)
120
- puts Rainbow(PHASE_1).yellow
121
- @options[:only] = ['Metrics/LineLength']
122
- execute_runner(paths)
123
- @options.delete(:only)
124
- @config_store = ConfigStore.new
125
- # Save the todo configuration of the LineLength cop.
126
- IO.read(ConfigLoader::AUTO_GENERATED_FILE)
127
- .lines
128
- .drop_while { |line| line.start_with?('#') }
129
- .join
130
- end
131
-
132
- def run_all_cops_auto_gen_config(line_length_contents, paths)
133
- puts Rainbow(PHASE_2).yellow
134
- result = execute_runner(paths)
135
- # This run was made with the current maximum length allowed, so append
136
- # the saved setting for LineLength.
137
- File.open(ConfigLoader::AUTO_GENERATED_FILE, 'a') do |f|
138
- f.write(line_length_contents)
139
- end
140
- result
141
- end
142
-
143
- def init_dotfile
144
- path = File.expand_path(ConfigLoader::DOTFILE)
145
-
146
- if File.exist?(ConfigLoader::DOTFILE)
147
- warn Rainbow("#{ConfigLoader::DOTFILE} already exists at #{path}").red
148
-
149
- STATUS_ERROR
68
+ def execute_runners
69
+ if @options[:auto_gen_config]
70
+ run_command(:auto_gen_config)
150
71
  else
151
- description = <<~DESC
152
- # The behavior of RuboCop can be controlled via the .rubocop.yml
153
- # configuration file. It makes it possible to enable/disable
154
- # certain cops (checks) and to alter their behavior if they accept
155
- # any parameters. The file can be placed either in your home
156
- # directory or in some project directory.
157
- #
158
- # RuboCop will start looking for the configuration file in the directory
159
- # where the inspected file is and continue its way up to the root directory.
160
- #
161
- # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
162
- DESC
163
-
164
- File.open(ConfigLoader::DOTFILE, 'w') do |f|
165
- f.write(description)
166
- end
167
-
168
- puts "Writing new #{ConfigLoader::DOTFILE} to #{path}"
169
-
170
- STATUS_SUCCESS
72
+ run_command(:execute_runner)
171
73
  end
172
74
  end
173
75
 
174
- def reset_config_and_auto_gen_file
175
- @config_store = ConfigStore.new
176
- @config_store.options_config = @options[:config] if @options[:config]
177
- File.open(ConfigLoader::AUTO_GENERATED_FILE, 'w') {}
178
- ConfigLoader.add_inheritance_from_auto_generated_file
179
- end
180
-
181
76
  def validate_options_vs_config
182
77
  if @options[:parallel] &&
183
78
  !@config_store.for(Dir.pwd).for_all_cops['UseCache']
@@ -207,31 +102,11 @@ module RuboCop
207
102
  end
208
103
  end
209
104
 
210
- def execute_runner(paths)
211
- runner = Runner.new(@options, @config_store)
212
-
213
- all_passed = runner.run(paths)
214
- display_warning_summary(runner.warnings)
215
- display_error_summary(runner.errors)
216
- maybe_print_corrected_source
217
-
218
- all_pass_or_excluded = all_passed || @options[:auto_gen_config]
219
-
220
- if runner.aborting?
221
- STATUS_INTERRUPTED
222
- elsif all_pass_or_excluded && runner.errors.empty?
223
- STATUS_SUCCESS
224
- else
225
- STATUS_OFFENSES
226
- end
227
- end
228
-
229
105
  def handle_exiting_options
230
106
  return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
231
107
 
232
- puts RuboCop::Version.version(false) if @options[:version]
233
- puts RuboCop::Version.version(true) if @options[:verbose_version]
234
- print_available_cops if @options[:show_cops]
108
+ run_command(:version) if @options[:version] || @options[:verbose_version]
109
+ run_command(:show_cops) if @options[:show_cops]
235
110
  raise Finished
236
111
  end
237
112
 
@@ -247,100 +122,6 @@ module RuboCop
247
122
  end
248
123
  [[formatter, @options[:output_path]]]
249
124
  end
250
-
251
- return unless @options[:auto_gen_config]
252
-
253
- @options[:formatters] << [Formatter::DisabledConfigFormatter,
254
- ConfigLoader::AUTO_GENERATED_FILE]
255
- end
256
-
257
- def print_available_cops
258
- # Load the configs so the require()s are done for custom cops
259
- @config_store.for(Dir.pwd)
260
- registry = Cop::Cop.registry
261
- show_all = @options[:show_cops].empty?
262
-
263
- if show_all
264
- puts "# Available cops (#{registry.length}) + config for #{Dir.pwd}: "
265
- end
266
-
267
- registry.departments.sort!.each do |department|
268
- print_cops_of_department(registry, department, show_all)
269
- end
270
- end
271
-
272
- def print_cops_of_department(registry, department, show_all)
273
- selected_cops = if show_all
274
- cops_of_department(registry, department)
275
- else
276
- selected_cops_of_department(registry, department)
277
- end
278
-
279
- puts "# Department '#{department}' (#{selected_cops.length}):" if show_all
280
-
281
- print_cop_details(selected_cops)
282
- end
283
-
284
- def print_cop_details(cops)
285
- cops.each do |cop|
286
- puts '# Supports --auto-correct' if cop.new.support_autocorrect?
287
- puts "#{cop.cop_name}:"
288
- puts config_lines(cop)
289
- puts
290
- end
291
- end
292
-
293
- def selected_cops_of_department(cops, department)
294
- cops_of_department(cops, department).select do |cop|
295
- @options[:show_cops].include?(cop.cop_name)
296
- end
297
- end
298
-
299
- def cops_of_department(cops, department)
300
- cops.with_department(department).sort!
301
- end
302
-
303
- def config_lines(cop)
304
- cnf = @config_store.for(Dir.pwd).for_cop(cop)
305
- cnf.to_yaml.lines.to_a.drop(1).map { |line| ' ' + line }
306
- end
307
-
308
- def display_warning_summary(warnings)
309
- return if warnings.empty?
310
-
311
- warn Rainbow("\n#{pluralize(warnings.size, 'warning')}:").yellow
312
-
313
- warnings.each { |warning| warn warning }
314
- end
315
-
316
- def display_error_summary(errors)
317
- return if errors.empty?
318
-
319
- warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
320
-
321
- errors.each { |error| warn error }
322
-
323
- warn <<~WARNING
324
- Errors are usually caused by RuboCop bugs.
325
- Please, report your problems to RuboCop's issue tracker.
326
- #{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}
327
-
328
- Mention the following information in the issue report:
329
- #{RuboCop::Version.version(true)}
330
- WARNING
331
- end
332
-
333
- def maybe_print_corrected_source
334
- # If we are asked to autocorrect source code read from stdin, the only
335
- # reasonable place to write it is to stdout
336
- # Unfortunately, we also write other information to stdout
337
- # So a delimiter is needed for tools to easily identify where the
338
- # autocorrected source begins
339
- return unless @options[:stdin] && @options[:auto_correct]
340
-
341
- puts '=' * 20
342
- print @options[:stdin]
343
125
  end
344
126
  end
345
127
  end
346
- # rubocop:enable Metrics/ClassLength