rubocop 0.74.0 → 0.78.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 (213) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -2
  3. data/config/default.yml +366 -318
  4. data/lib/rubocop.rb +48 -32
  5. data/lib/rubocop/ast/builder.rb +1 -0
  6. data/lib/rubocop/ast/node.rb +5 -1
  7. data/lib/rubocop/ast/node/block_node.rb +2 -0
  8. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +1 -12
  9. data/lib/rubocop/ast/node/return_node.rb +24 -0
  10. data/lib/rubocop/cli.rb +11 -227
  11. data/lib/rubocop/cli/command.rb +21 -0
  12. data/lib/rubocop/cli/command/auto_genenerate_config.rb +105 -0
  13. data/lib/rubocop/cli/command/base.rb +33 -0
  14. data/lib/rubocop/cli/command/execute_runner.rb +76 -0
  15. data/lib/rubocop/cli/command/init_dotfile.rb +45 -0
  16. data/lib/rubocop/cli/command/show_cops.rb +73 -0
  17. data/lib/rubocop/cli/command/version.rb +17 -0
  18. data/lib/rubocop/cli/environment.rb +21 -0
  19. data/lib/rubocop/comment_config.rb +5 -4
  20. data/lib/rubocop/config.rb +12 -1
  21. data/lib/rubocop/config_loader.rb +21 -3
  22. data/lib/rubocop/config_loader_resolver.rb +4 -3
  23. data/lib/rubocop/config_obsoletion.rb +85 -11
  24. data/lib/rubocop/config_validator.rb +28 -19
  25. data/lib/rubocop/cop/autocorrect_logic.rb +3 -3
  26. data/lib/rubocop/cop/bundler/gem_comment.rb +4 -4
  27. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -2
  28. data/lib/rubocop/cop/commissioner.rb +15 -7
  29. data/lib/rubocop/cop/cop.rb +35 -9
  30. data/lib/rubocop/cop/corrector.rb +8 -7
  31. data/lib/rubocop/cop/correctors/alignment_corrector.rb +43 -17
  32. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
  33. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  34. data/lib/rubocop/cop/correctors/space_corrector.rb +1 -2
  35. data/lib/rubocop/cop/generator.rb +3 -3
  36. data/lib/rubocop/cop/generator/configuration_injector.rb +9 -4
  37. data/lib/rubocop/cop/generator/require_file_injector.rb +1 -1
  38. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  39. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +59 -0
  40. data/lib/rubocop/cop/layout/{align_arguments.rb → argument_alignment.rb} +1 -1
  41. data/lib/rubocop/cop/layout/{align_array.rb → array_alignment.rb} +1 -1
  42. data/lib/rubocop/cop/layout/{indent_assignment.rb → assignment_indentation.rb} +11 -2
  43. data/lib/rubocop/cop/layout/block_alignment.rb +2 -2
  44. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +1 -1
  45. data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
  46. data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
  47. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +22 -7
  48. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +2 -2
  49. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +2 -2
  50. data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
  51. data/lib/rubocop/cop/layout/extra_spacing.rb +1 -7
  52. data/lib/rubocop/cop/layout/{indent_first_argument.rb → first_argument_indentation.rb} +14 -12
  53. data/lib/rubocop/cop/layout/{indent_first_array_element.rb → first_array_element_indentation.rb} +4 -4
  54. data/lib/rubocop/cop/layout/{indent_first_hash_element.rb → first_hash_element_indentation.rb} +4 -4
  55. data/lib/rubocop/cop/layout/{indent_first_parameter.rb → first_parameter_indentation.rb} +3 -3
  56. data/lib/rubocop/cop/layout/{align_hash.rb → hash_alignment.rb} +8 -4
  57. data/lib/rubocop/cop/layout/{indent_heredoc.rb → heredoc_indentation.rb} +6 -6
  58. data/lib/rubocop/cop/layout/{leading_blank_lines.rb → leading_empty_lines.rb} +1 -1
  59. data/lib/rubocop/cop/{metrics → layout}/line_length.rb +41 -114
  60. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  61. data/lib/rubocop/cop/layout/multiline_block_layout.rb +24 -2
  62. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +1 -1
  63. data/lib/rubocop/cop/layout/{align_parameters.rb → parameter_alignment.rb} +1 -1
  64. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
  65. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +5 -1
  66. data/lib/rubocop/cop/layout/space_around_keyword.rb +12 -0
  67. data/lib/rubocop/cop/layout/space_around_operators.rb +32 -7
  68. data/lib/rubocop/cop/layout/space_before_block_braces.rb +17 -0
  69. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
  70. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +8 -5
  71. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +7 -0
  72. data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
  73. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +2 -0
  74. data/lib/rubocop/cop/layout/{trailing_blank_lines.rb → trailing_empty_lines.rb} +1 -1
  75. data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
  76. data/lib/rubocop/cop/lint/assignment_in_condition.rb +17 -4
  77. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  78. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +1 -1
  79. data/lib/rubocop/cop/lint/{duplicated_key.rb → duplicate_hash_key.rb} +1 -1
  80. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  81. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
  82. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +10 -36
  83. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  84. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
  85. data/lib/rubocop/cop/lint/{multiple_compare.rb → multiple_comparison.rb} +1 -1
  86. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +89 -0
  87. data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
  88. data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +26 -26
  89. data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +10 -12
  90. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
  91. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +6 -6
  92. data/lib/rubocop/cop/lint/{string_conversion_in_interpolation.rb → redundant_string_coercion.rb} +1 -1
  93. data/lib/rubocop/cop/lint/redundant_with_index.rb +2 -2
  94. data/lib/rubocop/cop/lint/redundant_with_object.rb +2 -2
  95. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
  96. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +91 -0
  97. data/lib/rubocop/cop/lint/{handle_exceptions.rb → suppressed_exception.rb} +1 -1
  98. data/lib/rubocop/cop/lint/unused_block_argument.rb +22 -6
  99. data/lib/rubocop/cop/lint/unused_method_argument.rb +23 -5
  100. data/lib/rubocop/cop/lint/useless_access_modifier.rb +57 -23
  101. data/lib/rubocop/cop/lint/useless_setter_call.rb +1 -1
  102. data/lib/rubocop/cop/lint/void.rb +7 -26
  103. data/lib/rubocop/cop/message_annotator.rb +16 -7
  104. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  105. data/lib/rubocop/cop/metrics/method_length.rb +1 -1
  106. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
  107. data/lib/rubocop/cop/migration/department_name.rb +44 -0
  108. data/lib/rubocop/cop/mixin/alignment.rb +2 -2
  109. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +1 -1
  110. data/lib/rubocop/cop/mixin/{hash_alignment.rb → hash_alignment_styles.rb} +1 -1
  111. data/lib/rubocop/cop/mixin/line_length_help.rb +88 -0
  112. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
  113. data/lib/rubocop/cop/mixin/nil_methods.rb +4 -4
  114. data/lib/rubocop/cop/mixin/rational_literal.rb +18 -0
  115. data/lib/rubocop/cop/mixin/statement_modifier.rb +7 -4
  116. data/lib/rubocop/cop/mixin/trailing_comma.rb +14 -9
  117. data/lib/rubocop/cop/naming/{uncommunicative_block_param_name.rb → block_parameter_name.rb} +3 -3
  118. data/lib/rubocop/cop/naming/file_name.rb +12 -5
  119. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +5 -5
  120. data/lib/rubocop/cop/naming/method_name.rb +12 -1
  121. data/lib/rubocop/cop/naming/{uncommunicative_method_param_name.rb → method_parameter_name.rb} +3 -3
  122. data/lib/rubocop/cop/naming/predicate_name.rb +6 -6
  123. data/lib/rubocop/cop/naming/variable_name.rb +1 -0
  124. data/lib/rubocop/cop/offense.rb +29 -7
  125. data/lib/rubocop/cop/registry.rb +22 -1
  126. data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -0
  127. data/lib/rubocop/cop/style/alias.rb +1 -1
  128. data/lib/rubocop/cop/style/array_join.rb +1 -1
  129. data/lib/rubocop/cop/style/attr.rb +10 -2
  130. data/lib/rubocop/cop/style/block_delimiters.rb +2 -1
  131. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +35 -16
  132. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  133. data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
  134. data/lib/rubocop/cop/style/commented_keyword.rb +8 -2
  135. data/lib/rubocop/cop/style/conditional_assignment.rb +6 -6
  136. data/lib/rubocop/cop/style/copyright.rb +11 -7
  137. data/lib/rubocop/cop/style/documentation_method.rb +44 -0
  138. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +10 -4
  139. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  140. data/lib/rubocop/cop/style/empty_literal.rb +2 -2
  141. data/lib/rubocop/cop/style/empty_method.rb +5 -5
  142. data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
  143. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  144. data/lib/rubocop/cop/style/expand_path_arguments.rb +1 -1
  145. data/lib/rubocop/cop/style/format_string.rb +10 -7
  146. data/lib/rubocop/cop/style/format_string_token.rb +19 -68
  147. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +28 -33
  148. data/lib/rubocop/cop/style/guard_clause.rb +3 -2
  149. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  150. data/lib/rubocop/cop/style/if_unless_modifier.rb +93 -15
  151. data/lib/rubocop/cop/style/infinite_loop.rb +6 -5
  152. data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
  153. data/lib/rubocop/cop/style/ip_addresses.rb +4 -4
  154. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
  155. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +25 -25
  156. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
  157. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  158. data/lib/rubocop/cop/style/mixin_usage.rb +11 -1
  159. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  160. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
  161. data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
  162. data/lib/rubocop/cop/style/nested_modifier.rb +22 -4
  163. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +5 -5
  164. data/lib/rubocop/cop/style/next.rb +5 -5
  165. data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
  166. data/lib/rubocop/cop/style/numeric_literals.rb +7 -3
  167. data/lib/rubocop/cop/style/option_hash.rb +3 -3
  168. data/lib/rubocop/cop/style/or_assignment.rb +6 -1
  169. data/lib/rubocop/cop/style/parentheses_around_condition.rb +14 -0
  170. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
  171. data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
  172. data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
  173. data/lib/rubocop/cop/style/redundant_parentheses.rb +16 -7
  174. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
  175. data/lib/rubocop/cop/style/redundant_return.rb +39 -29
  176. data/lib/rubocop/cop/style/redundant_self.rb +18 -1
  177. data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +5 -5
  178. data/lib/rubocop/cop/style/rescue_modifier.rb +24 -0
  179. data/lib/rubocop/cop/style/safe_navigation.rb +23 -3
  180. data/lib/rubocop/cop/style/semicolon.rb +13 -2
  181. data/lib/rubocop/cop/style/single_line_methods.rb +8 -1
  182. data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
  183. data/lib/rubocop/cop/style/ternary_parentheses.rb +19 -0
  184. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +7 -1
  185. data/lib/rubocop/cop/style/trivial_accessors.rb +5 -5
  186. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  187. data/lib/rubocop/cop/team.rb +5 -0
  188. data/lib/rubocop/cop/util.rb +1 -1
  189. data/lib/rubocop/cop/utils/format_string.rb +120 -0
  190. data/lib/rubocop/cop/variable_force.rb +7 -5
  191. data/lib/rubocop/cop/variable_force/variable.rb +15 -2
  192. data/lib/rubocop/core_ext/string.rb +0 -24
  193. data/lib/rubocop/formatter/base_formatter.rb +2 -2
  194. data/lib/rubocop/formatter/clang_style_formatter.rb +9 -6
  195. data/lib/rubocop/formatter/emacs_style_formatter.rb +22 -9
  196. data/lib/rubocop/formatter/file_list_formatter.rb +1 -1
  197. data/lib/rubocop/formatter/formatter_set.rb +16 -15
  198. data/lib/rubocop/formatter/json_formatter.rb +6 -5
  199. data/lib/rubocop/formatter/pacman_formatter.rb +80 -0
  200. data/lib/rubocop/formatter/simple_text_formatter.rb +16 -4
  201. data/lib/rubocop/formatter/tap_formatter.rb +18 -7
  202. data/lib/rubocop/magic_comment.rb +4 -0
  203. data/lib/rubocop/node_pattern.rb +4 -2
  204. data/lib/rubocop/options.rb +21 -26
  205. data/lib/rubocop/processed_source.rb +1 -1
  206. data/lib/rubocop/rake_task.rb +1 -0
  207. data/lib/rubocop/result_cache.rb +24 -8
  208. data/lib/rubocop/runner.rb +60 -33
  209. data/lib/rubocop/target_finder.rb +12 -6
  210. data/lib/rubocop/version.rb +1 -1
  211. metadata +48 -33
  212. data/lib/rubocop/cop/mixin/ignored_method_patterns.rb +0 -19
  213. data/lib/rubocop/cop/mixin/safe_mode.rb +0 -22
