rubocop 1.43.0 → 1.50.2

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 (286) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +108 -40
  4. data/lib/rubocop/cli/command/auto_generate_config.rb +7 -0
  5. data/lib/rubocop/cli/command/execute_runner.rb +7 -2
  6. data/lib/rubocop/cli.rb +54 -8
  7. data/lib/rubocop/comment_config.rb +19 -0
  8. data/lib/rubocop/config.rb +3 -3
  9. data/lib/rubocop/config_loader.rb +20 -23
  10. data/lib/rubocop/config_loader_resolver.rb +3 -4
  11. data/lib/rubocop/cop/autocorrect_logic.rb +29 -13
  12. data/lib/rubocop/cop/base.rb +28 -10
  13. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  14. data/lib/rubocop/cop/commissioner.rb +8 -2
  15. data/lib/rubocop/cop/cop.rb +25 -5
  16. data/lib/rubocop/cop/corrector.rb +11 -3
  17. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
  18. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +3 -3
  19. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +3 -3
  20. data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
  21. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
  22. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +2 -7
  23. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
  24. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
  25. data/lib/rubocop/cop/gemspec/dependency_version.rb +1 -1
  26. data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +1 -1
  27. data/lib/rubocop/cop/gemspec/development_dependencies.rb +107 -0
  28. data/lib/rubocop/cop/internal_affairs/cop_description.rb +5 -5
  29. data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +3 -3
  30. data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
  31. data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
  32. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  33. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
  34. data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +42 -0
  35. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +11 -3
  36. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
  37. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
  38. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +66 -0
  39. data/lib/rubocop/cop/internal_affairs.rb +3 -0
  40. data/lib/rubocop/cop/layout/array_alignment.rb +1 -1
  41. data/lib/rubocop/cop/layout/block_end_newline.rb +7 -15
  42. data/lib/rubocop/cop/layout/class_structure.rb +8 -19
  43. data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -1
  44. data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +2 -6
  45. data/lib/rubocop/cop/layout/empty_comment.rb +3 -3
  46. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
  47. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  48. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
  49. data/lib/rubocop/cop/layout/end_alignment.rb +9 -1
  50. data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
  51. data/lib/rubocop/cop/layout/first_argument_indentation.rb +8 -3
  52. data/lib/rubocop/cop/layout/first_array_element_line_break.rb +25 -34
  53. data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +7 -19
  54. data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +42 -52
  55. data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +38 -55
  56. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +8 -2
  57. data/lib/rubocop/cop/layout/heredoc_indentation.rb +8 -11
  58. data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
  59. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  60. data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -3
  61. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +11 -7
  62. data/lib/rubocop/cop/layout/multiline_array_line_breaks.rb +8 -27
  63. data/lib/rubocop/cop/layout/multiline_hash_key_line_breaks.rb +7 -26
  64. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +4 -21
  65. data/lib/rubocop/cop/layout/multiline_method_parameter_line_breaks.rb +6 -30
  66. data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
  67. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -2
  68. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
  69. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  70. data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
  71. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
  72. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +11 -13
  73. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  74. data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
  75. data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
  76. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +4 -4
  77. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +5 -4
  78. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  79. data/lib/rubocop/cop/lint/ambiguous_operator.rb +4 -0
  80. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
  81. data/lib/rubocop/cop/lint/debugger.rb +11 -27
  82. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +62 -112
  83. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
  84. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
  85. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
  86. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -3
  87. data/lib/rubocop/cop/lint/else_layout.rb +3 -7
  88. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  89. data/lib/rubocop/cop/lint/empty_conditional_body.rb +4 -2
  90. data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
  91. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +14 -7
  92. data/lib/rubocop/cop/lint/heredoc_method_call_position.rb +15 -17
  93. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  94. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  95. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +46 -4
  96. data/lib/rubocop/cop/lint/missing_super.rb +31 -2
  97. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
  98. data/lib/rubocop/cop/lint/nested_method_definition.rb +4 -9
  99. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -0
  100. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +6 -10
  101. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  102. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  103. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +11 -5
  104. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
  105. data/lib/rubocop/cop/lint/redundant_require_statement.rb +12 -2
  106. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  107. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
  108. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
  109. data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
  110. data/lib/rubocop/cop/lint/refinement_import_methods.rb +2 -1
  111. data/lib/rubocop/cop/lint/rescue_type.rb +3 -3
  112. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +1 -1
  113. data/lib/rubocop/cop/lint/script_permission.rb +1 -1
  114. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
  115. data/lib/rubocop/cop/lint/syntax.rb +4 -0
  116. data/lib/rubocop/cop/lint/to_enum_arguments.rb +13 -3
  117. data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
  118. data/lib/rubocop/cop/lint/useless_access_modifier.rb +10 -7
  119. data/lib/rubocop/cop/lint/useless_method_definition.rb +12 -4
  120. data/lib/rubocop/cop/lint/useless_rescue.rb +20 -2
  121. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +9 -1
  122. data/lib/rubocop/cop/lint/useless_times.rb +1 -1
  123. data/lib/rubocop/cop/lint/void.rb +24 -11
  124. data/lib/rubocop/cop/metrics/block_length.rb +1 -1
  125. data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
  126. data/lib/rubocop/cop/metrics/class_length.rb +1 -0
  127. data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
  128. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +1 -1
  129. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +2 -5
  130. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +3 -3
  131. data/lib/rubocop/cop/migration/department_name.rb +1 -1
  132. data/lib/rubocop/cop/mixin/alignment.rb +1 -1
  133. data/lib/rubocop/cop/mixin/allowed_methods.rb +3 -1
  134. data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
  135. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  136. data/lib/rubocop/cop/mixin/comments_help.rb +8 -6
  137. data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
  138. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
  139. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +56 -25
  140. data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
  141. data/lib/rubocop/cop/mixin/line_length_help.rb +3 -1
  142. data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
  143. data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +0 -3
  144. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
  145. data/lib/rubocop/cop/mixin/range_help.rb +1 -6
  146. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
  147. data/lib/rubocop/cop/mixin/surrounding_space.rb +3 -3
  148. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -2
  149. data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
  150. data/lib/rubocop/cop/naming/block_forwarding.rb +4 -0
  151. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  152. data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
  153. data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
  154. data/lib/rubocop/cop/naming/method_name.rb +3 -3
  155. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  156. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  157. data/lib/rubocop/cop/registry.rb +15 -8
  158. data/lib/rubocop/cop/style/access_modifier_declarations.rb +26 -11
  159. data/lib/rubocop/cop/style/accessor_grouping.rb +39 -17
  160. data/lib/rubocop/cop/style/arguments_forwarding.rb +4 -3
  161. data/lib/rubocop/cop/style/array_intersect.rb +1 -1
  162. data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
  163. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +1 -1
  164. data/lib/rubocop/cop/style/block_comments.rb +1 -1
  165. data/lib/rubocop/cop/style/block_delimiters.rb +17 -2
  166. data/lib/rubocop/cop/style/case_like_if.rb +20 -3
  167. data/lib/rubocop/cop/style/class_and_module_children.rb +4 -11
  168. data/lib/rubocop/cop/style/class_equality_comparison.rb +42 -9
  169. data/lib/rubocop/cop/style/collection_compact.rb +4 -1
  170. data/lib/rubocop/cop/style/command_literal.rb +1 -1
  171. data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
  172. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  173. data/lib/rubocop/cop/style/comparable_clamp.rb +125 -0
  174. data/lib/rubocop/cop/style/concat_array_literals.rb +10 -2
  175. data/lib/rubocop/cop/style/conditional_assignment.rb +6 -12
  176. data/lib/rubocop/cop/style/copyright.rb +1 -1
  177. data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
  178. data/lib/rubocop/cop/style/dir_empty.rb +60 -0
  179. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
  180. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +2 -2
  181. data/lib/rubocop/cop/style/documentation.rb +11 -5
  182. data/lib/rubocop/cop/style/documentation_method.rb +10 -4
  183. data/lib/rubocop/cop/style/double_negation.rb +2 -2
  184. data/lib/rubocop/cop/style/each_with_object.rb +1 -1
  185. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  186. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  187. data/lib/rubocop/cop/style/eval_with_location.rb +4 -4
  188. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  189. data/lib/rubocop/cop/style/file_empty.rb +71 -0
  190. data/lib/rubocop/cop/style/file_read.rb +1 -1
  191. data/lib/rubocop/cop/style/file_write.rb +1 -1
  192. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  193. data/lib/rubocop/cop/style/guard_clause.rb +1 -1
  194. data/lib/rubocop/cop/style/hash_except.rb +4 -4
  195. data/lib/rubocop/cop/style/hash_like_case.rb +3 -9
  196. data/lib/rubocop/cop/style/hash_syntax.rb +5 -2
  197. data/lib/rubocop/cop/style/if_unless_modifier.rb +108 -15
  198. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
  199. data/lib/rubocop/cop/style/infinite_loop.rb +2 -5
  200. data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
  201. data/lib/rubocop/cop/style/invertible_unless_condition.rb +114 -0
  202. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +2 -2
  203. data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
  204. data/lib/rubocop/cop/style/map_to_set.rb +4 -1
  205. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +14 -12
  206. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +44 -37
  207. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -0
  208. data/lib/rubocop/cop/style/min_max.rb +3 -3
  209. data/lib/rubocop/cop/style/min_max_comparison.rb +11 -1
  210. data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
  211. data/lib/rubocop/cop/style/multiline_if_modifier.rb +0 -4
  212. data/lib/rubocop/cop/style/multiline_memoization.rb +2 -2
  213. data/lib/rubocop/cop/style/multiline_method_signature.rb +7 -4
  214. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +18 -3
  215. data/lib/rubocop/cop/style/negated_if_else_condition.rb +13 -12
  216. data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
  217. data/lib/rubocop/cop/style/numbered_parameters_limit.rb +11 -3
  218. data/lib/rubocop/cop/style/one_line_conditional.rb +3 -6
  219. data/lib/rubocop/cop/style/operator_method_call.rb +2 -2
  220. data/lib/rubocop/cop/style/parallel_assignment.rb +29 -19
  221. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
  222. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  223. data/lib/rubocop/cop/style/redundant_condition.rb +18 -3
  224. data/lib/rubocop/cop/style/redundant_conditional.rb +0 -4
  225. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +16 -10
  226. data/lib/rubocop/cop/style/redundant_fetch_block.rb +6 -4
  227. data/lib/rubocop/cop/style/redundant_heredoc_delimiter_quotes.rb +58 -0
  228. data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
  229. data/lib/rubocop/cop/style/redundant_line_continuation.rb +179 -0
  230. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -2
  231. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  232. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +7 -8
  233. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +11 -4
  234. data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
  235. data/lib/rubocop/cop/style/redundant_string_escape.rb +3 -4
  236. data/lib/rubocop/cop/style/require_order.rb +3 -12
  237. data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
  238. data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
  239. data/lib/rubocop/cop/style/self_assignment.rb +2 -2
  240. data/lib/rubocop/cop/style/semicolon.rb +24 -2
  241. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
  242. data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -3
  243. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  244. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
  245. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  246. data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
  247. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
  248. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  249. data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
  250. data/lib/rubocop/cop/style/unpack_first.rb +3 -3
  251. data/lib/rubocop/cop/style/word_array.rb +18 -6
  252. data/lib/rubocop/cop/style/yoda_condition.rb +13 -6
  253. data/lib/rubocop/cop/style/yoda_expression.rb +11 -2
  254. data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
  255. data/lib/rubocop/cop/team.rb +30 -22
  256. data/lib/rubocop/cop/util.rb +13 -4
  257. data/lib/rubocop/cop/variable_force/scope.rb +3 -3
  258. data/lib/rubocop/cop/variable_force/variable.rb +5 -3
  259. data/lib/rubocop/cop/variable_force/variable_table.rb +3 -1
  260. data/lib/rubocop/cop/variable_force.rb +1 -1
  261. data/lib/rubocop/cops_documentation_generator.rb +10 -3
  262. data/lib/rubocop/directive_comment.rb +3 -3
  263. data/lib/rubocop/ext/comment.rb +18 -0
  264. data/lib/rubocop/ext/regexp_node.rb +1 -1
  265. data/lib/rubocop/ext/regexp_parser.rb +1 -1
  266. data/lib/rubocop/formatter/junit_formatter.rb +4 -1
  267. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  268. data/lib/rubocop/formatter.rb +0 -1
  269. data/lib/rubocop/options.rb +26 -2
  270. data/lib/rubocop/result_cache.rb +1 -1
  271. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  272. data/lib/rubocop/rspec/expect_offense.rb +6 -4
  273. data/lib/rubocop/rspec/shared_contexts.rb +4 -0
  274. data/lib/rubocop/rspec/support.rb +1 -0
  275. data/lib/rubocop/runner.rb +40 -4
  276. data/lib/rubocop/server/cache.rb +11 -4
  277. data/lib/rubocop/server/cli.rb +37 -18
  278. data/lib/rubocop/server/client_command/exec.rb +1 -1
  279. data/lib/rubocop/server/client_command/start.rb +6 -1
  280. data/lib/rubocop/server/core.rb +24 -9
  281. data/lib/rubocop/server/helper.rb +1 -1
  282. data/lib/rubocop/server/server_command/exec.rb +1 -1
  283. data/lib/rubocop/target_ruby.rb +1 -1
  284. data/lib/rubocop/version.rb +1 -1
  285. data/lib/rubocop.rb +12 -0
  286. metadata +21 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adbae8e6d8a8ad828f302b9d3bba545a8b7fe54727480077a1878d4c2109dbf3
