rubocop 1.89.0 → 1.90.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 (176) hide show
  1. checksums.yaml +4 -4
  2. data/config/default.yml +74 -7
  3. data/exe/rubocop +1 -1
  4. data/lib/rubocop/cached_data.rb +7 -2
  5. data/lib/rubocop/cli/command/execute_runner.rb +31 -0
  6. data/lib/rubocop/cli.rb +2 -4
  7. data/lib/rubocop/comment_config/directive_range.rb +32 -0
  8. data/lib/rubocop/comment_config/disable_next.rb +97 -0
  9. data/lib/rubocop/comment_config.rb +46 -30
  10. data/lib/rubocop/config.rb +23 -5
  11. data/lib/rubocop/config_loader.rb +1 -2
  12. data/lib/rubocop/config_loader_resolver.rb +1 -2
  13. data/lib/rubocop/config_validator.rb +1 -2
  14. data/lib/rubocop/cop/autocorrect_logic.rb +8 -0
  15. data/lib/rubocop/cop/base.rb +34 -2
  16. data/lib/rubocop/cop/corrector.rb +3 -3
  17. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -2
  18. data/lib/rubocop/cop/internal_affairs/node_pattern_groups/ast_walker.rb +1 -2
  19. data/lib/rubocop/cop/layout/block_alignment.rb +1 -2
  20. data/lib/rubocop/cop/layout/class_structure.rb +102 -26
  21. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +1 -2
  22. data/lib/rubocop/cop/layout/empty_line_after_magic_comment.rb +63 -5
  23. data/lib/rubocop/cop/layout/end_alignment.rb +1 -2
  24. data/lib/rubocop/cop/layout/extra_spacing.rb +105 -3
  25. data/lib/rubocop/cop/layout/first_argument_indentation.rb +21 -1
  26. data/lib/rubocop/cop/layout/line_continuation_spacing.rb +1 -2
  27. data/lib/rubocop/cop/layout/line_length.rb +1 -2
  28. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -2
  29. data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +5 -5
  30. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -2
  31. data/lib/rubocop/cop/layout/space_around_operators.rb +7 -0
  32. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +2 -4
  33. data/lib/rubocop/cop/lint/ambiguous_range.rb +1 -2
  34. data/lib/rubocop/cop/lint/argument_mismatch.rb +89 -0
  35. data/lib/rubocop/cop/lint/constant_reassignment.rb +17 -11
  36. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +84 -8
  37. data/lib/rubocop/cop/lint/deprecated_reference.rb +11 -2
  38. data/lib/rubocop/cop/lint/duplicate_methods.rb +112 -14
  39. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -2
  40. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +1 -2
  41. data/lib/rubocop/cop/lint/interpolation_check.rb +1 -2
  42. data/lib/rubocop/cop/lint/literal_as_condition.rb +3 -6
  43. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +3 -6
  44. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +25 -12
  45. data/lib/rubocop/cop/lint/name_typo.rb +53 -6
  46. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +15 -0
  47. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +98 -19
  48. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +47 -7
  49. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -2
  50. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +1 -2
  51. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -2
  52. data/lib/rubocop/cop/lint/redundant_type_conversion.rb +1 -2
  53. data/lib/rubocop/cop/lint/redundant_with_index.rb +1 -2
  54. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +1 -2
  55. data/lib/rubocop/cop/lint/safe_navigation_consistency.rb +2 -4
  56. data/lib/rubocop/cop/lint/super_argument_mismatch.rb +179 -0
  57. data/lib/rubocop/cop/lint/suppressed_exception_in_number_conversion.rb +1 -2
  58. data/lib/rubocop/cop/lint/to_enum_arguments.rb +1 -2
  59. data/lib/rubocop/cop/lint/unreachable_code.rb +1 -2
  60. data/lib/rubocop/cop/lint/unused_private_method.rb +94 -17
  61. data/lib/rubocop/cop/lint/useless_access_modifier.rb +1 -2
  62. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -2
  63. data/lib/rubocop/cop/lint/useless_constant_scoping.rb +36 -0
  64. data/lib/rubocop/cop/lint/useless_method_definition.rb +1 -1
  65. data/lib/rubocop/cop/lint/useless_rescue.rb +1 -2
  66. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +61 -7
  67. data/lib/rubocop/cop/lint/void.rb +1 -2
  68. data/lib/rubocop/cop/lint.rb +2 -0
  69. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -2
  70. data/lib/rubocop/cop/migration/department_name.rb +1 -2
  71. data/lib/rubocop/cop/mixin/comments_help.rb +1 -2
  72. data/lib/rubocop/cop/mixin/configurable_enforced_style.rb +1 -2
  73. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +1 -2
  74. data/lib/rubocop/cop/mixin/hash_subset.rb +1 -2
  75. data/lib/rubocop/cop/mixin/indexed_method_arity.rb +94 -0
  76. data/lib/rubocop/cop/mixin/line_length_help.rb +7 -1
  77. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +51 -6
  78. data/lib/rubocop/cop/mixin/range_help.rb +1 -2
  79. data/lib/rubocop/cop/mixin/statement_modifier.rb +13 -7
  80. data/lib/rubocop/cop/mixin/trailing_comma.rb +2 -4
  81. data/lib/rubocop/cop/mixin.rb +4 -0
  82. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +16 -0
  83. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +2 -4
  84. data/lib/rubocop/cop/naming/method_name.rb +5 -2
  85. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -2
  86. data/lib/rubocop/cop/offense.rb +27 -4
  87. data/lib/rubocop/cop/registry.rb +34 -10
  88. data/lib/rubocop/cop/style/accessor_grouping.rb +1 -2
  89. data/lib/rubocop/cop/style/arguments_forwarding.rb +3 -6
  90. data/lib/rubocop/cop/style/array_first_last.rb +1 -2
  91. data/lib/rubocop/cop/style/bitwise_predicate.rb +1 -2
  92. data/lib/rubocop/cop/style/block_delimiters.rb +3 -6
  93. data/lib/rubocop/cop/style/case_like_if.rb +2 -4
  94. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -2
  95. data/lib/rubocop/cop/style/combinable_loops.rb +1 -2
  96. data/lib/rubocop/cop/style/concat_array_literals.rb +1 -2
  97. data/lib/rubocop/cop/style/conditional_assignment.rb +1 -2
  98. data/lib/rubocop/cop/style/constant_visibility.rb +1 -2
  99. data/lib/rubocop/cop/style/copyright.rb +1 -2
  100. data/lib/rubocop/cop/style/directive_scope.rb +171 -0
  101. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +36 -10
  102. data/lib/rubocop/cop/style/empty_case_condition.rb +1 -2
  103. data/lib/rubocop/cop/style/format_string_token.rb +1 -2
  104. data/lib/rubocop/cop/style/guard_clause.rb +1 -2
  105. data/lib/rubocop/cop/style/hash_each_methods.rb +1 -2
  106. data/lib/rubocop/cop/style/hash_syntax.rb +1 -2
  107. data/lib/rubocop/cop/style/identical_conditional_branches.rb +2 -4
  108. data/lib/rubocop/cop/style/if_inside_else.rb +1 -2
  109. data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -2
  110. data/lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb +1 -2
  111. data/lib/rubocop/cop/style/map_to_hash.rb +1 -2
  112. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -4
  113. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +1 -2
  114. data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -2
  115. data/lib/rubocop/cop/style/negated_if_else_condition.rb +1 -2
  116. data/lib/rubocop/cop/style/negative_array_index.rb +2 -4
  117. data/lib/rubocop/cop/style/nil_comparison.rb +1 -2
  118. data/lib/rubocop/cop/style/operator_method_call.rb +1 -2
  119. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -2
  120. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -2
  121. data/lib/rubocop/cop/style/redundant_condition.rb +2 -4
  122. data/lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb +1 -2
  123. data/lib/rubocop/cop/style/redundant_each.rb +1 -2
  124. data/lib/rubocop/cop/style/redundant_format.rb +2 -4
  125. data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -4
  126. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +1 -2
  127. data/lib/rubocop/cop/style/redundant_return.rb +1 -2
  128. data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -2
  129. data/lib/rubocop/cop/style/redundant_string_escape.rb +1 -2
  130. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -2
  131. data/lib/rubocop/cop/style/safe_navigation.rb +1 -2
  132. data/lib/rubocop/cop/style/sample.rb +11 -6
  133. data/lib/rubocop/cop/style/select_by_regexp.rb +1 -2
  134. data/lib/rubocop/cop/style/semicolon.rb +2 -4
  135. data/lib/rubocop/cop/style/single_line_do_end_block.rb +1 -2
  136. data/lib/rubocop/cop/style/sole_nested_conditional.rb +1 -2
  137. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +2 -0
  138. data/lib/rubocop/cop/style/string_concatenation.rb +18 -5
  139. data/lib/rubocop/cop/style/super_arguments.rb +1 -2
  140. data/lib/rubocop/cop/style/symbol_proc.rb +1 -2
  141. data/lib/rubocop/cop/style/time_now.rb +41 -0
  142. data/lib/rubocop/cop/style/yoda_condition.rb +1 -2
  143. data/lib/rubocop/cop/style.rb +2 -0
  144. data/lib/rubocop/cop/team.rb +11 -3
  145. data/lib/rubocop/cop/util.rb +2 -4
  146. data/lib/rubocop/cop/variable_force/variable.rb +1 -2
  147. data/lib/rubocop/cops_documentation_generator.rb +3 -6
  148. data/lib/rubocop/directive_comment.rb +37 -3
  149. data/lib/rubocop/formatter/emacs_style_formatter.rb +3 -1
  150. data/lib/rubocop/formatter/html_formatter.rb +2 -4
  151. data/lib/rubocop/formatter/json_formatter.rb +11 -6
  152. data/lib/rubocop/formatter/junit_formatter.rb +26 -9
  153. data/lib/rubocop/formatter/offense_count_formatter.rb +1 -2
  154. data/lib/rubocop/formatter/simple_text_formatter.rb +4 -3
  155. data/lib/rubocop/formatter/tap_formatter.rb +3 -1
  156. data/lib/rubocop/formatter/worst_offenders_formatter.rb +1 -2
  157. data/lib/rubocop/lockfile.rb +18 -0
  158. data/lib/rubocop/lsp/diagnostic.rb +4 -8
  159. data/lib/rubocop/lsp/routes.rb +48 -19
  160. data/lib/rubocop/mcp/server.rb +1 -2
  161. data/lib/rubocop/options.rb +10 -6
  162. data/lib/rubocop/path_util.rb +1 -2
  163. data/lib/rubocop/plugin/configuration_integrator.rb +6 -3
  164. data/lib/rubocop/rake_task.rb +1 -2
  165. data/lib/rubocop/rspec/expect_offense.rb +2 -4
  166. data/lib/rubocop/rspec/shared_contexts.rb +4 -2
  167. data/lib/rubocop/runner.rb +26 -23
  168. data/lib/rubocop/server/cache.rb +1 -2
  169. data/lib/rubocop/server/cli.rb +2 -4
  170. data/lib/rubocop/server.rb +14 -0
  171. data/lib/rubocop/target_finder.rb +4 -1
  172. data/lib/rubocop/todo_audit.rb +111 -0
  173. data/lib/rubocop/version.rb +3 -5
  174. data/lib/rubocop.rb +3 -0
  175. data/lib/ruby_lsp/rubocop/addon.rb +1 -2
  176. metadata +13 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e613534eb66c6766aa04d7e1075e0d09aa8a3a78690b8b921583d81ea9fb8e9e