@@ -55,6 +55,7 @@ require_relative 'rubocop/ast/node/range_node'
55
55
  require_relative 'rubocop/ast/node/regexp_node'
56
56
  require_relative 'rubocop/ast/node/resbody_node'
57
57
  require_relative 'rubocop/ast/node/retry_node'
58
+ require_relative 'rubocop/ast/node/return_node'
58
59
  require_relative 'rubocop/ast/node/self_class_node'
59
60
  require_relative 'rubocop/ast/node/send_node'
60
61
  require_relative 'rubocop/ast/node/str_node'
@@ -117,12 +118,12 @@ require_relative 'rubocop/cop/mixin/end_keyword_alignment'
117
118
  require_relative 'rubocop/cop/mixin/enforce_superclass'
118
119
  require_relative 'rubocop/cop/mixin/first_element_line_break'
119
120
  require_relative 'rubocop/cop/mixin/frozen_string_literal'
120
- require_relative 'rubocop/cop/mixin/hash_alignment'
121
+ require_relative 'rubocop/cop/mixin/hash_alignment_styles'
121
122
  require_relative 'rubocop/cop/mixin/ignored_pattern'
122
123
  require_relative 'rubocop/cop/mixin/ignored_methods'
123
- require_relative 'rubocop/cop/mixin/ignored_method_patterns'
124
124
  require_relative 'rubocop/cop/mixin/integer_node'
