rubocop 1.45.1 → 1.50.1

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 (223) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +46 -15
  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 +6 -6
  7. data/lib/rubocop/comment_config.rb +19 -0
  8. data/lib/rubocop/config.rb +3 -3
  9. data/lib/rubocop/config_loader.rb +8 -8
  10. data/lib/rubocop/cop/autocorrect_logic.rb +29 -13
  11. data/lib/rubocop/cop/base.rb +1 -1
  12. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -1
  13. data/lib/rubocop/cop/cop.rb +2 -2
  14. data/lib/rubocop/cop/corrector.rb +1 -1
  15. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
  16. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +3 -3
  17. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +3 -3
  18. data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
  19. data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +2 -2
  20. data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +1 -1
  21. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +1 -1
  22. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +2 -2
  23. data/lib/rubocop/cop/gemspec/dependency_version.rb +1 -1
  24. data/lib/rubocop/cop/internal_affairs/cop_description.rb +5 -5
  25. data/lib/rubocop/cop/internal_affairs/example_heredoc_delimiter.rb +3 -3
  26. data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +1 -1
  27. data/lib/rubocop/cop/internal_affairs/location_expression.rb +37 -0
  28. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  29. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -1
  30. data/lib/rubocop/cop/internal_affairs/processed_source_buffer_name.rb +42 -0
  31. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
  32. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
  33. data/lib/rubocop/cop/internal_affairs/redundant_source_range.rb +66 -0
  34. data/lib/rubocop/cop/internal_affairs.rb +3 -0
  35. data/lib/rubocop/cop/layout/block_end_newline.rb +7 -21
  36. data/lib/rubocop/cop/layout/class_structure.rb +6 -3
  37. data/lib/rubocop/cop/layout/closing_heredoc_indentation.rb +1 -1
  38. data/lib/rubocop/cop/layout/empty_comment.rb +3 -3
  39. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +1 -1
  40. data/lib/rubocop/cop/layout/empty_lines.rb +1 -1
  41. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +2 -0
  42. data/lib/rubocop/cop/layout/end_alignment.rb +9 -1
  43. data/lib/rubocop/cop/layout/extra_spacing.rb +6 -1
  44. data/lib/rubocop/cop/layout/first_argument_indentation.rb +7 -2
  45. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +8 -2
  46. data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
  47. data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
  48. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  49. data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +1 -3
  50. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +11 -7
  51. data/lib/rubocop/cop/layout/redundant_line_break.rb +6 -7
  52. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -2
  53. data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
  54. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +2 -2
  55. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +1 -1
  56. data/lib/rubocop/cop/layout/space_inside_parens.rb +2 -2
  57. data/lib/rubocop/cop/layout/space_inside_percent_literal_delimiters.rb +1 -1
  58. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  59. data/lib/rubocop/cop/lint/constant_resolution.rb +1 -1
  60. data/lib/rubocop/cop/lint/debugger.rb +3 -0
  61. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
  62. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +1 -1
  63. data/lib/rubocop/cop/lint/duplicate_match_pattern.rb +122 -0
  64. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -2
  65. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +1 -3
  66. data/lib/rubocop/cop/lint/else_layout.rb +1 -1
  67. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  68. data/lib/rubocop/cop/lint/empty_conditional_body.rb +4 -2
  69. data/lib/rubocop/cop/lint/empty_interpolation.rb +1 -1
  70. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -1
  71. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +46 -4
  72. data/lib/rubocop/cop/lint/missing_super.rb +31 -2
  73. data/lib/rubocop/cop/lint/nested_method_definition.rb +3 -11
  74. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +2 -0
  75. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +6 -10
  76. data/lib/rubocop/cop/lint/percent_string_array.rb +1 -1
  77. data/lib/rubocop/cop/lint/percent_symbol_array.rb +1 -1
  78. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +11 -5
  79. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +5 -5
  80. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -1
  81. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  82. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +35 -15
  83. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -1
  84. data/lib/rubocop/cop/lint/redundant_with_object.rb +1 -1
  85. data/lib/rubocop/cop/lint/refinement_import_methods.rb +2 -1
  86. data/lib/rubocop/cop/lint/rescue_type.rb +3 -3
  87. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +1 -1
  88. data/lib/rubocop/cop/lint/script_permission.rb +1 -1
  89. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -1
  90. data/lib/rubocop/cop/lint/syntax.rb +4 -0
  91. data/lib/rubocop/cop/lint/to_enum_arguments.rb +13 -3
  92. data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -3
  93. data/lib/rubocop/cop/lint/useless_access_modifier.rb +10 -10
  94. data/lib/rubocop/cop/lint/useless_method_definition.rb +10 -2
  95. data/lib/rubocop/cop/lint/useless_rescue.rb +6 -2
  96. data/lib/rubocop/cop/lint/useless_times.rb +1 -1
  97. data/lib/rubocop/cop/lint/void.rb +7 -3
  98. data/lib/rubocop/cop/metrics/block_nesting.rb +1 -1
  99. data/lib/rubocop/cop/metrics/class_length.rb +1 -0
  100. data/lib/rubocop/cop/metrics/collection_literal_length.rb +76 -0
  101. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +3 -3
  102. data/lib/rubocop/cop/migration/department_name.rb +1 -1
  103. data/lib/rubocop/cop/mixin/annotation_comment.rb +1 -1
  104. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  105. data/lib/rubocop/cop/mixin/comments_help.rb +3 -3
  106. data/lib/rubocop/cop/mixin/documentation_comment.rb +1 -1
  107. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +1 -1
  108. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +10 -5
  109. data/lib/rubocop/cop/mixin/hash_transform_method.rb +3 -3
  110. data/lib/rubocop/cop/mixin/min_branches_count.rb +40 -0
  111. data/lib/rubocop/cop/mixin/multiline_element_line_breaks.rb +0 -3
  112. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +1 -1
  113. data/lib/rubocop/cop/mixin/range_help.rb +1 -6
  114. data/lib/rubocop/cop/mixin/statement_modifier.rb +3 -3
  115. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  116. data/lib/rubocop/cop/naming/ascii_identifiers.rb +1 -1
  117. data/lib/rubocop/cop/naming/heredoc_delimiter_case.rb +1 -1
  118. data/lib/rubocop/cop/naming/inclusive_language.rb +23 -4
  119. data/lib/rubocop/cop/naming/method_name.rb +3 -3
  120. data/lib/rubocop/cop/naming/predicate_name.rb +1 -1
  121. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  122. data/lib/rubocop/cop/registry.rb +3 -1
  123. data/lib/rubocop/cop/style/accessor_grouping.rb +39 -17
  124. data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -3
  125. data/lib/rubocop/cop/style/array_intersect.rb +1 -1
  126. data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
  127. data/lib/rubocop/cop/style/bisected_attr_accessor.rb +1 -1
  128. data/lib/rubocop/cop/style/block_comments.rb +1 -1
  129. data/lib/rubocop/cop/style/block_delimiters.rb +11 -2
  130. data/lib/rubocop/cop/style/case_like_if.rb +20 -3
  131. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  132. data/lib/rubocop/cop/style/class_equality_comparison.rb +42 -9
  133. data/lib/rubocop/cop/style/collection_compact.rb +1 -1
  134. data/lib/rubocop/cop/style/comment_annotation.rb +1 -1
  135. data/lib/rubocop/cop/style/commented_keyword.rb +2 -2
  136. data/lib/rubocop/cop/style/concat_array_literals.rb +10 -2
  137. data/lib/rubocop/cop/style/conditional_assignment.rb +6 -6
  138. data/lib/rubocop/cop/style/copyright.rb +1 -1
  139. data/lib/rubocop/cop/style/data_inheritance.rb +75 -0
  140. data/lib/rubocop/cop/style/dir_empty.rb +60 -0
  141. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +2 -2
  142. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +2 -2
  143. data/lib/rubocop/cop/style/documentation.rb +10 -4
  144. data/lib/rubocop/cop/style/documentation_method.rb +4 -4
  145. data/lib/rubocop/cop/style/double_negation.rb +2 -2
  146. data/lib/rubocop/cop/style/each_with_object.rb +1 -1
  147. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  148. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  149. data/lib/rubocop/cop/style/eval_with_location.rb +4 -4
  150. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  151. data/lib/rubocop/cop/style/file_empty.rb +71 -0
  152. data/lib/rubocop/cop/style/file_read.rb +1 -1
  153. data/lib/rubocop/cop/style/file_write.rb +1 -1
  154. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  155. data/lib/rubocop/cop/style/guard_clause.rb +1 -1
  156. data/lib/rubocop/cop/style/hash_except.rb +4 -4
  157. data/lib/rubocop/cop/style/hash_like_case.rb +3 -9
  158. data/lib/rubocop/cop/style/hash_syntax.rb +5 -2
  159. data/lib/rubocop/cop/style/if_unless_modifier.rb +108 -15
  160. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +2 -0
  161. data/lib/rubocop/cop/style/inverse_methods.rb +5 -5
  162. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +2 -2
  163. data/lib/rubocop/cop/style/map_to_hash.rb +4 -1
  164. data/lib/rubocop/cop/style/map_to_set.rb +4 -1
  165. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +3 -7
  166. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +44 -37
  167. data/lib/rubocop/cop/style/min_max.rb +3 -3
  168. data/lib/rubocop/cop/style/mixin_grouping.rb +4 -4
  169. data/lib/rubocop/cop/style/multiline_method_signature.rb +7 -4
  170. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
  171. data/lib/rubocop/cop/style/negated_if_else_condition.rb +12 -7
  172. data/lib/rubocop/cop/style/nil_lambda.rb +2 -2
  173. data/lib/rubocop/cop/style/parallel_assignment.rb +26 -18
  174. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +2 -3
  175. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  176. data/lib/rubocop/cop/style/redundant_condition.rb +2 -2
  177. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +2 -2
  178. data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
  179. data/lib/rubocop/cop/style/redundant_line_continuation.rb +179 -0
  180. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -2
  181. data/lib/rubocop/cop/style/redundant_percent_q.rb +1 -1
  182. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +7 -8
  183. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +11 -4
  184. data/lib/rubocop/cop/style/redundant_sort.rb +3 -3
  185. data/lib/rubocop/cop/style/redundant_string_escape.rb +3 -4
  186. data/lib/rubocop/cop/style/require_order.rb +1 -3
  187. data/lib/rubocop/cop/style/rescue_standard_error.rb +2 -2
  188. data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
  189. data/lib/rubocop/cop/style/slicing_with_range.rb +1 -1
  190. data/lib/rubocop/cop/style/sole_nested_conditional.rb +3 -3
  191. data/lib/rubocop/cop/style/stderr_puts.rb +1 -1
  192. data/lib/rubocop/cop/style/struct_inheritance.rb +1 -1
  193. data/lib/rubocop/cop/style/trailing_body_on_class.rb +1 -0
  194. data/lib/rubocop/cop/style/trailing_underscore_variable.rb +1 -1
  195. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  196. data/lib/rubocop/cop/style/unless_logical_operators.rb +1 -0
  197. data/lib/rubocop/cop/style/unpack_first.rb +3 -3
  198. data/lib/rubocop/cop/style/word_array.rb +17 -5
  199. data/lib/rubocop/cop/style/yoda_condition.rb +1 -1
  200. data/lib/rubocop/cop/style/zero_length_predicate.rb +9 -5
  201. data/lib/rubocop/cop/team.rb +11 -8
  202. data/lib/rubocop/cop/util.rb +13 -4
  203. data/lib/rubocop/cop/variable_force/variable.rb +5 -3
  204. data/lib/rubocop/cops_documentation_generator.rb +10 -3
  205. data/lib/rubocop/directive_comment.rb +3 -3
  206. data/lib/rubocop/ext/comment.rb +18 -0
  207. data/lib/rubocop/ext/regexp_node.rb +1 -1
  208. data/lib/rubocop/ext/regexp_parser.rb +1 -1
  209. data/lib/rubocop/formatter/junit_formatter.rb +4 -1
  210. data/lib/rubocop/formatter/simple_text_formatter.rb +1 -1
  211. data/lib/rubocop/options.rb +4 -1
  212. data/lib/rubocop/result_cache.rb +1 -1
  213. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  214. data/lib/rubocop/rspec/shared_contexts.rb +4 -0
  215. data/lib/rubocop/rspec/support.rb +1 -0
  216. data/lib/rubocop/server/cache.rb +1 -1
  217. data/lib/rubocop/server/core.rb +1 -1
  218. data/lib/rubocop/server/helper.rb +1 -1
  219. data/lib/rubocop/server/server_command/exec.rb +1 -1
  220. data/lib/rubocop/target_ruby.rb +1 -1
  221. data/lib/rubocop/version.rb +1 -1
  222. data/lib/rubocop.rb +8 -0
  223. metadata +20 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 648a8aa3156aebf0c078bc0b600f301d3aa0abaf92d6b3643c343718575f7302