4
- data.tar.gz: c65ec7b8f764105d8950cc73c4deca24f6bec976c6c4041b5338f4a97e98645c
3
+ metadata.gz: 382da6a2b30d9de3a34dfad6d8a2aba1f4c314881d4a7a419d698b58faf07cd4
4
+ data.tar.gz: 3807b557f0eedb44f81b1a20880649e15b8c76ed31a916756d626a13b391d556
5
5
  SHA512:
6
- metadata.gz: 400677d5633740bb086f3f6e4c6cb9438423ce5a77ea6bc8a4bd72ff0249332c58370bbd98f809673699806cc2ae8dfde4d95a9313bfb8e465c631b506a18d20
7
- data.tar.gz: a08736ea293673d3cebd8185df6b8b0cf718d24d23b772c20c09c1c00e61838c4963245e84074fe0b8732ad5eb32f9f459c3d915fb5a07ad9ee0e0019d2b9a2c
6
+ metadata.gz: 7654d620f9e6504e76855f15335df419416a8353da06cb55c0a15b1fa123b2cabc170792846e8ee5ab1b122003d14038809f524fdf7a07773d51a69b1faca234
7
+ data.tar.gz: 296dc584530a8191088320cfcfe2fdd38339da0888aac861b510ba219b50a601bd4bd060b831f9733f12553031c20abd91fdcc7ece654d0e716857ef7eb8cee8
data/config/default.yml CHANGED
@@ -427,7 +427,7 @@ Layout/ArrayAlignment:
427
427
  Description: >-
