rubocop 1.19.0 → 1.23.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 (236) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +129 -21
  4. data/lib/rubocop/config.rb +5 -0
  5. data/lib/rubocop/config_loader.rb +5 -3
  6. data/lib/rubocop/config_validator.rb +9 -1
  7. data/lib/rubocop/cop/base.rb +3 -3
  8. data/lib/rubocop/cop/bundler/gem_comment.rb +3 -3
  9. data/lib/rubocop/cop/bundler/gem_filename.rb +103 -0
  10. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +45 -21
  11. data/lib/rubocop/cop/bundler/ordered_gems.rb +3 -12
  12. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +2 -2
  13. data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
  14. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +11 -10
  15. data/lib/rubocop/cop/documentation.rb +1 -1
  16. data/lib/rubocop/cop/gemspec/date_assignment.rb +2 -10
  17. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -10
  18. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +3 -12
  19. data/lib/rubocop/cop/gemspec/require_mfa.rb +146 -0
  20. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +31 -24
  21. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -10
  22. data/lib/rubocop/cop/generator.rb +14 -8
  23. data/lib/rubocop/cop/internal_affairs/location_line_equality_comparison.rb +60 -0
  24. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  25. data/lib/rubocop/cop/internal_affairs.rb +1 -0
  26. data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
  27. data/lib/rubocop/cop/layout/assignment_indentation.rb +1 -1
  28. data/lib/rubocop/cop/layout/block_alignment.rb +3 -3
  29. data/lib/rubocop/cop/layout/class_structure.rb +2 -1
  30. data/lib/rubocop/cop/layout/dot_position.rb +34 -5
  31. data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
  32. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +22 -1
  33. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +7 -4
  34. data/lib/rubocop/cop/layout/end_alignment.rb +2 -3
  35. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +1 -1
  36. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
  37. data/lib/rubocop/cop/layout/first_parameter_indentation.rb +1 -1
  38. data/lib/rubocop/cop/layout/hash_alignment.rb +1 -1
  39. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +1 -1
  40. data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
  41. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  42. data/lib/rubocop/cop/layout/line_length.rb +9 -7
  43. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  44. data/lib/rubocop/cop/layout/multiline_block_layout.rb +3 -3
  45. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +3 -0
  46. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +1 -1
  47. data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -0
  48. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +6 -5
  49. data/lib/rubocop/cop/layout/single_line_block_chain.rb +15 -4
  50. data/lib/rubocop/cop/layout/space_after_not.rb +1 -0
  51. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -1
  52. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  53. data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -0
  54. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
  55. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +11 -5
  56. data/lib/rubocop/cop/layout/space_inside_parens.rb +74 -28
  57. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
  58. data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +111 -0
  59. data/lib/rubocop/cop/lint/ambiguous_range.rb +11 -11
  60. data/lib/rubocop/cop/lint/assignment_in_condition.rb +7 -5
  61. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +18 -5
  62. data/lib/rubocop/cop/lint/boolean_symbol.rb +5 -0
  63. data/lib/rubocop/cop/lint/debugger.rb +2 -4
  64. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
  65. data/lib/rubocop/cop/lint/deprecated_constants.rb +3 -2
  66. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +24 -1
  67. data/lib/rubocop/cop/lint/else_layout.rb +10 -6
  68. data/lib/rubocop/cop/lint/empty_in_pattern.rb +1 -1
  69. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  70. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  71. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +12 -3
  72. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +67 -0
  73. data/lib/rubocop/cop/lint/interpolation_check.rb +5 -0
  74. data/lib/rubocop/cop/lint/loop.rb +4 -3
  75. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +5 -1
  76. data/lib/rubocop/cop/lint/number_conversion.rb +16 -2
  77. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -1
  78. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +4 -2
  79. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +17 -0
  80. data/lib/rubocop/cop/lint/percent_string_array.rb +10 -0
  81. data/lib/rubocop/cop/lint/raise_exception.rb +4 -0
  82. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +5 -4
  83. data/lib/rubocop/cop/lint/require_relative_self_path.rb +50 -0
  84. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
  85. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  86. data/lib/rubocop/cop/lint/triple_quotes.rb +1 -1
  87. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +8 -3
  88. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -3
  89. data/lib/rubocop/cop/lint/useless_method_definition.rb +3 -2
  90. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +117 -0
  91. data/lib/rubocop/cop/lint/useless_setter_call.rb +7 -4
  92. data/lib/rubocop/cop/lint/useless_times.rb +4 -3
  93. data/lib/rubocop/cop/metrics/abc_size.rb +6 -0
  94. data/lib/rubocop/cop/metrics/parameter_lists.rb +5 -2
  95. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
  96. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  97. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  98. data/lib/rubocop/cop/mixin/annotation_comment.rb +57 -34
  99. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  100. data/lib/rubocop/cop/mixin/documentation_comment.rb +5 -2
  101. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -2
  102. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +23 -1
  103. data/lib/rubocop/cop/mixin/gemspec_help.rb +30 -0
  104. data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
  105. data/lib/rubocop/cop/mixin/heredoc.rb +1 -3
  106. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -1
  107. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -2
  108. data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +1 -1
  109. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +9 -1
  110. data/lib/rubocop/cop/mixin/percent_array.rb +11 -3
  111. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +9 -1
  112. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -1
  113. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  114. data/lib/rubocop/cop/mixin/statement_modifier.rb +1 -1
  115. data/lib/rubocop/cop/mixin/trailing_body.rb +1 -1
  116. data/lib/rubocop/cop/naming/ascii_identifiers.rb +0 -3
  117. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  118. data/lib/rubocop/cop/naming/constant_name.rb +1 -1
  119. data/lib/rubocop/cop/naming/file_name.rb +37 -4
  120. data/lib/rubocop/cop/naming/inclusive_language.rb +9 -9
  121. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +5 -4
  122. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +7 -0
  123. data/lib/rubocop/cop/security/io_methods.rb +49 -0
  124. data/lib/rubocop/cop/security/json_load.rb +8 -7
  125. data/lib/rubocop/cop/security/open.rb +4 -0
  126. data/lib/rubocop/cop/security/yaml_load.rb +4 -0
  127. data/lib/rubocop/cop/style/accessor_grouping.rb +2 -2
  128. data/lib/rubocop/cop/style/and_or.rb +5 -0
  129. data/lib/rubocop/cop/style/arguments_forwarding.rb +13 -2
  130. data/lib/rubocop/cop/style/array_coercion.rb +21 -3
  131. data/lib/rubocop/cop/style/ascii_comments.rb +0 -3
  132. data/lib/rubocop/cop/style/block_delimiters.rb +23 -6
  133. data/lib/rubocop/cop/style/case_equality.rb +6 -9
  134. data/lib/rubocop/cop/style/case_like_if.rb +5 -0
  135. data/lib/rubocop/cop/style/class_and_module_children.rb +9 -0
  136. data/lib/rubocop/cop/style/collection_compact.rb +7 -5
  137. data/lib/rubocop/cop/style/collection_methods.rb +8 -6
  138. data/lib/rubocop/cop/style/combinable_loops.rb +3 -2
  139. data/lib/rubocop/cop/style/comment_annotation.rb +25 -39
  140. data/lib/rubocop/cop/style/commented_keyword.rb +9 -4
  141. data/lib/rubocop/cop/style/date_time.rb +5 -0
  142. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
  143. data/lib/rubocop/cop/style/documentation.rb +23 -8
  144. data/lib/rubocop/cop/style/double_negation.rb +27 -6
  145. data/lib/rubocop/cop/style/empty_method.rb +2 -2
  146. data/lib/rubocop/cop/style/encoding.rb +26 -15
  147. data/lib/rubocop/cop/style/explicit_block_argument.rb +21 -11
  148. data/lib/rubocop/cop/style/float_division.rb +10 -2
  149. data/lib/rubocop/cop/style/format_string_token.rb +2 -1
  150. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +7 -2
  151. data/lib/rubocop/cop/style/global_std_stream.rb +4 -0
  152. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +11 -0
  153. data/lib/rubocop/cop/style/hash_each_methods.rb +5 -0
  154. data/lib/rubocop/cop/style/hash_except.rb +4 -3
  155. data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -6
  156. data/lib/rubocop/cop/style/hash_transform_values.rb +4 -6
  157. data/lib/rubocop/cop/style/identical_conditional_branches.rb +18 -16
  158. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +18 -4
  159. data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
  160. data/lib/rubocop/cop/style/inverse_methods.rb +9 -2
  161. data/lib/rubocop/cop/style/lambda_call.rb +1 -1
  162. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -1
  163. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -6
  164. data/lib/rubocop/cop/style/module_function.rb +8 -9
  165. data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +1 -1
  166. data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
  167. data/lib/rubocop/cop/style/mutable_constant.rb +73 -6
  168. data/lib/rubocop/cop/style/negated_if.rb +1 -1
  169. data/lib/rubocop/cop/style/negated_unless.rb +1 -1
  170. data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
  171. data/lib/rubocop/cop/style/not.rb +2 -2
  172. data/lib/rubocop/cop/style/numbered_parameters.rb +46 -0
  173. data/lib/rubocop/cop/style/numbered_parameters_limit.rb +50 -0
  174. data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
  175. data/lib/rubocop/cop/style/numeric_predicate.rb +5 -0
  176. data/lib/rubocop/cop/style/open_struct_use.rb +69 -0
  177. data/lib/rubocop/cop/style/optional_arguments.rb +4 -0
  178. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +14 -4
  179. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
  180. data/lib/rubocop/cop/style/parentheses_around_condition.rb +12 -2
  181. data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
  182. data/lib/rubocop/cop/style/preferred_hash_methods.rb +9 -4
  183. data/lib/rubocop/cop/style/quoted_symbols.rb +21 -7
  184. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  185. data/lib/rubocop/cop/style/redundant_argument.rb +19 -9
  186. data/lib/rubocop/cop/style/redundant_begin.rb +25 -0
  187. data/lib/rubocop/cop/style/redundant_condition.rb +2 -3
  188. data/lib/rubocop/cop/style/redundant_fetch_block.rb +4 -0
  189. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +12 -3
  190. data/lib/rubocop/cop/style/redundant_freeze.rb +4 -4
  191. data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
  192. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -3
  193. data/lib/rubocop/cop/style/redundant_self.rb +10 -0
  194. data/lib/rubocop/cop/style/redundant_self_assignment.rb +4 -3
  195. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +23 -28
  196. data/lib/rubocop/cop/style/redundant_sort.rb +51 -18
  197. data/lib/rubocop/cop/style/regexp_literal.rb +3 -3
  198. data/lib/rubocop/cop/style/return_nil.rb +2 -1
  199. data/lib/rubocop/cop/style/safe_navigation.rb +13 -2
  200. data/lib/rubocop/cop/style/select_by_regexp.rb +139 -0
  201. data/lib/rubocop/cop/style/single_argument_dig.rb +5 -0
  202. data/lib/rubocop/cop/style/slicing_with_range.rb +13 -0
  203. data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -0
  204. data/lib/rubocop/cop/style/special_global_vars.rb +4 -0
  205. data/lib/rubocop/cop/style/static_class.rb +5 -5
  206. data/lib/rubocop/cop/style/string_chars.rb +4 -2
  207. data/lib/rubocop/cop/style/string_concatenation.rb +5 -1
  208. data/lib/rubocop/cop/style/string_hash_keys.rb +4 -0
  209. data/lib/rubocop/cop/style/struct_inheritance.rb +4 -0
  210. data/lib/rubocop/cop/style/swap_values.rb +4 -2
  211. data/lib/rubocop/cop/style/symbol_array.rb +3 -3
  212. data/lib/rubocop/cop/style/symbol_proc.rb +26 -0
  213. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +19 -0
  214. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  215. data/lib/rubocop/cop/style/word_array.rb +3 -3
  216. data/lib/rubocop/cop/style/yoda_condition.rb +24 -7
  217. data/lib/rubocop/cop/style/zero_length_predicate.rb +6 -0
  218. data/lib/rubocop/cop/util.rb +15 -4
  219. data/lib/rubocop/cops_documentation_generator.rb +17 -5
  220. data/lib/rubocop/formatter/html_formatter.rb +5 -2
  221. data/lib/rubocop/formatter/json_formatter.rb +4 -1
  222. data/lib/rubocop/magic_comment.rb +44 -15
  223. data/lib/rubocop/options.rb +126 -112
  224. data/lib/rubocop/rake_task.rb +1 -1
  225. data/lib/rubocop/remote_config.rb +1 -1
  226. data/lib/rubocop/result_cache.rb +3 -3
  227. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  228. data/lib/rubocop/rspec/expect_offense.rb +6 -2
  229. data/lib/rubocop/rspec/parallel_formatter.rb +90 -0
  230. data/lib/rubocop/rspec/support.rb +1 -0
  231. data/lib/rubocop/runner.rb +2 -3
  232. data/lib/rubocop/target_finder.rb +1 -1
  233. data/lib/rubocop/version.rb +1 -1
  234. data/lib/rubocop/yaml_duplication_checker.rb +1 -1
  235. data/lib/rubocop.rb +14 -2
  236. metadata +20 -5