4
- data.tar.gz: 21b185886d70b70a163c6e7f3ea47e04ee0a0afcf11217e0d7bcb31e25440880
3
+ metadata.gz: cc74785ce6643999994c7595e6ab7b6508abc7ab33532032d09fb854808d3ab5
4
+ data.tar.gz: 3313880579d587260cae9f718b148160a597da1a239464c9ae86ce8a773065fc
5
5
  SHA512:
6
- metadata.gz: ff5a5e947001ba9507f3e806896559baaf0e4bccc6b2cc56316dffc3ae334f62046040be389518139d2979c4d09900600f9b233bc1f4dbd2d1d37a2f8fe99037
7
- data.tar.gz: 8f89f55198c9d206c5b8d0c32cbeb5033491046c0ea0f4311f6c1a23595bcce852ec732606ca1fd2bc499b31ecb2265dcf6d85edd352f6400d01bd9385993a44
6
+ metadata.gz: 0b4ea0d9447499f45e99d333c05f72edd634980d506717117cb35029ac2f185de08681c68ce40a2d319efe163b23a168e6c9a55f8178dbf25f847ecc7710cb04
7
+ data.tar.gz: e1c57df60ec75958f78eec411b0697496ea34b0a10626b3fa79453a64328162292cb621319557b0aac59fe88d447fa32a5e3fbcf1d4d4efcf9ef9388191a6fee
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.45', 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
 