125
125
  require_relative 'rubocop/cop/mixin/interpolation'
126
+ require_relative 'rubocop/cop/mixin/line_length_help'
126
127
  require_relative 'rubocop/cop/mixin/match_range'
127
128
  require_relative 'rubocop/cop/mixin/method_complexity'
128
129
  require_relative 'rubocop/cop/mixin/method_preference'
@@ -142,9 +143,9 @@ require_relative 'rubocop/cop/mixin/percent_array'
142
143
  require_relative 'rubocop/cop/mixin/percent_literal'
143
144
  require_relative 'rubocop/cop/mixin/preceding_following_alignment'
144
145
  require_relative 'rubocop/cop/mixin/preferred_delimiters'
146
+ require_relative 'rubocop/cop/mixin/rational_literal'
145
147
  require_relative 'rubocop/cop/mixin/rescue_node'
146
148
  require_relative 'rubocop/cop/mixin/safe_assignment'
147
- require_relative 'rubocop/cop/mixin/safe_mode'
148
149
  require_relative 'rubocop/cop/mixin/space_after_punctuation'
149
150
  require_relative 'rubocop/cop/mixin/space_before_punctuation'
150
151
  require_relative 'rubocop/cop/mixin/surrounding_space'
@@ -158,6 +159,10 @@ require_relative 'rubocop/cop/mixin/trailing_comma'
158
159
  require_relative 'rubocop/cop/mixin/uncommunicative_name'
159
160
  require_relative 'rubocop/cop/mixin/unused_argument'
160
161
 
162
+ require_relative 'rubocop/cop/utils/format_string'
163
+
164
+ require_relative 'rubocop/cop/migration/department_name'
165
+
161
166
  require_relative 'rubocop/cop/correctors/alignment_corrector'
162
167
  require_relative 'rubocop/cop/correctors/condition_corrector'
163
168
  require_relative 'rubocop/cop/correctors/each_to_for_corrector'