@@ -59,86 +59,111 @@ module RuboCop
59
59
 
60
60
  def define_options
61
61
  OptionParser.new do |opts|
62
- opts.banner = 'Usage: rubocop [options] [file1, file2, ...]'
62
+ opts.banner = rainbow.wrap('Usage: rubocop [options] [file1, file2, ...]').bright
63
63
 
64
- add_list_options(opts)
65
- add_only_options(opts)
66
- add_configuration_options(opts)
67
- add_formatting_options(opts)
68
-
69
- option(opts, '-r', '--require FILE') { |f| require_feature(f) }
70
-
71
- add_severity_option(opts)
72
- add_flags_with_optional_args(opts)
64
+ add_check_options(opts)
73
65
  add_cache_options(opts)
74
- add_boolean_flags(opts)
75
- add_aliases(opts)
66
+ add_output_options(opts)
67
+ add_autocorrection_options(opts)
68
+ add_config_generation_options(opts)
69
+ add_additional_modes(opts)
70
+ add_general_options(opts)
71
+ end
72
+ end
76
73
 
74
+ def add_check_options(opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
75
+ section(opts, 'Basic Options') do
76
+ option(opts, '-l', '--lint') do
77
+ @options[:only] ||= []
78
+ @options[:only] << 'Lint'
79
+ end
80
+ option(opts, '-x', '--fix-layout') do
81
+ @options[:only] ||= []
82
+ @options[:only] << 'Layout'
83
+ @options[:auto_correct] = true
84
+ end
85
+ option(opts, '--safe')
86
+ add_cop_selection_csv_option('except', opts)
87
+ add_cop_selection_csv_option('only', opts)
88
+ option(opts, '--only-guide-cops')
89
+ option(opts, '-F', '--fail-fast')
90
+ option(opts, '--disable-pending-cops')
91
+ option(opts, '--enable-pending-cops')
92
+ option(opts, '--ignore-disable-comments')
93
+ option(opts, '--force-exclusion')
94
+ option(opts, '--only-recognized-file-types')
95
+ option(opts, '--ignore-parent-exclusion')
96
+ option(opts, '--force-default-config')
77
97
  option(opts, '-s', '--stdin FILE')
98
+ option(opts, '-P', '--[no-]parallel')
99
+ add_severity_option(opts)
78
100
  end
79
101
  end
80
102
 
81
- def add_only_options(opts)
82
- add_cop_selection_csv_option('except', opts)
83
- add_cop_selection_csv_option('only', opts)
84
- option(opts, '--only-guide-cops')
85
- end
103
+ def add_output_options(opts) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
104
+ section(opts, 'Output Options') do
105
+ option(opts, '-f', '--format FORMATTER') do |key|
106
+ @options[:formatters] ||= []
107
+ @options[:formatters] << [key]
108
+ end
86
109
 
87
- def add_cop_selection_csv_option(option, opts)
88
- option(opts, "--#{option} [COP1,COP2,...]") do |list|
89
- unless list
90
- message = "--#{option} argument should be [COP1,COP2,...]."
110
+ option(opts, '-D', '--[no-]display-cop-names')
111
+ option(opts, '-E', '--extra-details')
112
+ option(opts, '-S', '--display-style-guide')
91
113
 
92
- raise OptionArgumentError, message
114
+ option(opts, '-o', '--out FILE') do |path|
115
+ if @options[:formatters]
116
+ @options[:formatters].last << path
117
+ else
118
+ @options[:output_path] = path
119
+ end
93
120
  end
94
121
 
95
- @options[:"#{option}"] = list.empty? ? [''] : list.split(',')
122
+ option(opts, '--stderr')
123
+ option(opts, '--display-time')
124
+ option(opts, '--display-only-failed')
125
+ option(opts, '--display-only-fail-level-offenses')
96
126
  end
97
127
  end
98
128
 
99
- def add_configuration_options(opts)
100
- option(opts, '-c', '--config FILE')
101
- option(opts, '--force-exclusion')
102
- option(opts, '--only-recognized-file-types')
103
- option(opts, '--ignore-parent-exclusion')
104
- option(opts, '--force-default-config')
105
- add_auto_gen_options(opts)
106
- end
107
-
108
- def add_auto_gen_options(opts)
109
- option(opts, '--auto-gen-config')
110
-
111
- option(opts, '--regenerate-todo') do
112
- @options.replace(ConfigRegeneration.new.options.merge(@options))
129
+ def add_autocorrection_options(opts)
130
+ section(opts, 'Auto-correction') do
131
+ option(opts, '-a', '--auto-correct') { @options[:safe_auto_correct] = true }
132
+ option(opts, '--safe-auto-correct') do
133
+ warn '--safe-auto-correct is deprecated; use --auto-correct'
134
+ @options[:safe_auto_correct] = @options[:auto_correct] = true
135
+ end
136
+ option(opts, '-A', '--auto-correct-all') { @options[:auto_correct] = true }
137
+ option(opts, '--disable-uncorrectable')
113
138
  end
139
+ end
114
140
 
115
- option(opts, '--exclude-limit COUNT') { @validator.validate_exclude_limit_option }
141
+ def add_config_generation_options(opts)
142
+ section(opts, 'Config Generation') do
143
+ option(opts, '--auto-gen-config')
116
144
 
117
- option(opts, '--disable-uncorrectable')
145
+ option(opts, '--regenerate-todo') do
146
+ @options.replace(ConfigRegeneration.new.options.merge(@options))
147
+ end
118
148
 
119
- option(opts, '--[no-]offense-counts')
120
- option(opts, '--[no-]auto-gen-only-exclude')
121
- option(opts, '--[no-]auto-gen-timestamp')
149
+ option(opts, '--exclude-limit COUNT') { @validator.validate_exclude_limit_option }
122
150
 
123
- option(opts, '--init')
151
+ option(opts, '--[no-]offense-counts')
152
+ option(opts, '--[no-]auto-gen-only-exclude')
153
+ option(opts, '--[no-]auto-gen-timestamp')
154
+ end
124
155
  end
125
156
 
126
- def add_formatting_options(opts)
127
- option(opts, '-f', '--format FORMATTER') do |key|
128
- @options[:formatters] ||= []
129
- @options[:formatters] << [key]
130
- end
157
+ def add_cop_selection_csv_option(option, opts)
158
+ option(opts, "--#{option} [COP1,COP2,...]") do |list|
159
+ unless list
160
+ message = "--#{option} argument should be [COP1,COP2,...]."
131
161
 
132
- option(opts, '-o', '--out FILE') do |path|
133
- if @options[:formatters]
134
- @options[:formatters].last << path
135
- else
136
- @options[:output_path] = path
162
+ raise OptionArgumentError, message
137
163
  end
138
- end
139
164
 
140
- option(opts, '--display-time')
141
- option(opts, '--display-only-failed')
165
+ @options[:"#{option}"] = list.empty? ? [''] : list.split(',')
166
+ end
142
167
  end
143
168
 
144
169
  def add_severity_option(opts)
@@ -148,62 +173,50 @@ module RuboCop
148
173
  table) do |severity|