4
- data.tar.gz: fb30d554306879712c48bec3d389b4232ee8f8dde6d410dd139b73796a076d3d
3
+ metadata.gz: 67accbc10c4c2ae80033ab2a3713fce8a190d772234cbd52c5584e5c69895915
4
+ data.tar.gz: 69e7f99ee66c192619b2dc26df6d0ac73c794bb088bade8182f3eceb1cb8d8c0
5
5
  SHA512:
6
- metadata.gz: 7aa85cf4d34b4994422b5aa921d746b68bc282c97f7563affa2b2574a9b1102eefce4e10bed58801bb6ef9fb2ee2d3d563a63f5b114d754a69c872f6830a793e
7
- data.tar.gz: 1e088db8ccb3cdcf2ab7b9e624b68bfc4513681e4cc8ee6bd69084dfa91fda775fc28483a4764962829230d6d2fd5726855299ba1ae622bf85cc66f55451c8c9
6
+ metadata.gz: 21005d0d16a207a998640686ee7dcf251683899ab8e746baa861888fd26f2e58791733b48869a085b1b365ce2b67e64b216b4cfe6c1a2e26a2ecc699da0ea085
7
+ data.tar.gz: 461a588bb95269c194efee4ee8570c166ce009695664aa31181f1f0806220f451e4685d4feff8751d4135f196d3cb42ec100c171b905526e06ed968cd9bb47f9
data/README.md CHANGED
@@ -53,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
53
53
  in your `Gemfile`:
54
54
 
55
55
  ```rb
56
- gem 'rubocop', '~> 1.43', require: false
56
+ gem 'rubocop', '~> 1.50', require: false
57
57
  ```
58
58
 
59
59
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
data/config/default.yml CHANGED
@@ -153,6 +153,7 @@ AllCops:
153
153
  rubocop-sequel: [sequel]
154
154
  rubocop-rake: [rake]
155
155
  rubocop-graphql: [graphql]
156
+ rubocop-capybara: [capybara]
156
157
  # Enable/Disable checking the methods extended by Active Support.
157
158
  ActiveSupportExtensionsEnabled: false
158
159
 
@@ -262,6 +263,21 @@ Gemspec/DeprecatedAttributeAssignment:
262
263
  Include:
263
264
  - '**/*.gemspec'
264
265
 
266
+ Gemspec/DevelopmentDependencies:
267
+ Description: Checks that development dependencies are specified in Gemfile rather than gemspec.
268
+ Enabled: pending
269
+ VersionAdded: '1.44'
270
+ EnforcedStyle: Gemfile
271
+ SupportedStyles:
272
+ - Gemfile
273
+ - gems.rb
274
+ - gemspec
275
+ AllowedGems: []
276
+ Include:
277
+ - '**/*.gemspec'
278
+ - '**/Gemfile'
279
+ - '**/gems.rb'
280
+
265
281
  Gemspec/DuplicatedAssignment:
266
282
  Description: 'An attribute assignment method calls should be listed only once in a gemspec.'
267
283
  Enabled: true
@@ -391,9 +407,8 @@ Layout/AssignmentIndentation:
391
407
  Checks the indentation of the first line of the
392
408
  right-hand-side of a multi-line assignment.
393
409
  Enabled: true
394
- SafeAutoCorrect: false
395
410
  VersionAdded: '0.49'
396
- VersionChanged: '1.40'
411
+ VersionChanged: '1.45'
397
412
  # By default the indentation width from `Layout/IndentationWidth` is used,