@@ -185,10 +190,9 @@ require_relative 'rubocop/cop/gemspec/required_ruby_version'
185
190
  require_relative 'rubocop/cop/gemspec/ruby_version_globals_usage'
186
191
 
187
192
  require_relative 'rubocop/cop/layout/access_modifier_indentation'
188
- require_relative 'rubocop/cop/layout/align_arguments'
189
- require_relative 'rubocop/cop/layout/align_array'
190
- require_relative 'rubocop/cop/layout/align_hash'
191
- require_relative 'rubocop/cop/layout/align_parameters'
193
+ require_relative 'rubocop/cop/layout/argument_alignment'
194
+ require_relative 'rubocop/cop/layout/array_alignment'
195
+ require_relative 'rubocop/cop/layout/assignment_indentation'
192
196
  require_relative 'rubocop/cop/layout/block_alignment'
193
197
  require_relative 'rubocop/cop/layout/block_end_newline'
194
198
  require_relative 'rubocop/cop/layout/case_indentation'
@@ -209,29 +213,30 @@ require_relative 'rubocop/cop/layout/empty_lines_around_arguments'
209
213
  require_relative 'rubocop/cop/layout/empty_lines_around_begin_body'
210
214
  require_relative 'rubocop/cop/layout/empty_lines_around_block_body'
211
215
  require_relative 'rubocop/cop/layout/empty_lines_around_class_body'
212
- require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Metrics/LineLength
216
+ require_relative 'rubocop/cop/layout/empty_lines_around_exception_handling_keywords' # rubocop:disable Layout/LineLength
213
217
  require_relative 'rubocop/cop/layout/empty_lines_around_method_body'
214
218
  require_relative 'rubocop/cop/layout/empty_lines_around_module_body'
215
219
  require_relative 'rubocop/cop/layout/empty_lines'
216
220
  require_relative 'rubocop/cop/layout/end_alignment'
217
221
  require_relative 'rubocop/cop/layout/end_of_line'
218
222
  require_relative 'rubocop/cop/layout/extra_spacing'
223
+ require_relative 'rubocop/cop/layout/first_argument_indentation'
224
+ require_relative 'rubocop/cop/layout/first_array_element_indentation'
219
225
  require_relative 'rubocop/cop/layout/first_array_element_line_break'
226
+ require_relative 'rubocop/cop/layout/first_hash_element_indentation'
220
227
  require_relative 'rubocop/cop/layout/first_hash_element_line_break'
221
228
  require_relative 'rubocop/cop/layout/first_method_argument_line_break'
222
229
  require_relative 'rubocop/cop/layout/first_method_parameter_line_break'
230
+ require_relative 'rubocop/cop/layout/first_parameter_indentation'
231
+ require_relative 'rubocop/cop/layout/hash_alignment'
223
232
  require_relative 'rubocop/cop/layout/heredoc_argument_closing_parenthesis'
224
- require_relative 'rubocop/cop/layout/indent_assignment'
233
+ require_relative 'rubocop/cop/layout/heredoc_indentation'
225
234
  require_relative 'rubocop/cop/layout/indentation_consistency'
226
235
  require_relative 'rubocop/cop/layout/indentation_width'
227
- require_relative 'rubocop/cop/layout/indent_first_argument'
228
- require_relative 'rubocop/cop/layout/indent_first_array_element'
229
- require_relative 'rubocop/cop/layout/indent_first_hash_element'
230
- require_relative 'rubocop/cop/layout/indent_first_parameter'
231
- require_relative 'rubocop/cop/layout/indent_heredoc'
232
236
  require_relative 'rubocop/cop/layout/initial_indentation'
233
- require_relative 'rubocop/cop/layout/leading_blank_lines'
234
237
  require_relative 'rubocop/cop/layout/leading_comment_space'
238
+ require_relative 'rubocop/cop/layout/leading_empty_lines'
239
+ require_relative 'rubocop/cop/layout/line_length'
235
240
  require_relative 'rubocop/cop/layout/multiline_array_brace_layout'
236
241
  require_relative 'rubocop/cop/layout/multiline_array_line_breaks'
237
242
  require_relative 'rubocop/cop/layout/multiline_assignment_layout'
@@ -243,6 +248,7 @@ require_relative 'rubocop/cop/layout/multiline_method_call_brace_layout'
243
248
  require_relative 'rubocop/cop/layout/multiline_method_call_indentation'
244
249
  require_relative 'rubocop/cop/layout/multiline_method_definition_brace_layout'
245
250
  require_relative 'rubocop/cop/layout/multiline_operation_indentation'
251
+ require_relative 'rubocop/cop/layout/parameter_alignment'
246
252
  require_relative 'rubocop/cop/layout/rescue_ensure_alignment'
247
253
  require_relative 'rubocop/cop/layout/space_after_colon'
248
254
  require_relative 'rubocop/cop/layout/space_after_comma'
@@ -269,7 +275,7 @@ require_relative 'rubocop/cop/layout/space_inside_range_literal'
269
275
  require_relative 'rubocop/cop/layout/space_inside_reference_brackets'
270
276
  require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
271
277
  require_relative 'rubocop/cop/layout/tab'
272
- require_relative 'rubocop/cop/layout/trailing_blank_lines'
278
+ require_relative 'rubocop/cop/layout/trailing_empty_lines'
273
279
  require_relative 'rubocop/cop/layout/trailing_whitespace'
274
280
 
275
281
  require_relative 'rubocop/cop/lint/ambiguous_block_association'