149
174
  @options[:fail_level] = severity
150
175
  end
151
- option(opts, '--display-only-fail-level-offenses')
152
176
  end
153
177
 
154
- def add_flags_with_optional_args(opts)
155
- option(opts, '--show-cops [COP1,COP2,...]') do |list|
156
- @options[:show_cops] = list.nil? ? [] : list.split(',')
178
+ def add_cache_options(opts)
179
+ section(opts, 'Caching') do
180
+ option(opts, '-C', '--cache FLAG')
181
+ option(opts, '--cache-root DIR') { @validator.validate_cache_enabled_for_cache_root }
157
182
  end
158
183
  end
159
184
 
160
- def add_cache_options(opts)
161
- option(opts, '-C', '--cache FLAG')
162
- option(opts, '--cache-root DIR') { @validator.validate_cache_enabled_for_cache_root }
163
- end
164
-
165
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
166
- def add_boolean_flags(opts)
167
- option(opts, '-F', '--fail-fast')
168
- option(opts, '-d', '--debug')
169
- option(opts, '-D', '--[no-]display-cop-names')
170
- option(opts, '-E', '--extra-details')
171
- option(opts, '-S', '--display-style-guide')
172
- option(opts, '-a', '--auto-correct') { @options[:safe_auto_correct] = true }
173
- option(opts, '--safe-auto-correct') do
174
- warn '--safe-auto-correct is deprecated; use --auto-correct'
175
- @options[:safe_auto_correct] = @options[:auto_correct] = true
185
+ def add_additional_modes(opts)
186
+ section(opts, 'Additional Modes') do
187
+ option(opts, '-L', '--list-target-files')
188
+ option(opts, '--show-cops [COP1,COP2,...]') do |list|
189
+ @options[:show_cops] = list.nil? ? [] : list.split(',')
190
+ end
176
191
  end