@@ -1015,8 +1016,6 @@ Layout/LineContinuationLeadingSpace:
1015
1016
  Layout/LineContinuationSpacing:
1016
1017
  Description: 'Checks the spacing in front of backslash in line continuations.'
1017
1018
  Enabled: pending
1018
- AutoCorrect: true
1019
- SafeAutoCorrect: true
1020
1019
  VersionAdded: '1.31'
1021
1020
  EnforcedStyle: space
1022
1021
  SupportedStyles:
@@ -1630,13 +1629,12 @@ Lint/Debugger:
1630
1629
  Description: 'Check for debugger calls.'
1631
1630
  Enabled: true
1632
1631
  VersionAdded: '0.14'
1633
- VersionChanged: '1.10'
1632
+ VersionChanged: '1.46'
1634
1633
  DebuggerMethods:
1635
1634
  # Groups are available so that a specific group can be disabled in
1636
1635
  # a user's configuration, but are otherwise not significant.
1637
1636
  Kernel:
1638
1637
  - binding.irb
1639
- - p
1640
1638
  - Kernel.binding.irb
1641
1639
  Byebug:
1642
1640
  - byebug
@@ -1646,9 +1644,6 @@ Lint/Debugger:
1646
1644
  Capybara:
1647
1645
  - save_and_open_page