@@ -283,8 +289,8 @@ require_relative 'rubocop/cop/lint/debugger'
283
289
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
284
290
  require_relative 'rubocop/cop/lint/disjunctive_assignment_in_constructor'
285
291
  require_relative 'rubocop/cop/lint/duplicate_case_condition'
292
+ require_relative 'rubocop/cop/lint/duplicate_hash_key'
286
293
  require_relative 'rubocop/cop/lint/duplicate_methods'
287
- require_relative 'rubocop/cop/lint/duplicated_key'
288
294
  require_relative 'rubocop/cop/lint/each_with_object_argument'
289
295
  require_relative 'rubocop/cop/lint/else_layout'
290
296
  require_relative 'rubocop/cop/lint/empty_ensure'
@@ -297,7 +303,6 @@ require_relative 'rubocop/cop/lint/erb_new_arguments'
297
303
  require_relative 'rubocop/cop/lint/flip_flop'
298
304
  require_relative 'rubocop/cop/lint/float_out_of_range'
299
305
  require_relative 'rubocop/cop/lint/format_parameter_mismatch'
300
- require_relative 'rubocop/cop/lint/handle_exceptions'
301
306
  require_relative 'rubocop/cop/lint/heredoc_method_call_position'
302
307
  require_relative 'rubocop/cop/lint/implicit_string_concatenation'
303
308
  require_relative 'rubocop/cop/lint/inherit_exception'
@@ -307,10 +312,11 @@ require_relative 'rubocop/cop/lint/literal_as_condition'
307
312
  require_relative 'rubocop/cop/lint/literal_in_interpolation'
308
313
  require_relative 'rubocop/cop/lint/loop'
309
314
  require_relative 'rubocop/cop/lint/missing_cop_enable_directive'
310
- require_relative 'rubocop/cop/lint/multiple_compare'
315
+ require_relative 'rubocop/cop/lint/multiple_comparison'
311
316
  require_relative 'rubocop/cop/lint/nested_method_definition'
312
317
  require_relative 'rubocop/cop/lint/nested_percent_literal'
313
318
  require_relative 'rubocop/cop/lint/next_without_accumulator'
319
+ require_relative 'rubocop/cop/lint/non_deterministic_require_order'
314
320
  require_relative 'rubocop/cop/lint/non_local_exit_from_iterator'
315
321
  require_relative 'rubocop/cop/lint/number_conversion'
316
322
  require_relative 'rubocop/cop/lint/ordered_magic_comments'
@@ -318,6 +324,11 @@ require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
318
324
  require_relative 'rubocop/cop/lint/percent_string_array'
319
325
  require_relative 'rubocop/cop/lint/percent_symbol_array'
320
326
  require_relative 'rubocop/cop/lint/rand_one'
327
+ require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
328
+ require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
329
+ require_relative 'rubocop/cop/lint/redundant_require_statement'
330
+ require_relative 'rubocop/cop/lint/redundant_splat_expansion'
331
+ require_relative 'rubocop/cop/lint/redundant_string_coercion'
321
332
  require_relative 'rubocop/cop/lint/redundant_with_index'
322
333
  require_relative 'rubocop/cop/lint/redundant_with_object'
323
334
  require_relative 'rubocop/cop/lint/regexp_as_condition'
@@ -329,18 +340,15 @@ require_relative 'rubocop/cop/lint/safe_navigation_consistency'
329
340
  require_relative 'rubocop/cop/lint/safe_navigation_chain'
330
341
  require_relative 'rubocop/cop/lint/safe_navigation_with_empty'
331
342
  require_relative 'rubocop/cop/lint/script_permission'
343
+ require_relative 'rubocop/cop/lint/send_with_mixin_argument'
332
344
  require_relative 'rubocop/cop/lint/shadowed_argument'
333
345
  require_relative 'rubocop/cop/lint/shadowed_exception'
334
346
  require_relative 'rubocop/cop/lint/shadowing_outer_local_variable'
335
- require_relative 'rubocop/cop/lint/string_conversion_in_interpolation'
347
+ require_relative 'rubocop/cop/lint/suppressed_exception'
336
348
  require_relative 'rubocop/cop/lint/syntax'
337
349
  require_relative 'rubocop/cop/lint/to_json'
338
350
  require_relative 'rubocop/cop/lint/underscore_prefixed_variable_name'
339
351
  require_relative 'rubocop/cop/lint/unified_integer'
340
- require_relative 'rubocop/cop/lint/unneeded_cop_disable_directive'
341
- require_relative 'rubocop/cop/lint/unneeded_cop_enable_directive'
342
- require_relative 'rubocop/cop/lint/unneeded_require_statement'
343
- require_relative 'rubocop/cop/lint/unneeded_splat_expansion'
344
352
  require_relative 'rubocop/cop/lint/unreachable_code'
345
353
  require_relative 'rubocop/cop/lint/unused_block_argument'
346
354
  require_relative 'rubocop/cop/lint/unused_method_argument'
@@ -360,7 +368,6 @@ require_relative 'rubocop/cop/metrics/abc_size'
360
368
  require_relative 'rubocop/cop/metrics/block_length'
361
369
  require_relative 'rubocop/cop/metrics/block_nesting'
362
370
  require_relative 'rubocop/cop/metrics/class_length'
363
- require_relative 'rubocop/cop/metrics/line_length'
364
371
  require_relative 'rubocop/cop/metrics/method_length'
365
372
  require_relative 'rubocop/cop/metrics/module_length'