177
- option(opts, '-A', '--auto-correct-all') { @options[:auto_correct] = true }
178
- option(opts, '--disable-pending-cops')
179
- option(opts, '--enable-pending-cops')
180
- option(opts, '--ignore-disable-comments')
181
-
182
- option(opts, '--safe')
183
-
184
- option(opts, '--stderr')
185
- option(opts, '--[no-]color')
186
-
187
- option(opts, '-v', '--version')
188
- option(opts, '-V', '--verbose-version')
189
- option(opts, '-P', '--[no-]parallel')
190
192
  end
191
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
192
193
 
193
- def add_aliases(opts)
194
- option(opts, '-l', '--lint') do
195
- @options[:only] ||= []
196
- @options[:only] << 'Lint'
194
+ def add_general_options(opts)
195
+ section(opts, 'General Options') do
196
+ option(opts, '--init')
197
+ option(opts, '-c', '--config FILE')
198
+ option(opts, '-d', '--debug')
199
+ option(opts, '-r', '--require FILE') { |f| require_feature(f) }
200
+ option(opts, '--[no-]color')
201
+ option(opts, '-v', '--version')
202
+ option(opts, '-V', '--verbose-version')
197
203
  end
198
- option(opts, '-x', '--fix-layout') do
199
- @options[:only] ||= []
200
- @options[:only] << 'Layout'
201
- @options[:auto_correct] = true
204
+ end
205
+
206
+ def rainbow
207
+ @rainbow ||= begin
208
+ rainbow = Rainbow.new
209
+ rainbow.enabled = false if ARGV.include?('--no-color')
210
+ rainbow
202
211
  end