1648
1646
  - save_and_open_screenshot
1649
- PP:
1650
- - PP.pp
1651
- - pp
1652
1647
  debug.rb:
1653
1648
  - binding.b
1654
1649
  - binding.break
@@ -1662,6 +1657,7 @@ Lint/Debugger:
1662
1657
  - Kernel.binding.remote_pry
1663
1658
  - Kernel.binding.pry_remote
1664
1659
  - Pry.rescue
1660
+ - pry
1665
1661
  Rails:
1666
1662
  - debugger
1667
1663
  - Kernel.debugger
@@ -1754,6 +1750,11 @@ Lint/DuplicateMagicComment:
1754
1750
  Enabled: pending
1755
1751
  VersionAdded: '1.37'
1756
1752
 
1753
+ Lint/DuplicateMatchPattern:
1754
+ Description: 'Do not repeat patterns in `in` keywords.'
1755
+ Enabled: pending
1756
+ VersionAdded: '1.50'
1757
+
1757
1758
  Lint/DuplicateMethods:
1758
1759
  Description: 'Check for duplicate method definitions.'
1759
1760
  Enabled: true
@@ -2547,6 +2548,12 @@ Metrics/ClassLength:
2547
2548
  Max: 100
2548
2549
  CountAsOne: []
2549
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
+
2550
2557
  # Avoid complex methods.
2551
2558
  Metrics/CyclomaticComplexity:
2552
2559
  Description: >-
@@ -2775,7 +2782,7 @@ Naming/InclusiveLanguage:
2775
2782
  Description: 'Recommend the use of inclusive language instead of problematic terms.'
2776
2783
  Enabled: false
2777
2784
  VersionAdded: '1.18'
2778
- VersionChanged: '1.21'
2785
+ VersionChanged: '1.49'
2779
2786
  CheckIdentifiers: true
2780
2787
  CheckConstants: true
2781
2788
  CheckVariables: true
@@ -2927,6 +2934,7 @@ Naming/VariableNumber:
2927
2934
  - rfc822 # Time#rfc822
2928
2935
  - rfc2822 # Time#rfc2822
2929
2936
  - rfc3339 # DateTime.rfc3339
2937
+ - x86_64 # Allowed by default as an underscore separated CPU architecture name
2930
2938
  AllowedPatterns: []
2931
2939
 
2932
2940
  #################### Security ##############################
@@ -3054,6 +3062,7 @@ Style/ArrayCoercion:
3054
3062
  Style/ArrayIntersect:
3055
3063
  Description: 'Use `array1.intersect?(array2)` instead of `(array1 & array2).any?`.'
3056
3064
  Enabled: 'pending'
3065
+ Safe: false
3057
3066
  VersionAdded: '1.40'
3058
3067
 
3059
3068
  Style/ArrayJoin:
@@ -3256,6 +3265,9 @@ Style/CaseLikeIf:
3256
3265
  Enabled: true
3257
3266
  Safe: false
3258
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
3259
3271
 
3260
3272
  Style/CharacterLiteral:
3261
3273
  Description: 'Checks for uses of character literals.'
@@ -3268,7 +3280,7 @@ Style/ClassAndModuleChildren:
3268
3280
  StyleGuide: '#namespace-definition'
3269
3281
  # Moving from compact to nested children requires knowledge of whether the
3270
3282
  # outer parent is a module or a class. Moving from nested to compact requires
3271
- # verification that the outer parent is defined elsewhere. Rubocop does not
3283
+ # verification that the outer parent is defined elsewhere. RuboCop does not
3272
3284
  # have the knowledge to perform either operation safely and thus requires
3273
3285
  # manual oversight.
3274
3286
  SafeAutoCorrect: false
@@ -3499,6 +3511,12 @@ Style/Copyright:
3499
3511
  Notice: '^Copyright (\(c\) )?2[0-9]{3} .+'
3500
3512
  AutocorrectNotice: ''
3501
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
+
3502
3520
  Style/DateTime:
3503
3521
  Description: 'Use Time over DateTime.'
3504
3522
  StyleGuide: '#date-time'
@@ -3522,6 +3540,12 @@ Style/Dir:
3522
3540
  Enabled: true
3523
3541
  VersionAdded: '0.50'
3524
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
+
3525
3549
  Style/DisableCopsWithinSourceCodeDirective:
3526
3550
  Description: >-
3527
3551
  Forbids disabling/enabling cops within source code.
@@ -3717,6 +3741,13 @@ Style/FetchEnvVar:
3717
3741
  # Environment variables to be excluded from the inspection.
3718
3742
  AllowedVars: []
3719
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
+
3720
3751
  Style/FileRead:
3721
3752
  Description: 'Favor `File.(bin)read` convenience methods.'
3722
3753
  StyleGuide: '#file-read'
@@ -4027,10 +4058,6 @@ Style/InverseMethods:
4027
4058
  :=~: :!~
4028
4059
  :<: :>=
4029
4060
  :>: :<=
4030
- # `ActiveSupport` defines some common inverse methods. They are listed below,
4031
- # and not enabled by default.
4032
- # :present?: :blank?,
4033
- # :include?: :exclude?
4034
4061
  # `InverseBlocks` are methods that are inverted by inverting the return
4035
4062
  # of the block that is passed to the method
4036
4063
  InverseBlocks:
@@ -4546,11 +4573,10 @@ Style/NumericPredicate:
4546
4573
  Checks for the use of predicate- or comparison methods for
4547
4574
  numeric comparisons.
4548
4575
  StyleGuide: '#predicate-methods'
4549
- Safe: false
4550
4576
  # This will change to a new method call which isn't guaranteed to be on the
4551
4577
  # object. Switching these methods has to be done with knowledge of the types
4552
4578
  # of the variables which rubocop doesn't have.
4553
- SafeAutoCorrect: false
4579
+ Safe: false
4554
4580
  Enabled: true
4555
4581
  VersionAdded: '0.42'
4556
4582
  VersionChanged: '0.59'
@@ -4859,6 +4885,11 @@ Style/RedundantInterpolation:
4859
4885
  VersionAdded: '0.76'
4860
4886
  VersionChanged: '1.30'
4861
4887
 
4888
+ Style/RedundantLineContinuation:
4889
+ Description: 'Check for redundant line continuation.'
4890
+ Enabled: pending
4891
+ VersionAdded: '1.49'
4892
+
4862
4893
  Style/RedundantParentheses:
4863
4894
  Description: "Checks for parentheses that seem not to serve any purpose."
4864
4895
  Enabled: true
@@ -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
@@ -87,20 +87,20 @@ module RuboCop
87
87
 
88
88
  tmp_dir = File.join(ConfigFinder.project_root, 'tmp')
89
89
  FileUtils.mkdir_p(tmp_dir)
90
+ cpu_profile_file = File.join(tmp_dir, 'rubocop-stackprof.dump')
90
91
  status = nil
91
92
 
92
- StackProf.run(out: File.join(tmp_dir, 'rubocop-stackprof.dump')) do
93
+ StackProf.run(out: cpu_profile_file) do
93
94
  status = yield