366
373
  require_relative 'rubocop/cop/metrics/parameter_lists'
@@ -368,6 +375,7 @@ require_relative 'rubocop/cop/metrics/perceived_complexity'
368
375
 
369
376
  require_relative 'rubocop/cop/naming/accessor_method_name'
370
377
  require_relative 'rubocop/cop/naming/ascii_identifiers'
378
+ require_relative 'rubocop/cop/naming/block_parameter_name'
371
379
  require_relative 'rubocop/cop/naming/class_and_module_camel_case'
372
380
  require_relative 'rubocop/cop/naming/constant_name'
373
381
  require_relative 'rubocop/cop/naming/file_name'
@@ -375,11 +383,10 @@ require_relative 'rubocop/cop/naming/heredoc_delimiter_case'
375
383
  require_relative 'rubocop/cop/naming/heredoc_delimiter_naming'
376
384
  require_relative 'rubocop/cop/naming/memoized_instance_variable_name'
377
385
  require_relative 'rubocop/cop/naming/method_name'
386
+ require_relative 'rubocop/cop/naming/method_parameter_name'
378
387
  require_relative 'rubocop/cop/naming/binary_operator_parameter_name'
379
388
  require_relative 'rubocop/cop/naming/predicate_name'
380
389
  require_relative 'rubocop/cop/naming/rescued_exceptions_variable_name'
381
- require_relative 'rubocop/cop/naming/uncommunicative_block_param_name'
382
- require_relative 'rubocop/cop/naming/uncommunicative_method_param_name'
383
390
  require_relative 'rubocop/cop/naming/variable_name'
384
391
  require_relative 'rubocop/cop/naming/variable_number'
385
392
 
@@ -498,12 +505,17 @@ require_relative 'rubocop/cop/style/proc'
498
505
  require_relative 'rubocop/cop/style/raise_args'
499
506
  require_relative 'rubocop/cop/style/random_with_offset'
500
507
  require_relative 'rubocop/cop/style/redundant_begin'
508
+ require_relative 'rubocop/cop/style/redundant_capital_w'
509
+ require_relative 'rubocop/cop/style/redundant_condition'
501
510
  require_relative 'rubocop/cop/style/redundant_conditional'
502
511
  require_relative 'rubocop/cop/style/redundant_exception'
503
512
  require_relative 'rubocop/cop/style/redundant_freeze'
513
+ require_relative 'rubocop/cop/style/redundant_interpolation'
504
514
  require_relative 'rubocop/cop/style/redundant_parentheses'
515
+ require_relative 'rubocop/cop/style/redundant_percent_q'
505
516
  require_relative 'rubocop/cop/style/redundant_return'
506
517
  require_relative 'rubocop/cop/style/redundant_self'
518
+ require_relative 'rubocop/cop/style/redundant_sort'
507
519
  require_relative 'rubocop/cop/style/redundant_sort_by'
508
520
  require_relative 'rubocop/cop/style/regexp_literal'
509
521
  require_relative 'rubocop/cop/style/rescue_modifier'
@@ -540,11 +552,6 @@ require_relative 'rubocop/cop/style/trailing_method_end_statement'
540
552
  require_relative 'rubocop/cop/style/trailing_underscore_variable'
541
553
  require_relative 'rubocop/cop/style/trivial_accessors'
542
554
  require_relative 'rubocop/cop/style/unless_else'
543
- require_relative 'rubocop/cop/style/unneeded_capital_w'
544
- require_relative 'rubocop/cop/style/unneeded_condition'
545
- require_relative 'rubocop/cop/style/unneeded_interpolation'
546
- require_relative 'rubocop/cop/style/unneeded_percent_q'
547
- require_relative 'rubocop/cop/style/unneeded_sort'
548
555
  require_relative 'rubocop/cop/style/unpack_first'
549
556
  require_relative 'rubocop/cop/style/variable_interpolation'
550
557
  require_relative 'rubocop/cop/style/when_then'
@@ -578,6 +585,7 @@ require_relative 'rubocop/formatter/progress_formatter'
578
585
  require_relative 'rubocop/formatter/quiet_formatter'
579
586
  require_relative 'rubocop/formatter/tap_formatter'
580
587
  require_relative 'rubocop/formatter/worst_offenders_formatter'
588
+ require_relative 'rubocop/formatter/pacman_formatter'
581
589
  # relies on progress formatter
582
590
  require_relative 'rubocop/formatter/auto_gen_config_formatter'
583
591
 
@@ -598,6 +606,14 @@ require_relative 'rubocop/processed_source'
598
606
  require_relative 'rubocop/result_cache'
599
607
  require_relative 'rubocop/runner'
600
608
  require_relative 'rubocop/cli'
609
+ require_relative 'rubocop/cli/command'
610
+ require_relative 'rubocop/cli/environment'
611
+ require_relative 'rubocop/cli/command/base'
612
+ require_relative 'rubocop/cli/command/auto_genenerate_config'
613
+ require_relative 'rubocop/cli/command/execute_runner'
614
+ require_relative 'rubocop/cli/command/init_dotfile'
615
+ require_relative 'rubocop/cli/command/show_cops'
616
+ require_relative 'rubocop/cli/command/version'
601
617
  require_relative 'rubocop/options'
602
618
  require_relative 'rubocop/remote_config'
603
619
  require_relative 'rubocop/yaml_duplication_checker'
@@ -41,6 +41,7 @@ module RuboCop
41
41
  regexp: RegexpNode,