203
212
  end
204
213
 
205
- def add_list_options(opts)
206
- option(opts, '-L', '--list-target-files')
214
+ # Creates a section of options in order to separate them visually when
215
+ # using `--help`.
216
+ def section(opts, heading, &_block)
217
+ heading = rainbow.wrap(heading).bright
218
+ opts.separator("\n#{heading}:\n")
219
+ yield
207
220
  end
208
221
 
209
222
  # Sets a value in the @options hash, based on the given long option and its
@@ -403,7 +416,7 @@ module RuboCop
403
416
  only: 'Run only the given cop(s).',
404
417
  only_guide_cops: ['Run only cops for rules that link to a',
405
418
  'style guide.'],
406
- except: 'Disable the given cop(s).',
419
+ except: 'Exclude the given cop(s).',
407
420
  require: 'Require Ruby file.',
408
421
  config: 'Specify configuration file.',
409
422
  auto_gen_config: ['Generate a configuration file acting as a',
@@ -422,29 +435,30 @@ module RuboCop
422
435
  'when running --auto-gen-config, except if the',
423
436
  'number of files with offenses is bigger than',
424
437
  'exclude-limit. Default is false.'],
425
- exclude_limit: ['Used together with --auto-gen-config to',
426
- 'set the limit for how many Exclude',
427
- "properties to generate. Default is #{MAX_EXCL}."],
438
+ exclude_limit: ['Set the limit for how many files to explicitly exclude.',
439
+ 'If there are more files than the limit, the cop will',
440
+ "be disabled instead. Default is #{MAX_EXCL}."],
428
441
  disable_uncorrectable: ['Used with --auto-correct to annotate any',
429
442
  'offenses that do not support autocorrect',
430
443
  'with `rubocop:todo` comments.'],