94
95
  end
95
- puts 'Profile report generated'
96
+ puts "Profile report generated at #{cpu_profile_file}"
96
97
 
97
98
  if with_memory
98
99
  puts 'Building memory report...'
99
100
  report = MemoryProfiler.stop
100
- report.pretty_print(
101
- to_file: File.join(tmp_dir, 'rubocop-memory_profiler.txt'),
102
- scale_bytes: true
103
- )
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
104
  end
105
105
  status
106
106
  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'] }
@@ -23,6 +23,14 @@ module RuboCop
23
23
  class << self
24
24
  include FileFinder
25
25
 
26
+ PENDING_BANNER = <<~BANNER
27
+ The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
28
+
29
+ Please also note that you can opt-in to new cops by default by adding this to your config:
30
+ AllCops:
31
+ NewCops: enable
32
+ BANNER
33
+
26
34
  attr_accessor :debug, :ignore_parent_exclusion, :disable_pending_cops, :enable_pending_cops,
27
35
  :ignore_unrecognized_cops
28
36
  attr_writer :default_configuration
@@ -165,14 +173,6 @@ module RuboCop
165
173
  ConfigFinder.project_root
166
174
  end
167
175
 
168
- PENDING_BANNER = <<~BANNER
169
- The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
170
-
171
- Please also note that you can opt-in to new cops by default by adding this to your config:
172
- AllCops:
173
- NewCops: enable
174
- BANNER
175
-
176
176
  def warn_on_pending_cops(pending_cops)
177
177
  warn Rainbow(PENDING_BANNER).yellow
178
178
 
@@ -35,7 +35,7 @@ module RuboCop
35
35
  return false if cop_config['AutoCorrect'] == false
36
36
 
37
37
  # :safe_autocorrect is a derived option based on several command-line
38
- # arguments - see Rubocop::Options#add_autocorrection_options
38
+ # arguments - see RuboCop::Options#add_autocorrection_options
39
39
  return safe_autocorrect? if @options.fetch(:safe_autocorrect, false)
40
40
 
41
41
  true
@@ -43,18 +43,24 @@ module RuboCop
43
43
 
44
44
  private
45
45
 
46
- def disable_offense(range)
47
- heredoc_range = surrounding_heredoc(range)
48
- if heredoc_range
49
- disable_offense_before_and_after(range_by_lines(heredoc_range))
46
+ def disable_offense(offense_range)
47
+ range = surrounding_heredoc(offense_range) || surrounding_percent_array(offense_range)
48
+
49
+ if range
50
+ disable_offense_before_and_after(range_by_lines(range))
51
+ else
52
+ disable_offense_with_eol_or_surround_comment(offense_range)
53
+ end
54
+ end
55
+
56
+ def disable_offense_with_eol_or_surround_comment(range)
57
+ eol_comment = " # rubocop:todo #{cop_name}"
58
+ needed_line_length = (range.source_line + eol_comment).length
59
+
60
+ if needed_line_length <= max_line_length
61
+ disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
50
62
  else
51
- eol_comment = " # rubocop:todo #{cop_name}"
52
- needed_line_length = (range.source_line + eol_comment).length
53
- if needed_line_length <= max_line_length
54
- disable_offense_at_end_of_line(range_of_first_line(range), eol_comment)
55
- else
56
- disable_offense_before_and_after(range_by_lines(range))
57
- end
63
+ disable_offense_before_and_after(range_by_lines(range))
58
64
  end
59
65
  end
60
66
 
@@ -65,10 +71,20 @@ module RuboCop
65
71
  heredoc_nodes = processed_source.ast.each_descendant.select do |node|
66
72
  node.respond_to?(:heredoc?) && node.heredoc?
67
73
  end
68
- heredoc_nodes.map { |node| node.loc.expression.join(node.loc.heredoc_end) }
74
+ heredoc_nodes.map { |node| node.source_range.join(node.loc.heredoc_end) }
69
75
  .find { |range| range.contains?(offense_range) }
70
76
  end
71
77
 
78
+ def surrounding_percent_array(offense_range)
79
+ return nil if offense_range.empty?
80
+
81
+ percent_array = processed_source.ast.each_descendant.select do |node|
82
+ node.array_type? && node.percent_literal?
83
+ end
84
+
85
+ percent_array.map(&:source_range).find { |range| range.overlaps?(offense_range) }
86
+ end
87
+
72
88
  def range_of_first_line(range)
73
89
  begin_of_first_line = range.begin_pos - range.column
74
90
  end_of_first_line = begin_of_first_line + range.source_line.length