42
42
  resbody: ResbodyNode,
43
43
  retry: RetryNode,
44
+ return: ReturnNode,
44
45
  csend: SendNode,
45
46
  send: SendNode,
46
47
  str: StrNode,
@@ -469,6 +469,10 @@ module RuboCop
469
469
  parent&.send_type? && parent.arguments.include?(self)
470
470
  end
471
471
 
472
+ def boolean_type?
473
+ true_type? || false_type?
474
+ end
475
+
472
476
  def numeric_type?
473
477
  int_type? || float_type?
474
478
  end
@@ -620,7 +624,7 @@ module RuboCop
620
624
  end
621
625
 
622
626
  def parent_module_name_for_block(ancestor)
623
- if ancestor.method_name == :class_eval
627
+ if ancestor.method?(:class_eval)
624
628
  # `class_eval` with no receiver applies to whatever module or class
625
629
  # we are currently in
626
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.
@@ -222,22 +222,11 @@ module RuboCop
222
222
 
223
223
  def_node_matcher :macro_scope?, <<~PATTERN
224
224
  {^{({sclass class module block} ...) class_constructor?}
225
- ^^#ascend_macro_scope?
225
+ ^^{({sclass class module block} ... ({begin if} ...)) class_constructor?}
226
226
  ^#macro_kwbegin_wrapper?
227
227
  #root_node?}
228
228
  PATTERN
229
229
 
230
- def_node_matcher :wrapped_macro_scope?, <<~PATTERN
231
- {({sclass class module block} ... ({begin if} ...)) class_constructor?}
232
- PATTERN
233
-
234
- def ascend_macro_scope?(ancestor)
235
- return true if wrapped_macro_scope?(ancestor)
236
- return false if root_node?(ancestor)
237
-
238
- ascend_macro_scope?(ancestor.parent)
239
- end
240
-
241
230
  # Check if a node's parent is a kwbegin wrapper within a macro scope
242
231
  #
243
232
  # @param parent [Node] parent of the node being checked
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A node extension for `return` nodes. This will be used in place of a
6
+ # plain node when the builder constructs the AST, making its methods
7
+ # available to all `return` nodes within RuboCop.
8
+ class ReturnNode < Node
9
+ include MethodDispatchNode
10
+ include ParameterizedNode
11
+
12
+ # Returns the arguments of the `return`.
13
+ #
14
+ # @return [Array] The arguments of the `return`.
15
+ def arguments
16
+ if node_parts.one? && node_parts.first.begin_type?
17
+ node_parts.first.children
18
+ else
19
+ node_parts
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -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,110 +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
- puts Rainbow("#{PHASE_1} #{PHASE_1_DISABLED}").yellow
87
- ''
88
- elsif !same_max_line_length?(
89
- @config_store.for(Dir.pwd), ConfigLoader.default_configuration
90
- )
91
- puts Rainbow("#{PHASE_1} #{PHASE_1_OVERRIDDEN}").yellow
92
- ''
93
- else
94
- run_line_length_cop_auto_gen_config(paths)
95
- end
96
- end
97
-
98
- def line_length_enabled?(config)
99
- line_length_cop(config)['Enabled']
100
- end
101
-
102
- def same_max_line_length?(config1, config2)
103
- max_line_length(config1) == max_line_length(config2)
104
- end
105
-
106
- def max_line_length(config)
107
- line_length_cop(config)['Max']
108
- end
109
-
110
- def line_length_cop(config)
111
- config.for_cop('Metrics/LineLength')
64
+ def run_command(name)
65
+ @env.run(name)
112
66
  end
113
67
 
114
- # Do an initial run with only Metrics/LineLength so that cops that depend
115
- # on Metrics/LineLength:Max get the correct value for that parameter.
116
- def run_line_length_cop_auto_gen_config(paths)
117
- puts Rainbow(PHASE_1).yellow
118
- @options[:only] = ['Metrics/LineLength']
119
- execute_runner(paths)
120
- @options.delete(:only)
121
- @config_store = ConfigStore.new
122
- # Save the todo configuration of the LineLength cop.
123
- IO.read(ConfigLoader::AUTO_GENERATED_FILE)
124
- .lines
125
- .drop_while { |line| line.start_with?('#') }
126
- .join
127
- end
128
-
129
- def run_all_cops_auto_gen_config(line_length_contents, paths)
130
- puts Rainbow(PHASE_2).yellow
131
- result = execute_runner(paths)
132
- # This run was made with the current maximum length allowed, so append
133
- # the saved setting for LineLength.
134
- File.open(ConfigLoader::AUTO_GENERATED_FILE, 'a') do |f|
135
- f.write(line_length_contents)
136
- end
137
- result
138
- end
139
-
140
- def init_dotfile
141
- path = File.expand_path(ConfigLoader::DOTFILE)
142
-
143
- if File.exist?(ConfigLoader::DOTFILE)
144
- warn Rainbow("#{ConfigLoader::DOTFILE} already exists at #{path}").red
145
-
146
- STATUS_ERROR
68
+ def execute_runners
69
+ if @options[:auto_gen_config]
70
+ run_command(:auto_gen_config)
147
71
  else
148
- description = <<~DESC
149
- # The behavior of RuboCop can be controlled via the .rubocop.yml
150
- # configuration file. It makes it possible to enable/disable
151
- # certain cops (checks) and to alter their behavior if they accept
152
- # any parameters. The file can be placed either in your home
153
- # directory or in some project directory.
154
- #
155
- # RuboCop will start looking for the configuration file in the directory
156
- # where the inspected file is and continue its way up to the root directory.
157
- #
158
- # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
159
- DESC
160
-
161
- File.open(ConfigLoader::DOTFILE, 'w') do |f|
162
- f.write(description)
163
- end
164
-
165
- puts "Writing new #{ConfigLoader::DOTFILE} to #{path}"
166
-
167
- STATUS_SUCCESS
72
+ run_command(:execute_runner)
168
73
  end
169
74
  end
170
75
 
171
- def reset_config_and_auto_gen_file
172
- @config_store = ConfigStore.new
173
- @config_store.options_config = @options[:config] if @options[:config]
174
- File.open(ConfigLoader::AUTO_GENERATED_FILE, 'w') {}
175
- ConfigLoader.add_inheritance_from_auto_generated_file
176
- end
177
-
178
76
  def validate_options_vs_config
179
77
  if @options[:parallel] &&
180
78
  !@config_store.for(Dir.pwd).for_all_cops['UseCache']
@@ -204,31 +102,11 @@ module RuboCop
204
102
  end
205
103
  end
206
104
 
207
- def execute_runner(paths)
208
- runner = Runner.new(@options, @config_store)
209
-
210
- all_passed = runner.run(paths)
211
- display_warning_summary(runner.warnings)
212
- display_error_summary(runner.errors)
213
- maybe_print_corrected_source
214
-
215
- all_pass_or_excluded = all_passed || @options[:auto_gen_config]
216
-
217
- if runner.aborting?
218
- STATUS_INTERRUPTED
219
- elsif all_pass_or_excluded && runner.errors.empty?
220
- STATUS_SUCCESS
221
- else
222
- STATUS_OFFENSES
223
- end
224
- end
225
-
226
105
  def handle_exiting_options
227
106
  return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
228
107
 
229
- puts RuboCop::Version.version(false) if @options[:version]
230
- puts RuboCop::Version.version(true) if @options[:verbose_version]
231
- 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]
232
110
  raise Finished