431
- force_exclusion: ['Force excluding files specified in the',
432
- 'configuration `Exclude` even if they are',
433
- 'explicitly passed as arguments.'],
444
+ force_exclusion: ['Any files excluded by `Exclude` in configuration',
445
+ 'files will be excluded, even if given explicitly',
446
+ 'as arguments.'],
434
447
  only_recognized_file_types: ['Inspect files given on the command line only if',
435
- 'they are listed in AllCops/Include parameters',
448
+ 'they are listed in `AllCops/Include` parameters',
436
449
  'of user configuration or default configuration.'],
437
450
  ignore_disable_comments: ['Run cops even when they are disabled locally',
438
- 'with a comment.'],
439
- ignore_parent_exclusion: ['Prevent from inheriting AllCops/Exclude from',
451
+ 'by a `rubocop:disable` directive.'],
452
+ ignore_parent_exclusion: ['Prevent from inheriting `AllCops/Exclude` from',
440
453
  'parent folders.'],
441
454
  force_default_config: ['Use default configuration even if configuration',
442
455
  'files are present in the directory tree.'],
443
456
  format: ['Choose an output formatter. This option',
444
457
  'can be specified multiple times to enable',
445
458
  'multiple formatters at the same time.',
446
- '[p]rogress is used by default',
447
- *FORMATTER_OPTION_LIST.map { |item| " #{item}" },
459
+ *FORMATTER_OPTION_LIST.map do |item|
460
+ " #{item}#{' (default)' if item == '[p]rogress'}"
461
+ end,
448
462
  ' custom formatter class name'],