428
428
  Align the elements of an array literal if they span more than
429
429
  one line.
430
- StyleGuide: '#no-double-indent'
430
+ StyleGuide: '#align-multiline-arrays'
431
431
  Enabled: true
432
432
  VersionAdded: '0.49'
433
433
  VersionChanged: '0.77'
@@ -618,6 +618,12 @@ Layout/EmptyLineAfterMagicComment:
618
618
  StyleGuide: '#separate-magic-comments-from-code'
619
619
  Enabled: true
620
620
  VersionAdded: '0.49'
621
+ VersionChanged: '1.90'
622
+ # The minimum number of empty lines required after the last magic comment. Set this
623
+ # to `2` when using YARD, which otherwise treats the magic comments as documentation
624
+ # for the first module or class in the file. `Layout/EmptyLines` has to be disabled
625
+ # for values greater than `1`.
626
+ NumberOfEmptyLines: 1
621
627
 
622
628
  Layout/EmptyLineAfterMultilineCondition:
623
629
  Description: 'Enforces empty line after multiline condition.'
@@ -1416,6 +1422,7 @@ Layout/SpaceAroundOperators:
1416
1422
  StyleGuide: '#spaces-operators'
1417
1423
  Enabled: true
1418
1424
  VersionAdded: '0.49'
1425
+ VersionChanged: '1.90'
1419
1426
  # When `true`, allows most uses of extra spacing if the intent is to align
1420
1427
  # with an operator on the previous or next line, not counting empty lines
1421
1428
  # or comment lines.
@@ -1659,6 +1666,13 @@ Lint/AmbiguousRegexpLiteral:
1659
1666
  VersionAdded: '0.17'