233
111
  end
234
112
 
@@ -244,100 +122,6 @@ module RuboCop
244
122
  end
245
123
  [[formatter, @options[:output_path]]]
246
124
  end
247
-
248
- return unless @options[:auto_gen_config]
249
-
250
- @options[:formatters] << [Formatter::DisabledConfigFormatter,
251
- ConfigLoader::AUTO_GENERATED_FILE]
252
- end
253
-
254
- def print_available_cops
255
- # Load the configs so the require()s are done for custom cops
256
- @config_store.for(Dir.pwd)
257
- registry = Cop::Cop.registry
258
- show_all = @options[:show_cops].empty?
259
-
260
- if show_all
261
- puts "# Available cops (#{registry.length}) + config for #{Dir.pwd}: "
262
- end
263
-
264
- registry.departments.sort!.each do |department|
265
- print_cops_of_department(registry, department, show_all)
266
- end
267
- end
268
-
269
- def print_cops_of_department(registry, department, show_all)
270
- selected_cops = if show_all
271
- cops_of_department(registry, department)
272
- else
273
- selected_cops_of_department(registry, department)
274
- end
275
-
276
- puts "# Department '#{department}' (#{selected_cops.length}):" if show_all
277
-
278
- print_cop_details(selected_cops)
279
- end
280
-
281
- def print_cop_details(cops)
282
- cops.each do |cop|
283
- puts '# Supports --auto-correct' if cop.new.support_autocorrect?
284
- puts "#{cop.cop_name}:"
285
- puts config_lines(cop)
286
- puts
287
- end
288
- end
289
-
290
- def selected_cops_of_department(cops, department)
291
- cops_of_department(cops, department).select do |cop|
292
- @options[:show_cops].include?(cop.cop_name)
293
- end
294
- end
295
-
296
- def cops_of_department(cops, department)
297
- cops.with_department(department).sort!
298
- end
299
-
300
- def config_lines(cop)
301
- cnf = @config_store.for(Dir.pwd).for_cop(cop)
302
- cnf.to_yaml.lines.to_a.drop(1).map { |line| ' ' + line }
303
- end
304
-
305
- def display_warning_summary(warnings)
306
- return if warnings.empty?
307
-
308
- warn Rainbow("\n#{pluralize(warnings.size, 'warning')}:").yellow
309
-
310
- warnings.each { |warning| warn warning }
311
- end
312
-
313
- def display_error_summary(errors)
314
- return if errors.empty?
315
-
316
- warn Rainbow("\n#{pluralize(errors.size, 'error')} occurred:").red
317
-
318
- errors.each { |error| warn error }
319
-
320
- warn <<~WARNING
321
- Errors are usually caused by RuboCop bugs.
322
- Please, report your problems to RuboCop's issue tracker.
323
- #{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}
324
-
325
- Mention the following information in the issue report:
326
- #{RuboCop::Version.version(true)}
327
- WARNING
328
- end
329
-
330
- def maybe_print_corrected_source
331
- # If we are asked to autocorrect source code read from stdin, the only
332
- # reasonable place to write it is to stdout
333
- # Unfortunately, we also write other information to stdout
334
- # So a delimiter is needed for tools to easily identify where the
335
- # autocorrected source begins
336
- return unless @options[:stdin] && @options[:auto_correct]
337
-
338
- puts '=' * 20
339
- print @options[:stdin]
340
125
  end
341
126
  end
342
127
  end
343
- # rubocop:enable Metrics/ClassLength