449
463
  out: ['Write output to a file instead of STDOUT.',
450
464
  'This option applies to the previously',
@@ -33,7 +33,7 @@ module RuboCop
33
33
  private
34
34
 
35
35
  def run_cli(verbose, options)
36
- # We lazy-load rubocop so that the task doesn't dramatically impact the
36
+ # We lazy-load RuboCop so that the task doesn't dramatically impact the
37
37
  # load time of your Rakefile.
38
38
  require 'rubocop'
39
39
 
@@ -33,7 +33,7 @@ module RuboCop
33
33
 
34
34
  def inherit_from_remote(file, path)
35
35
  new_uri = @uri.dup
36
- new_uri.path.gsub!(%r{/[^/]*$}, "/#{file}")
36
+ new_uri.path.gsub!(%r{/[^/]*$}, "/#{file.delete_prefix('./')}")
37
37
  RemoteConfig.new(new_uri.to_s, File.dirname(path))
38
38
  end
39
39
 
@@ -6,7 +6,7 @@ require 'etc'
6
6
  require 'zlib'
7
7
 
8
8
  module RuboCop
9
- # Provides functionality for caching rubocop runs.
9
+ # Provides functionality for caching RuboCop runs.
10
10
  # @api private
11
11
  class ResultCache
12
12
  NON_CHANGING = %i[color format formatters out debug fail_level auto_correct
@@ -45,7 +45,7 @@ module RuboCop
45
45
  def remove_oldest_files(files, dirs, cache_root, verbose)
46
46
  # Add 1 to half the number of files, so that we remove the file if
47
47
  # there's only 1 left.
48
- remove_count = 1 + files.length / 2
48
+ remove_count = 1 + (files.length / 2)
49
49
  puts "Removing the #{remove_count} oldest files from #{cache_root}" if verbose
50
50
  sorted = files.sort_by { |path| File.mtime(path) }
51
51
  remove_files(sorted, dirs, remove_count)
@@ -170,7 +170,7 @@ module RuboCop
170
170
  attr_accessor :source_checksum, :inhibit_cleanup
171
171
  end
172
172
 
173
- # The checksum of the rubocop program running the inspection.
173
+ # The checksum of the RuboCop program running the inspection.
174
174
  def rubocop_checksum
175
175
  ResultCache.source_checksum ||=
176
176
  begin
@@ -49,7 +49,7 @@ module CopHelper
49
49
  team = RuboCop::Cop::Team.new([cop], nil, raise_error: true)
50
50
  report = team.investigate(processed_source)
51
51
  @last_corrector = report.correctors.first || RuboCop::Cop::Corrector.new(processed_source)
52
- report.offenses
52
+ report.offenses.reject(&:disabled?)
53
53
  end
54
54
  end
55
55
 
@@ -126,7 +126,7 @@ module RuboCop
126
126
  @offenses
127
127
  end
128
128
 
129
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
129
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
130
130
  def expect_correction(correction, loop: true, source: nil)
131
131
  if source
132
132
  expected_annotations = parse_annotations(source, raise_error: false)
@@ -136,6 +136,8 @@ module RuboCop
136
136
 
137
137
  raise '`expect_correction` must follow `expect_offense`' unless @processed_source
138
138
 
139
+ source = @processed_source.raw_source
140
+
139
141
  iteration = 0
140
142
  new_source = loop do
141
143
  iteration += 1
@@ -155,9 +157,11 @@ module RuboCop
155
157
  _investigate(cop, @processed_source)
156
158
  end
157
159
 
160
+ raise 'Use `expect_no_corrections` if the code will not change' if new_source == source
161
+
158
162
  expect(new_source).to eq(correction)
159
163
  end
160
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
164
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity
161
165
 
162
166
  def expect_no_corrections
163
167
  raise '`expect_no_corrections` must follow `expect_offense`' unless @processed_source
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec::Support.require_rspec_core 'formatters/base_text_formatter'
4
+ RSpec::Support.require_rspec_core 'formatters/console_codes'
5
+
6
+ module RuboCop
7
+ module RSpec
8
+ # RSpec formatter for use with running `rake spec` in parallel. This formatter
9
+ # removes much of the noise from RSpec so that only the important information
10
+ # will be surfaced by test-queue.
11
+ # It also adds metadata to the output in order to more easily find the text
12
+ # needed for outputting after the parallel run completes.
13
+ class ParallelFormatter < ::RSpec::Core::Formatters::BaseTextFormatter
14
+ ::RSpec::Core::Formatters.register self, :dump_pending, :dump_failures, :dump_summary
15
+
16
+ # Don't show pending tests
17
+ def dump_pending(*); end
18
+
19
+ # The BEGIN/END comments are used by `spec_runner.rake` to determine what
20
+ # output goes where in the final parallelized output, and should not be
21
+ # removed!
22
+ def dump_failures(notification)
23
+ return if notification.failure_notifications.empty?
24
+
25
+ output.puts '# FAILURES BEGIN'
26
+ notification.failure_notifications.each do |failure|
27
+ output.puts failure.fully_formatted('*', colorizer)
28
+ end
29
+ output.puts
30
+ output.puts '# FAILURES END'
31
+ end
32
+
33
+ def dump_summary(summary)
34
+ output_summary(summary)
35
+ output_rerun_commands(summary)
36
+ end
37
+
38
+ private
39
+
40
+ def colorizer
41
+ @colorizer ||= ::RSpec::Core::Formatters::ConsoleCodes
42
+ end
43
+
44
+ # The BEGIN/END comments are used by `spec_runner.rake` to determine what
45
+ # output goes where in the final parallelized output, and should not be
46
+ # removed!
47
+ def output_summary(summary)
48
+ output.puts '# SUMMARY BEGIN'
49
+ output.puts colorize_summary(summary)
50
+ output.puts '# SUMMARY END'
51
+ end
52
+
53
+ def colorize_summary(summary)
54
+ totals = totals(summary)
55
+
56
+ if summary.failure_count.positive? || summary.errors_outside_of_examples_count.positive?
57
+ colorizer.wrap(totals, ::RSpec.configuration.failure_color)
58
+ else
59
+ colorizer.wrap(totals, ::RSpec.configuration.success_color)
60
+ end
61
+ end
62
+
63
+ # The BEGIN/END comments are used by `spec_runner.rake` to determine what
64
+ # output goes where in the final parallelized output, and should not be
65
+ # removed!
66
+ def output_rerun_commands(summary)
67
+ output.puts '# RERUN BEGIN'
68
+ output.puts summary.colorized_rerun_commands.lines[3..-1].join
69
+ output.puts '# RERUN END'
70
+ end
71
+
72
+ def totals(summary)
73
+ output = pluralize(summary.example_count, 'example')
74
+ output += ", #{summary.pending_count} pending" if summary.pending_count.positive?
75
+ output += ", #{pluralize(summary.failure_count, 'failure')}"
76
+
77
+ if summary.errors_outside_of_examples_count.positive?
78
+ error_count = pluralize(summary.errors_outside_of_examples_count, 'error')
79
+ output += ", #{error_count} occurred outside of examples"
80
+ end
81
+
82
+ output
83
+ end
84
+
85
+ def pluralize(*args)
86
+ ::RSpec::Core::Formatters::Helpers.pluralize(*args)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -6,6 +6,7 @@ require_relative 'cop_helper'
6
6
  require_relative 'host_environment_simulation_helper'
7
7
  require_relative 'shared_contexts'
8
8
  require_relative 'expect_offense'
9
+ require_relative 'parallel_formatter'
9
10
 
10
11
  RSpec.configure do |config|
11
12
  config.include CopHelper
@@ -60,7 +60,7 @@ module RuboCop
60
60
 
61
61
  private
62
62
 
63
- # Warms up the RuboCop cache by forking a suitable number of rubocop
63
+ # Warms up the RuboCop cache by forking a suitable number of RuboCop
64
64
  # instances that each inspects its allotted group of files.
65
65
  def warm_cache(target_files)
66
66
  puts 'Running parallel inspection' if @options[:debug]
@@ -216,8 +216,7 @@ module RuboCop
216
216
  def cached_run?
217
217
  @cached_run ||=
218
218
  (@options[:cache] == 'true' ||
219
- @options[:cache] != 'false' &&
220
- @config_store.for_pwd.for_all_cops['UseCache']) &&
219
+ (@options[:cache] != 'false' && @config_store.for_pwd.for_all_cops['UseCache'])) &&
221
220
  # When running --auto-gen-config, there's some processing done in the
222
221
  # cops related to calculating the Max parameters for Metrics cops. We
223
222
  # need to do that processing and cannot use caching.
@@ -95,7 +95,7 @@ module RuboCop
95
95
 
96
96
  def wanted_dir_patterns(base_dir, exclude_pattern, flags)
97
97
  base_dir = base_dir.gsub('/{}/', '/\{}/')
98
- dirs = Dir.glob(File.join(base_dir.gsub('/**/', '/\**/'), '*/'), flags)
98
+ dirs = Dir.glob(File.join(base_dir.gsub('/*/', '/\*/').gsub('/**/', '/\**/'), '*/'), flags)
99
99
  .reject do |dir|
100
100
  next true if dir.end_with?('/./', '/../')
101
101
  next true if File.fnmatch?(exclude_pattern, dir, flags)
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  # This module holds the RuboCop version information.
5
5
  module Version
6
- STRING = '1.19.0'
6
+ STRING = '1.23.0'
7
7
 
8
8
  MSG = '%<version>s (using Parser %<parser_version>s, '\
9
9
  'rubocop-ast %<rubocop_ast_version>s, ' \
@@ -23,7 +23,7 @@ module RuboCop
23
23
  when Psych::Nodes::Mapping
24
24
  tree.children.each_slice(2).with_object([]) do |(key, value), keys|
25
25
  exist = keys.find { |key2| key2.value == key.value }
26
- on_duplicated.call(exist, key) if exist
26
+ yield(exist, key) if exist
27
27
  keys << key
28
28
  traverse(value, &on_duplicated)
29
29
  end