1660
1667
  VersionChanged: '0.83'
1661
1668
 
1669
+ Lint/ArgumentMismatch:
1670
+ Description: >-
1671
+ Checks for calls that pass the wrong number of positional arguments
1672
+ to a method, using the project index.
1673
+ Enabled: pending
1674
+ VersionAdded: '1.90'
1675
+
1662
1676
  Lint/ArrayLiteralInRegexp:
1663
1677
  Description: 'Checks for an array literal interpolated inside a regexp.'
1664
1678
  Enabled: pending
@@ -1734,6 +1748,7 @@ Lint/CopDirectiveSyntax:
1734
1748
  Description: 'Checks that `# rubocop:` directives are strictly formatted.'
1735
1749
  Enabled: pending
1736
1750
  VersionAdded: '1.72'
1751
+ VersionChanged: '1.90'
1737
1752
 
1738
1753
  Lint/DataDefineOverride:
1739
1754
  Description: 'Disallow overriding the `Data` built-in methods via `Data.define`.'
@@ -1849,6 +1864,7 @@ Lint/DeprecatedReference:
1849
1864
 
1850
1865
  Lint/DisjunctiveAssignmentInConstructor:
1851
1866
  Description: 'In constructor, plain assignment is preferred over disjunctive.'
1867
+ StyleGuide: '#disjunctive-assignment-in-constructor'
1852
1868
  Enabled: true
1853
1869
  Safe: false
1854
1870
  VersionAdded: '0.62'
@@ -1893,7 +1909,7 @@ Lint/DuplicateMethods:
1893
1909
  Description: 'Checks for duplicate method definitions.'
1894
1910
  Enabled: true
1895
1911
  VersionAdded: '0.29'
1896
- VersionChanged: '1.89'
1912
+ VersionChanged: '1.90'
1897
1913
  # Methods that define instance methods by delegation, in the style of
1898
1914
  # Active Support's `delegate` (`delegate :foo, :bar, to: :target`). Register
1899
1915
  # a project's own `delegate`-shaped macros here so the cop recognizes the
@@ -1901,6 +1917,14 @@ Lint/DuplicateMethods:
1901
1917
  # is `true`.
1902
1918
  DelegatingMethods:
1903
1919
  - delegate
1920
+ # Cross-file duplicates (detected with `AllCops/UseProjectIndex`) whose other
1921
+ # definition lives in a file matching one of these patterns are not reported.
1922
+ # Useful for files that redefine application methods but are never loaded
1923
+ # together with them, such as standalone scripts. Patterns follow the same
1924
+ # glob (or regexp) semantics as `Exclude` and are matched against the other
1925
+ # file's path relative to the directory of the config file; absolute patterns
1926
+ # are matched against the absolute path.
1927
+ AllowedCrossFilePaths: []
1904
1928
 
1905
1929
  Lint/DuplicateRegexpCharacterClassElement:
1906
1930
  Description: 'Checks for duplicate elements in Regexp character classes.'
@@ -2140,7 +2164,7 @@ Lint/MissingCopEnableDirective:
2140
2164
  Description: 'Checks for a `# rubocop:enable` after `# rubocop:disable`.'
2141
2165
  Enabled: true
2142
2166
  VersionAdded: '0.52'
2143
- VersionChanged: '1.88'
2167
+ VersionChanged: '1.90'
2144
2168
  # Maximum number of consecutive lines the cop can be disabled for.
2145
2169
  # 0 allows only single-line disables
2146
2170
  # 1 would mean the maximum allowed is the following:
@@ -2167,6 +2191,7 @@ Lint/MixedCaseRange:
2167
2191
 
2168
2192
  Lint/MixedRegexpCaptureTypes:
2169
2193
  Description: 'Do not mix named captures and numbered captures in a Regexp literal.'
2194
+ StyleGuide: '#do-not-mix-named-and-numbered-captures'
2170
2195
  Enabled: true
2171
2196
  VersionAdded: '0.85'
2172
2197
 
@@ -2323,6 +2348,7 @@ Lint/RedundantCopEnableDirective:
2323
2348
  Description: Checks for rubocop:enable comments that can be removed.
2324
2349
  Enabled: true
2325
2350
  VersionAdded: '0.76'
2351
+ VersionChanged: '1.90'
2326
2352
 
2327
2353
  Lint/RedundantDirGlobSort:
2328
2354
  Description: 'Checks for redundant `sort` method to `Dir.glob` and `Dir[]`.'
@@ -2505,6 +2531,7 @@ Lint/ShadowedException:
2505
2531
  Description: >-
2506
2532
  Avoid rescuing a higher level exception
2507
2533
  before a lower level exception.
2534
+ StyleGuide: '#exception-ordering'
2508
2535
  Enabled: true
2509
2536
  VersionAdded: '0.41'
2510
2537
 
@@ -2527,6 +2554,13 @@ Lint/StructNewOverride:
2527
2554
  Enabled: true
2528
2555
  VersionAdded: '0.81'