398
413
  # but it can be overridden by setting this parameter.
399
414
  IndentationWidth: ~
@@ -964,7 +979,6 @@ Layout/IndentationWidth:
964
979
  # Number of spaces for each indentation level.
965
980
  Width: 2
966
981
  AllowedPatterns: []
967
- IgnoredPatterns: [] # deprecated
968
982
 
969
983
  Layout/InitialIndentation:
970
984
  Description: >-
@@ -992,10 +1006,8 @@ Layout/LineContinuationLeadingSpace:
992
1006
  Use trailing spaces instead of leading spaces in strings
993
1007
  broken over multiple lines (by a backslash).
994
1008
  Enabled: pending
995
- AutoCorrect: false
996
- SafeAutoCorrect: false
997
1009
  VersionAdded: '1.31'
998
- VersionChanged: '1.32'
1010
+ VersionChanged: '1.45'
999
1011
  EnforcedStyle: trailing
1000
1012
  SupportedStyles:
1001
1013
  - leading
@@ -1004,8 +1016,6 @@ Layout/LineContinuationLeadingSpace:
1004
1016
  Layout/LineContinuationSpacing:
1005
1017
  Description: 'Checks the spacing in front of backslash in line continuations.'
1006
1018
  Enabled: pending
1007
- AutoCorrect: true
1008
- SafeAutoCorrect: true
1009
1019
  VersionAdded: '1.31'
1010
1020
  EnforcedStyle: space
1011
1021
  SupportedStyles:
@@ -1047,7 +1057,6 @@ Layout/LineLength:
1047
1057
  # elements. Strings will be converted to Regexp objects. A line that matches
1048
1058
  # any regular expression listed in this option will be ignored by LineLength.
1049
1059
  AllowedPatterns: []
1050
- IgnoredPatterns: [] # deprecated
1051
1060
 
1052
1061
  Layout/MultilineArrayBraceLayout:
1053
1062
  Description: >-
@@ -1526,7 +1535,6 @@ Lint/AmbiguousBlockAssociation:
1526
1535
  VersionChanged: '1.13'
1527
1536
  AllowedMethods: []
1528
1537
  AllowedPatterns: []
1529
- IgnoredMethods: [] # deprecated
1530
1538
 
1531
1539
  Lint/AmbiguousOperator:
1532
1540
  Description: >-
@@ -1563,7 +1571,9 @@ Lint/AssignmentInCondition:
1563
1571
  Description: "Don't use assignment in conditions."
1564
1572
  StyleGuide: '#safe-assignment-in-condition'
1565
1573
  Enabled: true
1574
+ SafeAutoCorrect: false
1566
1575
  VersionAdded: '0.9'
1576
+ VersionChanged: '1.45'
1567
1577
  AllowSafeAssignment: true
1568
1578
 
1569
1579
  Lint/BigDecimalNew:
@@ -1619,8 +1629,7 @@ Lint/Debugger:
1619
1629
  Description: 'Check for debugger calls.'
1620
1630
  Enabled: true
1621
1631
  VersionAdded: '0.14'
1622
- VersionChanged: '1.10'
1623
- DebuggerReceivers: [] # deprecated
1632
+ VersionChanged: '1.46'
1624
1633
  DebuggerMethods:
1625
1634
  # Groups are available so that a specific group can be disabled in
1626
1635
  # a user's configuration, but are otherwise not significant.
@@ -1648,6 +1657,7 @@ Lint/Debugger:
1648
1657
  - Kernel.binding.remote_pry
1649
1658
  - Kernel.binding.pry_remote
1650
1659
  - Pry.rescue
1660
+ - pry
1651
1661
  Rails:
1652
1662
  - debugger
1653
1663
  - Kernel.debugger
@@ -1740,6 +1750,11 @@ Lint/DuplicateMagicComment:
1740
1750
  Enabled: pending
1741
1751
  VersionAdded: '1.37'
1742
1752
 
1753
+ Lint/DuplicateMatchPattern:
1754
+ Description: 'Do not repeat patterns in `in` keywords.'
1755
+ Enabled: pending
1756
+ VersionAdded: '1.50'
1757
+
1743
1758
  Lint/DuplicateMethods:
1744
1759
  Description: 'Check for duplicate method definitions.'
1745
1760
  Enabled: true
@@ -2037,7 +2052,6 @@ Lint/NumberConversion:
2037
2052
  SafeAutoCorrect: false
2038
2053
  AllowedMethods: []
2039
2054
  AllowedPatterns: []
2040
- IgnoredMethods: [] # deprecated
2041
2055
  IgnoredClasses:
2042
2056
  - Time
2043
2057
  - DateTime
@@ -2388,7 +2402,6 @@ Lint/UnreachableLoop:
2388
2402
  # RSpec uses `times` in its message expectations
2389
2403
  # eg. `exactly(2).times`
2390
2404
  - !ruby/regexp /(exactly|at_least|at_most)\(\d+\)\.times/
2391
- IgnoredPatterns: [] # deprecated
2392
2405
 
2393
2406
  Lint/UnusedBlockArgument:
2394
2407
  Description: 'Checks for unused block arguments.'
@@ -2498,7 +2511,6 @@ Metrics/AbcSize:
2498
2511
  # a Float.
2499
2512
  AllowedMethods: []
2500
2513
  AllowedPatterns: []
2501
- IgnoredMethods: [] # deprecated
2502
2514
  CountRepeatedAttributes: true
2503
2515
  Max: 17
2504
2516
 
@@ -2510,13 +2522,11 @@ Metrics/BlockLength:
2510
2522
  CountComments: false # count full line comments?
2511
2523
  Max: 25
2512
2524
  CountAsOne: []
2513
- ExcludedMethods: [] # deprecated, retained for backwards compatibility
2514
2525
  AllowedMethods:
2515
2526
  # By default, exclude the `#refine` method, as it tends to have larger
2516
2527
  # associated blocks.
2517
2528
  - refine
2518
2529
  AllowedPatterns: []
2519
- IgnoredMethods: [] # deprecated
2520
2530
  Exclude:
2521
2531
  - '**/*.gemspec'
2522
2532
 
@@ -2538,6 +2548,12 @@ Metrics/ClassLength:
2538
2548
  Max: 100
2539
2549
  CountAsOne: []
2540
2550
 
2551
+ Metrics/CollectionLiteralLength:
2552
+ Description: 'Checks for `Array` or `Hash` literals with many entries.'
2553
+ Enabled: pending
2554
+ VersionAdded: '1.47'
2555
+ LengthThreshold: 250
2556
+
2541
2557
  # Avoid complex methods.
2542
2558
  Metrics/CyclomaticComplexity:
2543
2559
  Description: >-
@@ -2548,7 +2564,6 @@ Metrics/CyclomaticComplexity:
2548
2564
  VersionChanged: '0.81'
2549
2565
  AllowedMethods: []
2550
2566
  AllowedPatterns: []
2551
- IgnoredMethods: [] # deprecated
2552
2567
  Max: 7
2553
2568
 
2554
2569
  Metrics/MethodLength:
@@ -2560,10 +2575,8 @@ Metrics/MethodLength:
2560
2575
  CountComments: false # count full line comments?
2561
2576
  Max: 10
2562
2577
  CountAsOne: []
2563
- ExcludedMethods: [] # deprecated, retained for backwards compatibility
2564
2578
  AllowedMethods: []
2565
2579
  AllowedPatterns: []
2566
- IgnoredMethods: [] # deprecated
2567
2580
 
2568
2581
  Metrics/ModuleLength:
2569
2582
  Description: 'Avoid modules longer than 100 lines of code.'
@@ -2593,7 +2606,6 @@ Metrics/PerceivedComplexity:
2593
2606
  VersionChanged: '0.81'
2594
2607
  AllowedMethods: []
2595
2608
  AllowedPatterns: []
2596
- IgnoredMethods: [] # deprecated
2597
2609
  Max: 8
2598
2610
 
2599
2611
  ################## Migration #############################
@@ -2764,13 +2776,13 @@ Naming/HeredocDelimiterNaming:
2764
2776
  Enabled: true
2765
2777
  VersionAdded: '0.50'
2766
2778
  ForbiddenDelimiters:
2767
- - !ruby/regexp '/(^|\s)(EO[A-Z]{1}|END)(\s|$)/'
2779
+ - !ruby/regexp '/(^|\s)(EO[A-Z]{1}|END)(\s|$)/i'
2768
2780
 
2769
2781
  Naming/InclusiveLanguage:
2770
2782
  Description: 'Recommend the use of inclusive language instead of problematic terms.'
2771
2783
  Enabled: false
2772
2784
  VersionAdded: '1.18'
2773
- VersionChanged: '1.21'
2785
+ VersionChanged: '1.49'
2774
2786
  CheckIdentifiers: true
2775
2787
  CheckConstants: true
2776
2788
  CheckVariables: true
@@ -2822,7 +2834,6 @@ Naming/MethodName:
2822
2834
  # - '\A\s*onSelectionCleared\s*'
2823
2835
  #
2824
2836
  AllowedPatterns: []
2825
- IgnoredPatterns: [] # deprecated
2826
2837
 
2827
2838
  Naming/MethodParameterName:
2828
2839
  Description: >-
@@ -2923,6 +2934,7 @@ Naming/VariableNumber:
2923
2934
  - rfc822 # Time#rfc822
2924
2935
  - rfc2822 # Time#rfc2822
2925
2936
  - rfc3339 # DateTime.rfc3339
2937
+ - x86_64 # Allowed by default as an underscore separated CPU architecture name
2926
2938
  AllowedPatterns: []
2927
2939
 
2928
2940
  #################### Security ##############################
@@ -3050,6 +3062,7 @@ Style/ArrayCoercion:
3050
3062
  Style/ArrayIntersect:
3051
3063
  Description: 'Use `array1.intersect?(array2)` instead of `(array1 & array2).any?`.'
3052
3064
  Enabled: 'pending'
3065
+ Safe: false
3053
3066
  VersionAdded: '1.40'
3054
3067
 
3055
3068
  Style/ArrayJoin:
@@ -3192,7 +3205,6 @@ Style/BlockDelimiters:
3192
3205
  - proc
3193
3206
  - it
3194
3207
  AllowedPatterns: []
3195
- IgnoredMethods: [] # deprecated
3196
3208
  # The AllowBracesOnProceduralOneLiners option is ignored unless the
3197
3209
  # EnforcedStyle is set to `semantic`. If so:
3198
3210
  #
@@ -3216,7 +3228,7 @@ Style/BlockDelimiters:
3216
3228
  # collection.each do |element| puts element end
3217
3229
  AllowBracesOnProceduralOneLiners: false
3218
3230
  # The BracesRequiredMethods overrides all other configurations except
3219
- # IgnoredMethods. It can be used to enforce that all blocks for specific
3231
+ # AllowedMethods. It can be used to enforce that all blocks for specific
3220
3232
  # methods use braces. For example, you can use this to enforce Sorbet
3221
3233
  # signatures use braces even when the rest of your codebase enforces
3222
3234
  # the `line_count_based` style.
@@ -3253,6 +3265,9 @@ Style/CaseLikeIf:
3253
3265
  Enabled: true
3254
3266
  Safe: false
3255
3267
  VersionAdded: '0.88'