@@ -416,7 +416,7 @@ module RuboCop
416
416
 
417
417
  def range_from_node_or_range(node_or_range)
418
418
  if node_or_range.respond_to?(:loc)
419
- node_or_range.loc.expression
419
+ node_or_range.source_range
420
420
  elsif node_or_range.is_a?(::Parser::Source::Range)
421
421
  node_or_range
422
422
  else
@@ -124,7 +124,7 @@ module RuboCop
124
124
  end
125
125
 
126
126
  def preceding_comment?(node1, node2)
127
- node1 && node2 && precede?(node2, node1) && comment_line?(node2.loc.expression.source)
127
+ node1 && node2 && precede?(node2, node1) && comment_line?(node2.source)
128
128
  end
129
129
 
130
130
  def ignored_gem?(node)
@@ -138,10 +138,10 @@ module RuboCop
138
138
  def correction_lambda
139
139
  return unless support_autocorrect?
140
140
 
141
- dedup_on_node(@v0_argument) { autocorrect(@v0_argument) }
141
+ dedupe_on_node(@v0_argument) { autocorrect(@v0_argument) }
142
142
  end
143
143
 
144
- def dedup_on_node(node)
144
+ def dedupe_on_node(node)
145
145
  @corrected_nodes ||= {}.compare_by_identity
146
146
  yield unless @corrected_nodes.key?(node)
147
147
  ensure
@@ -104,7 +104,7 @@ module RuboCop
104
104
  def to_range(node_or_range)
105
105
  range = case node_or_range
106
106
  when ::RuboCop::AST::Node, ::Parser::Source::Comment
107
- node_or_range.loc.expression
107
+ node_or_range.source_range
108
108
  when ::Parser::Source::Range
109
109
  node_or_range
110
110
  else
@@ -16,7 +16,7 @@ module RuboCop
16
16
  return unless node
17
17
 
18
18
  @processed_source = processed_source
19
- expr = node.respond_to?(:loc) ? node.loc.expression : node
19
+ expr = node.respond_to?(:loc) ? node.source_range : node
20
20
  return if block_comment_within?(expr)
21
21
 
22
22
  taboo_ranges = inside_string_ranges(node)
@@ -80,7 +80,7 @@ module RuboCop
80
80
 
81
81
  def block_comment_within?(expr)
82
82
  processed_source.comments.select(&:document?).any? do |c|
83
- within?(c.loc.expression, expr)
83
+ within?(c.source_range, expr)
84
84
  end
85
85
  end
86
86
 
@@ -35,15 +35,15 @@ module RuboCop
35
35
 
36
36
  def offending_range
37
37
  if block_node.arguments?
38
- replacement_range(argument_node.loc.expression.end_pos)
38
+ replacement_range(argument_node.source_range.end_pos)
39
39
  else
40
40
  replacement_range(block_node.loc.begin.end_pos)
41
41
  end
42
42
  end
43
43
 
44
44
  def replacement_range(end_pos)