2529
2556
 
2557
+ Lint/SuperArgumentMismatch:
2558
+ Description: >-
2559
+ Checks for `super` calls that pass the wrong number of positional
2560
+ arguments to the overridden implementation, using the project index.
2561
+ Enabled: pending
2562
+ VersionAdded: '1.90'
2563
+
2530
2564
  Lint/SuppressedException:
2531
2565
  Description: "Don't suppress exceptions."
2532
2566
  StyleGuide: '#dont-hide-exceptions'
@@ -2617,6 +2651,7 @@ Lint/UnexpectedBlockArity:
2617
2651
 
2618
2652
  Lint/UnifiedInteger:
2619
2653
  Description: 'Use Integer instead of Fixnum or Bignum.'
2654
+ StyleGuide: '#integer-type-checking'
2620
2655
  Enabled: true
2621
2656
  VersionAdded: '0.43'
2622
2657
 
@@ -2679,7 +2714,10 @@ Lint/UnusedPrivateMethod:
2679
2714
  # would be reported as false positives. It is intended for occasional
2680
2715
  # dead-code sweeps rather than permanent enforcement.
2681
2716
  Enabled: false
2717
+ AllowedNames: []
2718
+ AllowedPatterns: []
2682
2719
  VersionAdded: '1.89'
2720
+ VersionChanged: '1.90'
2683
2721
 
2684
2722
  Lint/UriEscapeUnescape:
2685
2723
  Description: >-
@@ -2718,6 +2756,7 @@ Lint/UselessConstantScoping:
2718
2756
  Description: 'Checks for useless constant scoping.'
2719
2757
  Enabled: pending
2720
2758
  VersionAdded: '1.72'
2759
+ VersionChanged: '1.90'
2721
2760
 
2722
2761
  Lint/UselessDefaultValueArgument:
2723
2762
  Description: 'Checks for usage of `fetch` or `Array.new` with default value argument and block.'
@@ -3415,6 +3454,7 @@ Style/ArrayCoercion:
3415
3454
 
3416
3455
  Style/ArrayFirstLast:
3417
3456
  Description: 'Use `arr.first` and `arr.last` instead of `arr[0]` and `arr[-1]`.'
3457
+ StyleGuide: '#first-and-last'
3418
3458
  References:
3419
3459
  - '#first-and-last'
3420
3460
  Enabled: false
@@ -3878,6 +3918,7 @@ Style/ConditionalAssignment:
3878
3918
  Use the return value of `if` and `case` statements for
3879
3919
  assignment to a variable and variable comparison instead
3880
3920
  of assigning that variable inside of each branch.
3921
+ StyleGuide: '#use-if-case-returns'
3881
3922
  Enabled: true
3882
3923
  VersionAdded: '0.36'
3883
3924
  VersionChanged: '0.47'
@@ -3938,7 +3979,7 @@ Style/DataInheritance:
3938
3979
 
3939
3980
  Style/DateTime:
3940
3981
  Description: 'Use Time over DateTime.'
3941
- StyleGuide: '#date-time'
3982
+ StyleGuide: '#no-datetime'
3942
3983
  Enabled: false
3943
3984
  VersionAdded: '0.51'
3944
3985
  VersionChanged: '0.92'
@@ -3971,14 +4012,23 @@ Style/DirEmpty:
3971
4012
  Enabled: pending
3972
4013
  VersionAdded: '1.48'
3973
4014
 
4015
+ Style/DirectiveScope:
4016
+ Description: >-
4017
+ Checks for directive scopes that can be expressed with the
4018
+ tighter `disable-next` form.
4019
+ Enabled: pending
4020
+ SafeAutoCorrect: false
4021
+ VersionAdded: '1.90'
4022
+
3974
4023
  Style/DisableCopsWithinSourceCodeDirective:
3975
4024
  Description: >-
3976
4025
  Forbids disabling/enabling cops within source code.
3977
4026
  Enabled: false
3978
4027
  VersionAdded: '0.82'
3979
- VersionChanged: '1.89'
4028
+ VersionChanged: '1.90'
3980
4029
  AllowedCops: []
3981
4030
  DisallowedCops: []
4031
+ AllowTrailingComment: false
3982
4032
 
3983
4033
  Style/DocumentDynamicEvalDefinition:
3984
4034
  Description: >-
@@ -4051,6 +4101,7 @@ Style/EmptyCaseCondition:
4051
4101
 
4052
4102
  Style/EmptyClassDefinition:
4053
4103
  Description: 'Enforces consistent style for empty class definitions.'
4104
+ StyleGuide: '#single-line-classes'
4054
4105
  Enabled: pending
4055
4106
  VersionAdded: '1.84'
4056
4107
  VersionChanged: '1.86'
@@ -4216,12 +4267,14 @@ Style/FileEmpty:
4216
4267
 
4217
4268
  Style/FileNull:
4218
4269
  Description: 'Use `File::NULL` instead of hardcoding "dev/null".'