3268
+ VersionChanged: '1.48'
3269
+ # `MinBranchesCount` defines the number of branches `if` needs to have to trigger this cop.
3270
+ MinBranchesCount: 3
3256
3271
 
3257
3272
  Style/CharacterLiteral:
3258
3273
  Description: 'Checks for uses of character literals.'
@@ -3265,7 +3280,7 @@ Style/ClassAndModuleChildren:
3265
3280
  StyleGuide: '#namespace-definition'
3266
3281
  # Moving from compact to nested children requires knowledge of whether the
3267
3282
  # outer parent is a module or a class. Moving from nested to compact requires
3268
- # verification that the outer parent is defined elsewhere. Rubocop does not
3283
+ # verification that the outer parent is defined elsewhere. RuboCop does not
3269
3284
  # have the knowledge to perform either operation safely and thus requires
3270
3285
  # manual oversight.
3271
3286
  SafeAutoCorrect: false
@@ -3310,7 +3325,6 @@ Style/ClassEqualityComparison:
3310
3325
  - equal?
3311
3326
  - eql?
3312
3327
  AllowedPatterns: []
3313
- IgnoredMethods: [] # deprecated
3314
3328
 
3315
3329
  Style/ClassMethods:
3316
3330
  Description: 'Use self when defining module/class methods.'
@@ -3431,6 +3445,11 @@ Style/CommentedKeyword:
3431
3445
  VersionAdded: '0.51'
3432
3446
  VersionChanged: '1.19'
3433
3447
 
3448
+ Style/ComparableClamp:
3449
+ Description: 'Enforces the use of `Comparable#clamp` instead of comparison by minimum and maximum.'
3450
+ Enabled: pending
3451
+ VersionAdded: '1.44'
3452
+
3434
3453
  Style/ConcatArrayLiterals:
3435
3454
  Description: 'Enforces the use of `Array#push(item)` instead of `Array#concat([item])` to avoid redundant array literals.'
3436
3455
  Enabled: pending
@@ -3492,6 +3511,12 @@ Style/Copyright:
3492
3511
  Notice: '^Copyright (\(c\) )?2[0-9]{3} .+'
3493
3512
  AutocorrectNotice: ''
3494
3513
 
3514
+ Style/DataInheritance:
3515
+ Description: 'Checks for inheritance from Data.define.'
3516
+ StyleGuide: '#no-extend-data-define'
3517
+ Enabled: pending
3518
+ VersionAdded: '1.49'
3519
+
3495
3520
  Style/DateTime:
3496
3521
  Description: 'Use Time over DateTime.'
3497
3522
  StyleGuide: '#date-time'
@@ -3515,6 +3540,12 @@ Style/Dir:
3515
3540
  Enabled: true
3516
3541
  VersionAdded: '0.50'
3517
3542
 
3543
+ Style/DirEmpty:
3544
+ Description: >-
3545
+ Prefer to use `Dir.empty?('path/to/dir')` when checking if a directory is empty.
3546
+ Enabled: pending
3547
+ VersionAdded: '1.48'
3548
+
3518
3549
  Style/DisableCopsWithinSourceCodeDirective:
3519
3550
  Description: >-
3520
3551
  Forbids disabling/enabling cops within source code.
@@ -3710,6 +3741,13 @@ Style/FetchEnvVar:
3710
3741
  # Environment variables to be excluded from the inspection.
3711
3742
  AllowedVars: []
3712
3743
 
3744
+ Style/FileEmpty:
3745
+ Description: >-
3746
+ Prefer to use `File.empty?('path/to/file')` when checking if a file is empty.
3747
+ Enabled: pending
3748
+ Safe: false
3749
+ VersionAdded: '1.48'
3750
+
3713
3751
  Style/FileRead:
3714
3752
  Description: 'Favor `File.(bin)read` convenience methods.'
3715
3753
  StyleGuide: '#file-read'
@@ -3780,7 +3818,6 @@ Style/FormatStringToken:
3780
3818
  VersionChanged: '1.0'
3781
3819
  AllowedMethods: []
3782
3820
  AllowedPatterns: []
3783
- IgnoredMethods: [] # deprecated
3784
3821
 
3785
3822
  Style/FrozenStringLiteralComment:
3786
3823
  Description: >-
@@ -4021,16 +4058,43 @@ Style/InverseMethods:
4021
4058
  :=~: :!~
4022
4059
  :<: :>=
4023
4060
  :>: :<=
4024
- # `ActiveSupport` defines some common inverse methods. They are listed below,
4025
- # and not enabled by default.
4026
- # :present?: :blank?,
4027
- # :include?: :exclude?
4028
4061
  # `InverseBlocks` are methods that are inverted by inverting the return
4029
4062
  # of the block that is passed to the method
4030
4063
  InverseBlocks:
4031
4064
  :select: :reject
4032
4065
  :select!: :reject!
4033
4066
 
4067
+ Style/InvertibleUnlessCondition:
4068
+ Description: 'Favor `if` with inverted condition over `unless`.'
4069
+ Enabled: false
4070
+ Safe: false
4071
+ VersionAdded: '1.44'
4072
+ VersionChanged: '1.50'
4073
+ # `InverseMethods` are methods that can be inverted in a `unless` condition.
4074
+ # The relationship of inverse methods needs to be defined in both directions.
4075
+ # Keys and values both need to be defined as symbols.
4076
+ InverseMethods:
4077
+ :!=: :==
4078
+ :>: :<=
4079
+ :<=: :>
4080
+ :<: :>=
4081
+ :>=: :<
4082
+ :!~: :=~
4083
+ :zero?: :nonzero?
4084
+ :nonzero?: :zero?
4085
+ :any?: :none?
4086
+ :none?: :any?
4087
+ :even?: :odd?
4088
+ :odd?: :even?
4089
+ # `ActiveSupport` defines some common inverse methods. They are listed below,
4090
+ # and not enabled by default.
4091
+ # :present?: :blank?
4092
+ # :blank?: :present?
4093
+ # :include?: :exclude?
4094
+ # :exclude?: :include?
4095
+ # :one?: :many?
4096
+ # :many?: :one?
4097
+
4034
4098
  Style/IpAddresses:
4035
4099
  Description: "Don't include literal IP addresses in code."
4036
4100
  Enabled: false
@@ -4130,9 +4194,7 @@ Style/MethodCallWithArgsParentheses:
4130
4194
  VersionChanged: '1.7'
4131
4195
  IgnoreMacros: true
4132
4196
  AllowedMethods: []
4133
- IgnoredMethods: [] # deprecated
4134
4197
  AllowedPatterns: []
4135
- IgnoredPatterns: [] # deprecated
4136
4198
  IncludedMacros: []
4137
4199
  AllowParenthesesInMultilineCall: false
4138
4200
  AllowParenthesesInChaining: false
@@ -4149,7 +4211,6 @@ Style/MethodCallWithoutArgsParentheses:
4149
4211
  Enabled: true
4150
4212
  AllowedMethods: []
4151
4213
  AllowedPatterns: []
4152
- IgnoredMethods: [] # deprecated
4153
4214
  VersionAdded: '0.47'
4154
4215
  VersionChanged: '0.55'
4155
4216
 
@@ -4514,11 +4575,10 @@ Style/NumericPredicate:
4514
4575
  Checks for the use of predicate- or comparison methods for
4515
4576
  numeric comparisons.
4516
4577
  StyleGuide: '#predicate-methods'
4517
- Safe: false
4518
4578
  # This will change to a new method call which isn't guaranteed to be on the
4519
4579
  # object. Switching these methods has to be done with knowledge of the types
4520
4580
  # of the variables which rubocop doesn't have.
4521
- SafeAutoCorrect: false
4581
+ Safe: false
4522
4582
  Enabled: true
4523
4583
  VersionAdded: '0.42'
4524
4584
  VersionChanged: '0.59'
@@ -4528,7 +4588,6 @@ Style/NumericPredicate:
4528
4588
  - comparison
4529
4589
  AllowedMethods: []
4530
4590
  AllowedPatterns: []
4531
- IgnoredMethods: [] # deprecated
4532
4591
  # Exclude RSpec specs because assertions like `expect(1).to be > 0` cause
4533
4592
  # false positives.
4534
4593
  Exclude:
@@ -4808,6 +4867,11 @@ Style/RedundantFreeze:
4808
4867
  VersionAdded: '0.34'
4809
4868
  VersionChanged: '0.66'
4810
4869
 
4870
+ Style/RedundantHeredocDelimiterQuotes:
4871
+ Description: 'Checks for redundant heredoc delimiter quotes.'
4872
+ Enabled: pending
4873
+ VersionAdded: '1.45'
4874
+
4811
4875
  Style/RedundantInitialize:
4812
4876
  Description: 'Checks for redundant `initialize` methods.'
4813
4877
  Enabled: pending
@@ -4823,6 +4887,11 @@ Style/RedundantInterpolation:
4823
4887
  VersionAdded: '0.76'
4824
4888
  VersionChanged: '1.30'
4825
4889
 
4890
+ Style/RedundantLineContinuation:
4891
+ Description: 'Check for redundant line continuation.'
4892
+ Enabled: pending
4893
+ VersionAdded: '1.49'
4894
+
4826
4895
  Style/RedundantParentheses:
4827
4896
  Description: "Checks for parentheses that seem not to serve any purpose."
4828
4897
  Enabled: true
@@ -5205,7 +5274,6 @@ Style/SymbolProc:
5205
5274
  AllowedMethods:
5206
5275
  - define_method
5207
5276
  AllowedPatterns: []
5208
- IgnoredMethods: [] # deprecated
5209
5277
  AllowComments: false
5210
5278
 
5211
5279
  Style/TernaryParentheses:
@@ -16,6 +16,7 @@ module RuboCop
16
16
 
17
17
  PHASE_1_OVERRIDDEN = '(skipped because the default Layout/LineLength:Max is overridden)'
18
18
  PHASE_1_DISABLED = '(skipped because Layout/LineLength is disabled)'
19
+ PHASE_1_SKIPPED = '(skipped because a list of cops is passed to the `--only` flag)'
19
20
 
20
21
  def run
21
22
  add_formatter
@@ -31,6 +32,8 @@ module RuboCop
31
32
  skip_line_length_cop(PHASE_1_DISABLED)
32
33
  elsif !same_max_line_length?(@config_store.for_pwd, ConfigLoader.default_configuration)
33
34
  skip_line_length_cop(PHASE_1_OVERRIDDEN)
35
+ elsif options_has_only_flag?
36
+ skip_line_length_cop(PHASE_1_SKIPPED)
34
37
  else
35
38
  run_line_length_cop
36
39
  end
@@ -57,6 +60,10 @@ module RuboCop
57
60
  config.for_cop('Layout/LineLength')
58
61
  end
59
62
 
63
+ def options_has_only_flag?
64
+ @options[:only]
65
+ end
66
+
60
67
  # Do an initial run with only Layout/LineLength so that cops that
61
68
  # depend on Layout/LineLength:Max get the correct value for that
62
69
  # parameter.
@@ -76,13 +76,18 @@ module RuboCop
76
76
  warn <<~WARNING
77
77
  Errors are usually caused by RuboCop bugs.
78
78
  Please, report your problems to RuboCop's issue tracker.
79
- #{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}
80
-
79
+ #{bug_tracker_uri}
81
80
  Mention the following information in the issue report:
82
81
  #{RuboCop::Version.version(debug: true)}
83
82
  WARNING
84
83
  end