45
- Parser::Source::Range.new(block_node.loc.expression.source_buffer,
46
- block_node.loc.expression.begin_pos,
45
+ Parser::Source::Range.new(block_node.source_range.source_buffer,
46
+ block_node.source_range.begin_pos,
47
47
  end_pos)
48
48
  end
49
49
  end
@@ -56,7 +56,7 @@ module RuboCop
56
56
  if collection_node.begin_type?
57
57
  collection_node.loc.end
58
58
  else
59
- collection_node.loc.expression
59
+ collection_node.source_range
60
60
  end
61
61
  end
62
62
 
@@ -65,8 +65,8 @@ module RuboCop
65
65
  end
66
66
 
67
67
  def replacement_range(end_pos)
68
- Parser::Source::Range.new(for_node.loc.expression.source_buffer,
69
- for_node.loc.expression.begin_pos,
68
+ Parser::Source::Range.new(for_node.source_range.source_buffer,
69
+ for_node.source_range.begin_pos,
70
70
  end_pos)
71
71
  end
72
72
  end
@@ -35,7 +35,7 @@ module RuboCop
35
35
  def move_comment(eol_comment:, node:, corrector:)
36
36
  return unless eol_comment
37
37
 
38
- text = eol_comment.loc.expression.source
38
+ text = eol_comment.source
39
39
  corrector.insert_before(node, "#{text}\n#{' ' * node.loc.keyword.column}")
40
40
  corrector.remove(eol_comment)
41
41
  end
@@ -52,7 +52,7 @@ module RuboCop
52
52
  return unless (parent = node.parent)
53
53
  return unless use_heredoc_argument_method_chain?(parent)
54
54
 
55
- chained_method = range_between(parent.loc.dot.begin_pos, parent.loc.expression.end_pos)
55
+ chained_method = range_between(parent.loc.dot.begin_pos, parent.source_range.end_pos)
56
56
 
57
57
  corrector.remove(chained_method)
58
58
  corrector.insert_after(end_range, chained_method.source)
@@ -80,7 +80,7 @@ module RuboCop
80
80
  def select_content_to_be_inserted_after_last_element(corrector, node)
81
81
  range = range_between(
82
82
  node.loc.end.begin_pos,
83
- range_by_whole_lines(node.loc.expression).end.end_pos
83
+ range_by_whole_lines(node.source_range).end.end_pos
84
84
  )
85
85
 
86
86
  remove_trailing_content_of_comment(corrector, range)
@@ -26,7 +26,7 @@ module RuboCop
26
26
  def declaration_with_comment(node)
27
27
  buffer = processed_source.buffer
28
28
  begin_pos = range_by_whole_lines(get_source_range(node, comments_as_separators)).begin_pos
29
- end_line = buffer.line_for_position(node.loc.expression.end_pos)
29
+ end_line = buffer.line_for_position(node.source_range.end_pos)
30
30
  end_pos = range_by_whole_lines(buffer.line_range(end_line),
31
31
  include_final_newline: true).end_pos
32
32
 
@@ -74,7 +74,7 @@ module RuboCop
74
74
  def add_heredoc_comma(corrector, node)
75
75
  return unless heredoc?(node)
76
76
 
77
- corrector.insert_after(node.child_nodes.last.loc.expression, ',')
77
+ corrector.insert_after(node.child_nodes.last, ',')
78
78
  end
79
79
 
80
80
  def heredoc?(node)
@@ -66,10 +66,10 @@ module RuboCop
66
66
  end
67
67
  end
68
68
 
69
- def line_breaks(node, source, previous_line_num, base_line_num, node_indx)
69
+ def line_breaks(node, source, previous_line_num, base_line_num, node_index)
70
70
  source_in_lines = source.split("\n")
71
71
  if first_line?(node, previous_line_num)
72
- node_indx.zero? && node.first_line == base_line_num ? '' : ' '
72
+ node_index.zero? && node.first_line == base_line_num ? '' : ' '
73
73
  else
74
74
  process_lines(node, previous_line_num, base_line_num, source_in_lines)
75
75
  end
@@ -94,7 +94,7 @@ module RuboCop
94
94
  private
95
95
 
96
96
  def allowed_gem?(node)
97
- allowed_gems.include?(node.first_argument.value)
97
+ allowed_gems.include?(node.first_argument.str_content)
98
98
  end
99
99
 
100
100
  def allowed_gems
@@ -24,7 +24,7 @@ module RuboCop
24
24
  MSG = 'Description should be started with %<suggestion>s instead of `This cop ...`.'
25
25
 
26
26
  SPECIAL_WORDS = %w[is can could should will would must may].freeze
27
- COP_DESC_OFFENSE_REGEX = \
27
+ COP_DESC_OFFENSE_REGEX =
28
28
  /^\s+# This cop (?<special>#{SPECIAL_WORDS.join('|')})?\s*(?<word>.+?) .*/.freeze
29
29
  REPLACEMENT_REGEX = /^\s+# This cop (#{SPECIAL_WORDS.join('|')})?\s*(.+?) /.freeze
30
30
 
@@ -59,9 +59,9 @@ module RuboCop
59
59
  end
60
60
 
61
61
  def range(node, comment_line)
62
- source_buffer = node.loc.expression.source_buffer
62
+ source_buffer = node.source_range.source_buffer
63
63
 
64
- begin_pos = node.loc.expression.begin_pos
64
+ begin_pos = node.source_range.begin_pos
65
65
  begin_pos += comment_index(node, comment_line)
66
66
  end_pos = begin_pos + comment_body(comment_line).length
67
67
 
@@ -77,7 +77,7 @@ module RuboCop
77
77
  end
78
78
 
79
79
  def first_comment_line(node)
80
- node.loc.expression.source.lines.find { |line| comment_line?(line) }
80
+ node.source.lines.find { |line| comment_line?(line) }
81
81
  end
82
82
 
83
83
  def comment_body(comment_line)
@@ -86,7 +86,7 @@ module RuboCop
86
86
 
87
87
  def comment_index(node, comment_line)
88
88
  body = comment_body(comment_line)
89
- node.loc.expression.source.index(body)
89
+ node.source.index(body)
90
90
  end
91
91
 
92
92
  def relevant_file?(file)