4270
+ StyleGuide: '#null-devices'
4219
4271
  Enabled: pending
4220
4272
  SafeAutoCorrect: false
4221
4273
  VersionAdded: '1.69'
4222
4274
 
4223
4275
  Style/FileOpen:
4224
4276
  Description: 'Checks for `File.open` without a block, which can leak file descriptors.'
4277
+ StyleGuide: '#auto-release-resources'
4225
4278
  Enabled: pending
4226
4279
  Safe: false
4227
4280
  VersionAdded: '1.85'
@@ -4286,6 +4339,7 @@ Style/FormatString:
4286
4339
 
4287
4340
  Style/FormatStringToken:
4288
4341
  Description: 'Use a consistent style for format string tokens.'
4342
+ StyleGuide: '#named-format-tokens'
4289
4343
  Enabled: true
4290
4344
  VersionAdded: '0.49'
4291
4345
  VersionChanged: '1.74'
@@ -4475,6 +4529,7 @@ Style/HashSyntax:
4475
4529
 
4476
4530
  Style/HashTransformKeys:
4477
4531
  Description: 'Prefer `transform_keys` over `each_with_object`, `map`, or `to_h`.'
4532
+ StyleGuide: '#hash-transform-methods'
4478
4533
  Enabled: true
4479
4534
  VersionAdded: '0.80'
4480
4535
  VersionChanged: '0.90'
@@ -4482,6 +4537,7 @@ Style/HashTransformKeys:
4482
4537
 
4483
4538
  Style/HashTransformValues:
4484
4539
  Description: 'Prefer `transform_values` over `each_with_object`, `map`, or `to_h`.'
4540
+ StyleGuide: '#hash-transform-methods'
4485
4541
  Enabled: true
4486
4542
  VersionAdded: '0.80'
4487
4543
  VersionChanged: '0.90'
@@ -4652,7 +4708,7 @@ Style/KeywordArgumentsMerging:
4652
4708
 
4653
4709
  Style/KeywordParametersOrder:
4654
4710
  Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
4655
- StyleGuide: '#keyword-parameters-order'
4711
+ StyleGuide: '#keyword-arguments-order'
4656
4712
  Enabled: true
4657
4713
  VersionAdded: '0.90'
4658
4714
  VersionChanged: '1.7'
@@ -4685,6 +4741,7 @@ Style/LineEndConcatenation:
4685
4741
  Description: >-
4686
4742
  Use \ instead of + or << to concatenate two string literals at
4687
4743
  line end.
4744
+ StyleGuide: '#heredoc-long-strings'
4688
4745
  Enabled: true
4689
4746
  SafeAutoCorrect: false
4690
4747
  VersionAdded: '0.18'
@@ -4982,7 +5039,7 @@ Style/NegatedIfElseCondition:
4982
5039
 
4983
5040
  Style/NegatedUnless:
4984
5041
  Description: 'Favor if over unless for negative conditions.'
4985
- StyleGuide: '#if-for-negatives'
5042
+ StyleGuide: '#unless-for-negatives'
4986
5043
  Enabled: true
4987
5044
  VersionAdded: '0.69'
4988
5045
  EnforcedStyle: both
@@ -5185,6 +5242,7 @@ Style/ObjectThen:
5185
5242
 
5186
5243
  Style/OneClassPerFile:
5187
5244
  Description: 'Checks that each source file defines at most one top-level class or module.'
5245
+ StyleGuide: '#one-class-per-file'
5188
5246
  Enabled: pending
5189
5247
  VersionAdded: '1.85'
5190
5248
  VersionChanged: '1.86'
@@ -5550,6 +5608,7 @@ Style/RedundantInterpolationUnfreeze:
5550
5608
 
5551
5609
  Style/RedundantLineContinuation:
5552
5610
  Description: 'Checks for redundant line continuation.'
5611
+ StyleGuide: '#no-trailing-backslash'
5553
5612
  Enabled: pending
5554
5613
  VersionAdded: '1.49'
5555
5614
 
@@ -5586,6 +5645,7 @@ Style/RedundantRegexpConstructor:
5586
5645
 
5587
5646
  Style/RedundantRegexpEscape:
5588
5647
  Description: 'Checks for redundant escapes in Regexps.'
5648
+ StyleGuide: '#limit-escapes'
5589
5649
  Enabled: true
5590
5650
  VersionAdded: '0.85'
5591
5651
 
@@ -6039,6 +6099,12 @@ Style/TernaryParentheses:
6039
6099
  - require_parentheses_when_complex
6040
6100
  AllowSafeAssignment: true
6041
6101
 
6102
+ Style/TimeNow:
6103
+ Description: 'Prefer `Time.now` over `Time.new` when retrieving the current system time.'
6104
+ StyleGuide: '#time-now'
6105
+ Enabled: pending
6106
+ VersionAdded: '1.90'
6107
+
6042
6108
  Style/TopLevelMethodDefinition:
6043
6109
  Description: 'Looks for top-level method definitions.'