85
84
 
85
+ def bug_tracker_uri
86
+ return unless Gem.loaded_specs.key?('rubocop')
87
+
88
+ "#{Gem.loaded_specs['rubocop'].metadata['bug_tracker_uri']}\n"
89
+ end
90
+
86
91
  def maybe_print_corrected_source
87
92
  # Integration tools (like RubyMine) expect to have only the JSON result
88
93
  # when specifying JSON format. Similar HTML and JUnit are targeted as well.
data/lib/rubocop/cli.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
4
+
3
5
  module RuboCop
4
6
  # The CLI is a class responsible of handling all the command line interface
5
7
  # logic.
@@ -38,14 +40,16 @@ module RuboCop
38
40
  @options, paths = Options.new.parse(args)
39
41
  @env = Environment.new(@options, @config_store, paths)
40
42
 
41
- if @options[:init]
42
- run_command(:init)
43
- else
44
- act_on_options
45
- validate_options_vs_config
46
- parallel_by_default!
47
- apply_default_formatter
48
- execute_runners
43
+ profile_if_needed do
44
+ if @options[:init]
45
+ run_command(:init)
46
+ else
47
+ act_on_options
48
+ validate_options_vs_config
49
+ parallel_by_default!
50
+ apply_default_formatter
51
+ execute_runners
52
+ end
49
53
  end
50
54
  rescue ConfigNotFoundError, IncorrectCopNameError, OptionArgumentError => e
51
55
  warn e.message
@@ -68,6 +72,48 @@ module RuboCop
68
72
 
69
73
  private
70
74
 
75
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
76
+ def profile_if_needed
77
+ return yield unless @options[:profile]
78
+
79
+ return STATUS_ERROR unless require_gem('stackprof')
80
+
81
+ with_memory = @options[:memory]
82
+ if with_memory
83
+ return STATUS_ERROR unless require_gem('memory_profiler')
84
+
85
+ MemoryProfiler.start
86
+ end
87
+
88
+ tmp_dir = File.join(ConfigFinder.project_root, 'tmp')
89
+ FileUtils.mkdir_p(tmp_dir)
90
+ cpu_profile_file = File.join(tmp_dir, 'rubocop-stackprof.dump')
91
+ status = nil
92
+
93
+ StackProf.run(out: cpu_profile_file) do
94
+ status = yield
95
+ end
96
+ puts "Profile report generated at #{cpu_profile_file}"
97
+
98
+ if with_memory
99
+ puts 'Building memory report...'
100
+ report = MemoryProfiler.stop
101
+ memory_profile_file = File.join(tmp_dir, 'rubocop-memory_profiler.txt')
102
+ report.pretty_print(to_file: memory_profile_file, scale_bytes: true)
103
+ puts "Memory report generated at #{memory_profile_file}"
104
+ end
105
+ status
106
+ end
107
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
108
+
109
+ def require_gem(name)
110
+ require name
111
+ true
112
+ rescue LoadError
113
+ warn("You don't have #{name} installed. Add it to your Gemfile and run `bundle install`")
114
+ false
115
+ end
116
+
71
117
  def run_command(name)
72
118
  @env.run(name)
73
119
  end
@@ -11,6 +11,8 @@ module RuboCop
11
11
  # This class provides an API compatible with RuboCop::DirectiveComment
12
12
  # to be used for cops that are disabled in the config file
13
13
  class ConfigDisabledCopDirectiveComment
14
+ include RuboCop::Ext::Comment
15
+
14
16
  attr_reader :text, :loc, :line_number
15
17
 
16
18
  Loc = Struct.new(:expression)
@@ -42,6 +44,10 @@ module RuboCop
42
44
  disabled_line_ranges.none? { |range| range.include?(line_number) }
43
45
  end
44
46
 
47
+ def cop_opted_in?(cop)
48
+ opt_in_cops.include?(cop.cop_name)
49
+ end
50
+
45
51
  def cop_disabled_line_ranges
46
52
  @cop_disabled_line_ranges ||= analyze
47
53
  end
@@ -74,6 +80,19 @@ module RuboCop
74
80
  extras
75
81
  end
76
82
 
83
+ def opt_in_cops
84
+ @opt_in_cops ||= begin
85
+ cops = Set.new
86
+ each_directive do |directive|
87
+ next unless directive.enabled?
88
+ next if directive.all_cops?
89
+
90
+ cops.merge(directive.cop_names)
91
+ end
92
+ cops
93
+ end
94
+ end
95
+
77
96
  def analyze # rubocop:todo Metrics/AbcSize
78
97
  return {} if @no_directives
79
98
 
@@ -29,7 +29,7 @@ module RuboCop
29
29
  end
30
30
 
31
31
  # rubocop:disable Metrics/AbcSize
32
- def initialize(hash = {}, loaded_path = nil)
32
+ def initialize(hash = RuboCop::ConfigLoader.default_configuration, loaded_path = nil)
33
33
  @loaded_path = loaded_path
34
34
  @for_cop = Hash.new do |h, cop|
35
35
  cop_name = cop.respond_to?(:cop_name) ? cop.cop_name : cop
@@ -304,8 +304,8 @@ module RuboCop
304
304
  end
305
305
 
306
306
  def enable_cop?(qualified_cop_name, cop_options)
307
- # If the cop is explicitly enabled, the other checks can be skipped.
308
- return true if cop_options['Enabled'] == true
307
+ # If the cop is explicitly enabled or `Lint/Syntax`, the other checks can be skipped.
308
+ return true if cop_options['Enabled'] == true || qualified_cop_name == 'Lint/Syntax'
309
309
 
310
310
  department = department_of(qualified_cop_name)
311
311
  cop_enabled = cop_options.fetch('Enabled') { !for_all_cops['DisabledByDefault'] }