6044
6110
  StyleGuide: '#top-level-methods'
@@ -6129,6 +6195,7 @@ Style/TrailingUnderscoreVariable:
6129
6195
  Description: >-
6130
6196
  Checks for the usage of unneeded trailing underscores at the
6131
6197
  end of parallel variable assignment.
6198
+ StyleGuide: '#trailing-underscore-variables'
6132
6199
  Enabled: true
6133
6200
  VersionAdded: '0.31'
6134
6201
  VersionChanged: '0.35'
data/exe/rubocop CHANGED
@@ -8,7 +8,7 @@ server_cli = RuboCop::Server::CLI.new
8
8
  exit_status = server_cli.run
9
9
  exit exit_status if server_cli.exit?
10
10
 
11
- if RuboCop::Server.running?
11
+ if RuboCop::Server.forward_to_server?
12
12
  exit_status = RuboCop::Server::ClientCommand::Exec.new.run
13
13
  else
14
14
  require 'rubocop'
@@ -22,7 +22,7 @@ module RuboCop
22
22
 
23
23
  def serialize_offense(offense)
24
24
  status = :uncorrected if %i[corrected corrected_with_todo].include?(offense.status)
25
- {
25
+ hash = {
26
26
  # Calling #to_s here ensures that the serialization works when using
27
27
  # other json serializers such as Oj. Some of these gems do not call
28
28
  # #to_s implicitly.
@@ -35,6 +35,10 @@ module RuboCop
35
35
  cop_name: offense.cop_name,
36
36
  status: status || offense.status
37
37
  }
38
+ # Only offenses suppressed by a directive can carry one, so keep the key out of the
39
+ # common case rather than writing a null for every cached offense.
40
+ hash[:justification] = offense.justification if offense.justification
41
+ hash
38
42
  end
39
43
 
40
44
  def message(offense)
@@ -47,7 +51,8 @@ module RuboCop
47
51
  def deserialize_offenses(offenses)
48
52
  offenses.map! do |o|
49
53
  location = location_from_source_buffer(o)
50
- Cop::Offense.new(o['severity'], location, o['message'], o['cop_name'], o['status'].to_sym)
54
+ Cop::Offense.new(o['severity'], location, o['message'], o['cop_name'], o['status'].to_sym,
55
+ justification: o['justification'])
51
56
  end
52
57
  end
53
58
 
@@ -30,6 +30,10 @@ module RuboCop
30
30
 
31
31
  maybe_print_corrected_source
32
32
 
33
+ merge_todo_audit_status(runner_status(runner, all_pass_or_excluded))
34
+ end
35
+
36
+ def runner_status(runner, all_pass_or_excluded)
33
37
  if runner.aborting?
34
38
  STATUS_INTERRUPTED
35
39
  elsif all_pass_or_excluded && runner.errors.empty?
@@ -39,6 +43,33 @@ module RuboCop
39
43
  end
40
44
  end
41
45
 
46
+ def merge_todo_audit_status(status)
47
+ return status if status == STATUS_INTERRUPTED || !@options[:report_unused_todo_entries]
48
+
49
+ audit_status = report_unused_todo_entries
50
+ status == STATUS_SUCCESS ? audit_status : status
51
+ end
52
+
53
+ def report_unused_todo_entries
54
+ audit = TodoAudit.new(@config_store, @options)
55
+ unused = audit.unused_entries
56
+
57
+ if unused.nil?
58
+ warn Rainbow("No `#{audit.todo_file}` found; nothing to audit.").yellow
59
+ return STATUS_SUCCESS
60
+ end
61
+ return STATUS_SUCCESS if unused.empty?
62
+
63
+ print_unused_todo_entries(audit.todo_file, unused)
64
+ STATUS_OFFENSES
65
+ end
66
+
67
+ def print_unused_todo_entries(todo_file, unused)
68
+ noun = unused.size == 1 ? 'entry' : 'entries'
69
+ warn Rainbow("\n#{unused.size} unused todo #{noun} found in `#{todo_file}`:").red
70
+ unused.each { |entry| warn " #{entry.cop_name}: #{entry.path}" }
71
+ end
72
+
42
73
  def with_redirect
43
74
  if @options[:stderr]
44
75
  orig_stdout = $stdout
data/lib/rubocop/cli.rb CHANGED
@@ -35,7 +35,7 @@ module RuboCop
35
35
  # @param args [Array<String>] command line arguments
36
36
  # @return [Integer] UNIX exit code
37
37
  #
38
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
38
+ # rubocop:disable-next Metrics/MethodLength, Metrics/AbcSize
39
39
  def run(args = ARGV)
40
40
  time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
41
41
 
@@ -80,11 +80,10 @@ module RuboCop
80
80
  puts "Finished in #{elapsed_time.round(5)} seconds"
81
81
  end
82
82
  end
83
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
84
83
 
85
84
  private
86
85
 
87
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
86
+ # rubocop:disable-next Metrics/MethodLength, Metrics/AbcSize
88
87
  def profile_if_needed
89
88
  return yield unless @options[:profile]
90
89
 
@@ -116,7 +115,6 @@ module RuboCop
116
115
  end
117
116
  status
118
117
  end
119
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
120
118
 
121
119
  def require_gem(name)
122
120
  require name
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CommentConfig
5
+ # A disabled line range that remembers the directive comment that opened
6
+ # it. Value-equal to a plain `Range`, so consumers comparing or hashing
7
+ # ranges are unaffected.
8
+ # @api private
9
+ class DirectiveRange < Range
10
+ attr_reader :directive
11
+
12
+ def initialize(first_line, last_line, directive)
13
+ super(first_line, last_line)
14
+ @directive = directive
15
+ end
16
+ end
17
+
18
+ # The per-cop state accumulated while analyzing directives: the disabled
19
+ # ranges so far, plus the line and directive of the currently open
20
+ # disable, if any.
21
+ # @api private
22
+ CopAnalysis = Struct.new(:line_ranges, :start_line_number, :start_directive) do
23
+ # The open range (if any) closed at the given line, appended to the
24
+ # accumulated ranges, each remembering the directive that opened it.
25
+ def close(line)
26
+ return line_ranges unless start_line_number
27
+
28
+ line_ranges + [DirectiveRange.new(start_line_number, line, start_directive)]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CommentConfig
5
+ # Handling of `disable-next` directives: computing the statement scope
6
+ # they apply to and tracking directives that attached to nothing.
7
+ # The scope is the whole statement starting on the next line bearing
8
+ # code. Comment-only lines between the directive and the code chain (so
9
+ # several directives can stack), while a blank line breaks the attachment.
10
+ # @api private
11
+ module DisableNext
12
+ # `disable-next` directives that suppress nothing: nothing follows
13
+ # them, or they sit at the end of a code line.
14
+ def detached_next_directives
15
+ cop_disabled_line_ranges # ensure the analysis that collects them ran
16
+ @detached_next_directives
17
+ end
18
+
19
+ # The line range of the statement a `disable-next` directive on the
20
+ # given line scopes to (or would scope to), or `nil` when no statement
21
+ # is attached. A directive is only honored on a comment-only line.
22
+ # Stacked directives share the target, so the computation is memoized.
23
+ # @api private
24
+ def statement_scope_after(line)
25
+ return nil unless comment_only_line?(line)
26
+
27
+ code_line = attached_code_line(line)
28
+ return nil unless code_line
29
+
30
+ (@statement_bounds ||= {})[code_line] ||= statement_bounds_at(code_line)
31
+ end
32
+
33
+ private
34
+
35
+ def apply_disable_next(analyses, directive)
36
+ bounds = statement_scope_after(directive.line_number)
37
+ return @detached_next_directives << directive unless bounds
38
+
39
+ range = DirectiveRange.new(bounds.begin, bounds.end, directive)
40
+ directive.cop_names.each do |cop_name|
41
+ add_next_range(analyses, qualified_cop_name(cop_name), range)
42
+ end
43
+ end
44
+
45
+ def add_next_range(analyses, cop_name, range)
46
+ analysis = analyses[cop_name]
47
+ analyses[cop_name] = CopAnalysis.new(analysis.line_ranges + [range],
48
+ analysis.start_line_number, analysis.start_directive)
49
+ end
50
+
51
+ def attached_code_line(directive_line)
52
+ ((directive_line + 1)..processed_source.lines.size).each do |line|
53
+ return line unless comment_only_line?(line)
54
+ return nil if processed_source[line - 1].blank?
55
+ end
56
+
57
+ nil
58
+ end
59
+
60
+ def statement_bounds_at(line)
61
+ statement = statement_starting_at(line)
62
+ # A code line where no statement starts (e.g. a lone `end`) scopes
63
+ # the directive to that line alone.
64
+ return (line..line) unless statement
65
+
66
+ (line..statement_end_line(statement))
67
+ end
68
+
69
+ def statement_start_line?(node, line)
70
+ # Synthetic nodes (e.g. parentheses-less argument lists) have no
71
+ # source range. `begin` nodes are sequences of statements, not
72
+ # statements themselves - taking one would scope the directive to
73
+ # everything up to the last statement of the sequence.
74
+ node.source_range && node.first_line == line && !node.begin_type?
75
+ end
76
+
77
+ def statement_starting_at(line)
78
+ ast = processed_source.ast
79
+ return nil unless ast
80
+
81
+ ast.each_node.select { |node| statement_start_line?(node, line) }.max_by(&:last_line)
82
+ end
83
+
84
+ def statement_end_line(statement)
85
+ statement.each_node.filter_map do |node|
86
+ next unless node.source_range
87
+
88
+ heredoc?(node) ? node.loc.heredoc_end.line : node.last_line
89
+ end.max
90
+ end
91
+
92
+ def heredoc?(node)
93
+ node.respond_to?(:heredoc?) && node.heredoc?
94
+ end
95
+ end
96
+ end
97
+ end