rubocop 1.78.0 → 1.81.6

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 (117) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -3
  3. data/config/default.yml +46 -21
  4. data/exe/rubocop +1 -8
  5. data/lib/rubocop/cli/command/auto_generate_config.rb +2 -2
  6. data/lib/rubocop/cli.rb +6 -2
  7. data/lib/rubocop/config_loader.rb +3 -1
  8. data/lib/rubocop/config_store.rb +5 -0
  9. data/lib/rubocop/cop/autocorrect_logic.rb +4 -4
  10. data/lib/rubocop/cop/correctors/alignment_corrector.rb +7 -4
  11. data/lib/rubocop/cop/correctors/for_to_each_corrector.rb +7 -2
  12. data/lib/rubocop/cop/internal_affairs/node_pattern_groups.rb +3 -1
  13. data/lib/rubocop/cop/internal_affairs/node_type_group.rb +3 -2
  14. data/lib/rubocop/cop/internal_affairs/on_send_without_on_csend.rb +1 -1
  15. data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +1 -1
  16. data/lib/rubocop/cop/layout/class_structure.rb +1 -1
  17. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  18. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +30 -12
  19. data/lib/rubocop/cop/layout/empty_lines_after_module_inclusion.rb +101 -0
  20. data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +8 -29
  21. data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +1 -1
  22. data/lib/rubocop/cop/layout/hash_alignment.rb +0 -5
  23. data/lib/rubocop/cop/layout/line_length.rb +9 -1
  24. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +8 -4
  25. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +8 -0
  26. data/lib/rubocop/cop/layout/space_around_keyword.rb +6 -1
  27. data/lib/rubocop/cop/layout/space_around_operators.rb +8 -0
  28. data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
  29. data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +3 -2
  30. data/lib/rubocop/cop/lint/cop_directive_syntax.rb +13 -7
  31. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +4 -1
  32. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +5 -42
  33. data/lib/rubocop/cop/lint/empty_interpolation.rb +11 -0
  34. data/lib/rubocop/cop/lint/literal_as_condition.rb +12 -0
  35. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +1 -2
  36. data/lib/rubocop/cop/lint/numeric_operation_with_constant_result.rb +1 -0
  37. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +101 -2
  38. data/lib/rubocop/cop/lint/require_range_parentheses.rb +1 -1
  39. data/lib/rubocop/cop/lint/rescue_exception.rb +1 -4
  40. data/lib/rubocop/cop/lint/rescue_type.rb +1 -1
  41. data/lib/rubocop/cop/lint/self_assignment.rb +6 -5
  42. data/lib/rubocop/cop/lint/shadowed_argument.rb +7 -7
  43. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -0
  44. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +1 -0
  45. data/lib/rubocop/cop/lint/utils/nil_receiver_checker.rb +121 -0
  46. data/lib/rubocop/cop/lint/void.rb +7 -0
  47. data/lib/rubocop/cop/message_annotator.rb +1 -1
  48. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  49. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -7
  50. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  51. data/lib/rubocop/cop/naming/method_name.rb +40 -1
  52. data/lib/rubocop/cop/naming/predicate_method.rb +19 -3
  53. data/lib/rubocop/cop/security/json_load.rb +33 -11
  54. data/lib/rubocop/cop/style/access_modifier_declarations.rb +1 -1
  55. data/lib/rubocop/cop/style/accessor_grouping.rb +13 -1
  56. data/lib/rubocop/cop/style/arguments_forwarding.rb +11 -17
  57. data/lib/rubocop/cop/style/array_intersect.rb +99 -35
  58. data/lib/rubocop/cop/style/array_intersect_with_single_element.rb +47 -0
  59. data/lib/rubocop/cop/style/bitwise_predicate.rb +8 -1
  60. data/lib/rubocop/cop/style/block_delimiters.rb +1 -1
  61. data/lib/rubocop/cop/style/conditional_assignment.rb +8 -4
  62. data/lib/rubocop/cop/style/dig_chain.rb +1 -1
  63. data/lib/rubocop/cop/style/double_negation.rb +1 -1
  64. data/lib/rubocop/cop/style/endless_method.rb +15 -2
  65. data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
  66. data/lib/rubocop/cop/style/exponential_notation.rb +1 -0
  67. data/lib/rubocop/cop/style/hash_syntax.rb +1 -1
  68. data/lib/rubocop/cop/style/infinite_loop.rb +1 -1
  69. data/lib/rubocop/cop/style/inverse_methods.rb +1 -1
  70. data/lib/rubocop/cop/style/it_assignment.rb +69 -12
  71. data/lib/rubocop/cop/style/it_block_parameter.rb +2 -0
  72. data/lib/rubocop/cop/style/map_to_hash.rb +1 -3
  73. data/lib/rubocop/cop/style/map_to_set.rb +1 -3
  74. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -4
  75. data/lib/rubocop/cop/style/nil_comparison.rb +9 -7
  76. data/lib/rubocop/cop/style/one_line_conditional.rb +17 -9
  77. data/lib/rubocop/cop/style/parallel_assignment.rb +32 -20
  78. data/lib/rubocop/cop/style/redundant_begin.rb +34 -0
  79. data/lib/rubocop/cop/style/redundant_condition.rb +1 -1
  80. data/lib/rubocop/cop/style/redundant_exception.rb +1 -1
  81. data/lib/rubocop/cop/style/redundant_format.rb +26 -5
  82. data/lib/rubocop/cop/style/redundant_freeze.rb +1 -1
  83. data/lib/rubocop/cop/style/redundant_interpolation.rb +11 -2
  84. data/lib/rubocop/cop/style/redundant_line_continuation.rb +1 -1
  85. data/lib/rubocop/cop/style/redundant_parentheses.rb +29 -11
  86. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -0
  87. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -0
  88. data/lib/rubocop/cop/style/safe_navigation.rb +20 -1
  89. data/lib/rubocop/cop/style/semicolon.rb +20 -5
  90. data/lib/rubocop/cop/style/single_line_methods.rb +3 -3
  91. data/lib/rubocop/cop/style/sole_nested_conditional.rb +30 -1
  92. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -1
  93. data/lib/rubocop/cop/style/string_concatenation.rb +17 -13
  94. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  95. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +45 -0
  96. data/lib/rubocop/cop/style/unless_else.rb +10 -9
  97. data/lib/rubocop/cop/utils/format_string.rb +10 -0
  98. data/lib/rubocop/cop/variable_force/variable.rb +1 -1
  99. data/lib/rubocop/cop/variable_force.rb +25 -8
  100. data/lib/rubocop/cops_documentation_generator.rb +5 -4
  101. data/lib/rubocop/formatter/disabled_config_formatter.rb +18 -5
  102. data/lib/rubocop/formatter/markdown_formatter.rb +1 -0
  103. data/lib/rubocop/formatter/pacman_formatter.rb +1 -0
  104. data/lib/rubocop/lsp/diagnostic.rb +21 -20
  105. data/lib/rubocop/lsp/routes.rb +65 -9
  106. data/lib/rubocop/lsp/runtime.rb +2 -2
  107. data/lib/rubocop/lsp/server.rb +2 -2
  108. data/lib/rubocop/lsp/stdin_runner.rb +0 -16
  109. data/lib/rubocop/result_cache.rb +14 -12
  110. data/lib/rubocop/runner.rb +6 -4
  111. data/lib/rubocop/target_finder.rb +9 -9
  112. data/lib/rubocop/target_ruby.rb +10 -1
  113. data/lib/rubocop/version.rb +1 -1
  114. data/lib/rubocop.rb +3 -0
  115. data/lib/ruby_lsp/rubocop/addon.rb +23 -8
  116. data/lib/ruby_lsp/rubocop/runtime_adapter.rb +49 -15
  117. metadata +9 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b840814034fbb98e67e3bb60014f0f00f9387148ab85b8b66f3a7ca711efdd2
4
- data.tar.gz: b223e62eeeef5effd425654bf869ea22935beb8955df6e6fb22f0ba2a623d0f3
3
+ metadata.gz: d82a03998b60107aedc6589884c7edbafdab71312f8328edf17eed92ef26980b
4
+ data.tar.gz: 2ac88da54e9ad3d1b1d51f72391447749b440a8c90602a48b50d35d7767727d8
5
5
  SHA512:
6
- metadata.gz: 83f46c7462c956b9a37e61feb329b3dfdb96e631cab64ffa3d1485bdc2d36a3585dacc17fc0b546ca98a0ad1014e1818eabf328a367654ad0151eaea3eea7369
7
- data.tar.gz: d7cd91419c2ff881ef14b5f4406c9b87e555d2948c2c20b98bf02e6007e44b3d20b0aa73f3b91a595c5613164e551ba5f728e0852d084d04fe37312a65fa2b96
6
+ metadata.gz: cde998922977693d608c6a80a4afd9e87605e9f6b673babd8c70824b79602134116f9c090bc222e97ec6dc46254e0a85d7329ebad1aa50465ea8cc36d4636814
7
+ data.tar.gz: ed82346ea82e517fb1381653cc9a2a49ca1a5235df71491996e7b68d3000d137cd1c8ba69819cbd5d40d98440702757008ff69157d1dc7c13c8c6cf9345b5ac3
data/README.md CHANGED
@@ -6,8 +6,6 @@
6
6
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
7
7
  [![Gem Version](https://badge.fury.io/rb/rubocop.svg)](https://badge.fury.io/rb/rubocop)
8
8
  [![CI](https://github.com/rubocop/rubocop/actions/workflows/rubocop.yml/badge.svg)](https://github.com/rubocop/rubocop/actions/workflows/rubocop.yml)
9
- [![Test Coverage](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/test_coverage)](https://codeclimate.com/github/rubocop/rubocop/test_coverage)
10
- [![Maintainability](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/maintainability)](https://codeclimate.com/github/rubocop/rubocop/maintainability)
11
9
  [![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?sanitize=true)](https://discord.gg/wJjWvGRDmm)
12
10
 
13
11
  > Role models are important. <br/>
@@ -53,7 +51,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
53
51
  in your `Gemfile`:
54
52
 
55
53
  ```rb
56
- gem 'rubocop', '~> 1.78', require: false
54
+ gem 'rubocop', '~> 1.81', require: false
57
55
  ```
58
56
 
59
57
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
data/config/default.yml CHANGED
@@ -275,7 +275,7 @@ Gemspec/AddRuntimeDependency:
275
275
  Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
276
276
  StyleGuide: '#add_dependency_vs_add_runtime_dependency'
277
277
  References:
278
- - https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
278
+ - https://github.com/ruby/rubygems/issues/7799#issuecomment-2192720316
279
279
  Enabled: pending
280
280
  VersionAdded: '1.65'
281
281
  Include:
@@ -378,7 +378,7 @@ Gemspec/RubyVersionGlobalsUsage:
378
378
  #################### Layout ###########################
379
379
 
380
380
  Layout/AccessModifierIndentation:
381
- Description: Check indentation of private/protected visibility modifiers.
381
+ Description: Checks indentation of private/protected visibility modifiers.
382
382
  StyleGuide: '#indent-public-private-protected'
383
383
  Enabled: true
384
384
  VersionAdded: '0.49'
@@ -638,6 +638,12 @@ Layout/EmptyLines:
638
638
  Enabled: true
639
639
  VersionAdded: '0.49'
640
640
 
641
+ Layout/EmptyLinesAfterModuleInclusion:
642
+ Description: 'Keeps track of empty lines after module inclusion methods.'
643
+ StyleGuide: '#empty-lines-after-module-inclusion'
644
+ Enabled: pending
645
+ VersionAdded: '1.79'
646
+
641
647
  Layout/EmptyLinesAroundAccessModifier:
642
648
  Description: "Keep blank lines around access modifiers."
643
649
  StyleGuide: '#empty-lines-around-access-modifier'
@@ -1051,7 +1057,7 @@ Layout/LeadingCommentSpace:
1051
1057
  AllowSteepAnnotation: false
1052
1058
 
1053
1059
  Layout/LeadingEmptyLines:
1054
- Description: Check for unnecessary blank lines at the beginning of a file.
1060
+ Description: Checks for unnecessary blank lines at the beginning of a file.
1055
1061
  Enabled: true
1056
1062
  VersionAdded: '0.57'
1057
1063
  VersionChanged: '0.77'
@@ -1141,7 +1147,7 @@ Layout/MultilineArrayLineBreaks:
1141
1147
  AllowMultilineFinalElement: false
1142
1148
 
1143
1149
  Layout/MultilineAssignmentLayout:
1144
- Description: 'Check for a newline after the assignment operator in multi-line assignments.'
1150
+ Description: 'Checks for a newline after the assignment operator in multi-line assignments.'
1145
1151
  StyleGuide: '#indent-conditional-assignment'
1146
1152
  Enabled: false
1147
1153
  VersionAdded: '0.49'
@@ -1655,7 +1661,7 @@ Lint/BinaryOperatorWithIdenticalOperands:
1655
1661
  VersionChanged: '1.69'
1656
1662
 
1657
1663
  Lint/BooleanSymbol:
1658
- Description: 'Check for `:true` and `:false` symbols.'
1664
+ Description: 'Checks for `:true` and `:false` symbols.'
1659
1665
  Enabled: true
1660
1666
  SafeAutoCorrect: false
1661
1667
  VersionAdded: '0.50'
@@ -1688,7 +1694,7 @@ Lint/ConstantReassignment:
1688
1694
  VersionAdded: '1.70'
1689
1695
 
1690
1696
  Lint/ConstantResolution:
1691
- Description: 'Check that constants are fully qualified with `::`.'
1697
+ Description: 'Checks that constants are fully qualified with `::`.'
1692
1698
  Enabled: false
1693
1699
  VersionAdded: '0.86'
1694
1700
  # Restrict this cop to only looking at certain names
@@ -1702,7 +1708,7 @@ Lint/CopDirectiveSyntax:
1702
1708
  VersionAdded: '1.72'
1703
1709
 
1704
1710
  Lint/Debugger:
1705
- Description: 'Check for debugger calls.'
1711
+ Description: 'Checks for debugger calls.'
1706
1712
  Enabled: true
1707
1713
  VersionAdded: '0.14'
1708
1714
  VersionChanged: '1.63'
@@ -1753,7 +1759,7 @@ Lint/Debugger:
1753
1759
  - debug/start
1754
1760
 
1755
1761
  Lint/DeprecatedClassMethods:
1756
- Description: 'Check for deprecated class method calls.'
1762
+ Description: 'Checks for deprecated class method calls.'
1757
1763
  Enabled: true
1758
1764
  VersionAdded: '0.19'
1759
1765
 
@@ -1827,13 +1833,13 @@ Lint/DuplicateElsifCondition:
1827
1833
  VersionAdded: '0.88'
1828
1834
 
1829
1835
  Lint/DuplicateHashKey:
1830
- Description: 'Check for duplicate keys in hash literals.'
1836
+ Description: 'Checks for duplicate keys in hash literals.'
1831
1837
  Enabled: true
1832
1838
  VersionAdded: '0.34'
1833
1839
  VersionChanged: '0.77'
1834
1840
 
1835
1841
  Lint/DuplicateMagicComment:
1836
- Description: 'Check for duplicated magic comments.'
1842
+ Description: 'Checks for duplicated magic comments.'
1837
1843
  Enabled: pending
1838
1844
  VersionAdded: '1.37'
1839
1845
 
@@ -1843,7 +1849,7 @@ Lint/DuplicateMatchPattern:
1843
1849
  VersionAdded: '1.50'
1844
1850
 
1845
1851
  Lint/DuplicateMethods:
1846
- Description: 'Check for duplicate method definitions.'
1852
+ Description: 'Checks for duplicate method definitions.'
1847
1853
  Enabled: true
1848
1854
  VersionAdded: '0.29'
1849
1855
 
@@ -1853,7 +1859,7 @@ Lint/DuplicateRegexpCharacterClassElement:
1853
1859
  VersionAdded: '1.1'
1854
1860
 
1855
1861
  Lint/DuplicateRequire:
1856
- Description: 'Check for duplicate `require`s and `require_relative`s.'
1862
+ Description: 'Checks for duplicate `require`s and `require_relative`s.'
1857
1863
  Enabled: true
1858
1864
  SafeAutoCorrect: false
1859
1865
  VersionAdded: '0.90'
@@ -1870,12 +1876,12 @@ Lint/DuplicateSetElement:
1870
1876
  VersionAdded: '1.67'
1871
1877
 
1872
1878
  Lint/EachWithObjectArgument:
1873
- Description: 'Check for immutable argument given to each_with_object.'
1879
+ Description: 'Checks for immutable argument given to each_with_object.'
1874
1880
  Enabled: true
1875
1881
  VersionAdded: '0.31'
1876
1882
 
1877
1883
  Lint/ElseLayout:
1878
- Description: 'Check for odd code arrangement in an else block.'
1884
+ Description: 'Checks for odd code arrangement in an else block.'
1879
1885
  Enabled: true
1880
1886
  VersionAdded: '0.17'
1881
1887
  VersionChanged: '1.2'
@@ -2278,6 +2284,7 @@ Lint/RedundantSafeNavigation:
2278
2284
  Description: 'Checks for redundant safe navigation calls.'
2279
2285
  Enabled: true
2280
2286
  VersionAdded: '0.93'
2287
+ VersionChanged: '1.79'
2281
2288
  AllowedMethods:
2282
2289
  - instance_of?
2283
2290
  - kind_of?
@@ -2285,6 +2292,12 @@ Lint/RedundantSafeNavigation:
2285
2292
  - eql?
2286
2293
  - respond_to?
2287
2294
  - equal?
2295
+ InferNonNilReceiver: false
2296
+ AdditionalNilMethods:
2297
+ - present?
2298
+ - blank?
2299
+ - try
2300
+ - try!
2288
2301
  Safe: false
2289
2302
 
2290
2303
  Lint/RedundantSplatExpansion:
@@ -2817,7 +2830,7 @@ Migration/DepartmentName:
2817
2830
  #################### Naming ##############################
2818
2831
 
2819
2832
  Naming/AccessorMethodName:
2820
- Description: Check the naming of accessor methods for get_/set_.
2833
+ Description: Checks the naming of accessor methods for get_/set_.
2821
2834
  StyleGuide: '#accessor_mutator_method_names'
2822
2835
  Enabled: true
2823
2836
  VersionAdded: '0.50'
@@ -3194,6 +3207,7 @@ Security/JSONLoad:
3194
3207
  security issues. See reference for more information.
3195
3208
  References:
3196
3209
  - 'https://ruby-doc.org/stdlib-2.7.0/libdoc/json/rdoc/JSON.html#method-i-load'
3210
+ - 'https://bugs.ruby-lang.org/issues/19528'
3197
3211
  Enabled: true
3198
3212
  VersionAdded: '0.43'
3199
3213
  VersionChanged: '1.22'
@@ -3328,6 +3342,12 @@ Style/ArrayIntersect:
3328
3342
  Safe: false
3329
3343
  VersionAdded: '1.40'
3330
3344
 
3345
+ Style/ArrayIntersectWithSingleElement:
3346
+ Description: 'Use `include?(element)` instead of `intersect?([element])`.'
3347
+ Enabled: 'pending'
3348
+ Safe: false
3349
+ VersionAdded: '1.81'
3350
+
3331
3351
  Style/ArrayJoin:
3332
3352
  Description: 'Use Array#join instead of Array#*.'
3333
3353
  StyleGuide: '#array-join'
@@ -4224,7 +4244,7 @@ Style/GlobalVars:
4224
4244
  AllowedVariables: []
4225
4245
 
4226
4246
  Style/GuardClause:
4227
- Description: 'Check for conditionals that can be replaced with guard clauses.'
4247
+ Description: 'Checks for conditionals that can be replaced with guard clauses.'
4228
4248
  StyleGuide: '#no-nested-conditionals'
4229
4249
  Enabled: true
4230
4250
  VersionAdded: '0.20'
@@ -4486,7 +4506,7 @@ Style/IpAddresses:
4486
4506
  - '**/*.gemspec'
4487
4507
 
4488
4508
  Style/ItAssignment:
4489
- Description: 'Checks for assignment to `it` inside a block.'
4509
+ Description: 'Checks for local variables and method parameters named `it`.'
4490
4510
  Enabled: pending
4491
4511
  VersionAdded: '1.70'
4492
4512
 
@@ -4533,8 +4553,9 @@ Style/LambdaCall:
4533
4553
  Description: 'Use lambda.call(...) instead of lambda.(...).'
4534
4554
  StyleGuide: '#proc-call'
4535
4555
  Enabled: true
4556
+ AutoCorrect: contextual
4536
4557
  VersionAdded: '0.13'
4537
- VersionChanged: '0.14'
4558
+ VersionChanged: '<<next>>'
4538
4559
  EnforcedStyle: call
4539
4560
  SupportedStyles:
4540
4561
  - call
@@ -5187,7 +5208,7 @@ Style/RandomWithOffset:
5187
5208
  VersionAdded: '0.52'
5188
5209
 
5189
5210
  Style/RedundantArgument:
5190
- Description: 'Check for a redundant argument passed to certain methods.'
5211
+ Description: 'Checks for a redundant argument passed to certain methods.'
5191
5212
  Enabled: pending
5192
5213
  Safe: false
5193
5214
  VersionAdded: '1.4'
@@ -5348,7 +5369,7 @@ Style/RedundantInterpolationUnfreeze:
5348
5369
  VersionAdded: '1.66'
5349
5370
 
5350
5371
  Style/RedundantLineContinuation:
5351
- Description: 'Check for redundant line continuation.'
5372
+ Description: 'Checks for redundant line continuation.'
5352
5373
  Enabled: pending
5353
5374
  VersionAdded: '1.49'
5354
5375
 
@@ -5642,7 +5663,7 @@ Style/SpecialGlobalVars:
5642
5663
  - use_builtin_english_names
5643
5664
 
5644
5665
  Style/StabbyLambdaParentheses:
5645
- Description: 'Check for the usage of parentheses around stabby lambda arguments.'
5666
+ Description: 'Checks for the usage of parentheses around stabby lambda arguments.'
5646
5667
  StyleGuide: '#stabby-lambda-with-args'
5647
5668
  Enabled: true
5648
5669
  VersionAdded: '0.35'
@@ -5831,10 +5852,14 @@ Style/TrailingCommaInArguments:
5831
5852
  # parenthesized method calls where each argument is on its own line.
5832
5853
  # If `consistent_comma`, the cop requires a comma after the last argument,
5833
5854
  # for all parenthesized method calls with arguments.
5855
+ # If `diff_comma`, the cop requires a comma after the last argument, but only
5856
+ # when that argument is followed by an immediate newline, even if
5857
+ # there is an inline comment.
5834
5858
  EnforcedStyleForMultiline: no_comma
5835
5859
  SupportedStylesForMultiline:
5836
5860
  - comma
5837
5861
  - consistent_comma
5862
+ - diff_comma
5838
5863
  - no_comma
5839
5864
 
5840
5865
  Style/TrailingCommaInArrayLiteral:
data/exe/rubocop CHANGED
@@ -12,13 +12,6 @@ if RuboCop::Server.running?
12
12
  exit_status = RuboCop::Server::ClientCommand::Exec.new.run
13
13
  else
14
14
  require 'rubocop'
15
-
16
- cli = RuboCop::CLI.new
17
-
18
- time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
19
- exit_status = cli.run
20
- elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_start
21
-
22
- puts "Finished in #{elapsed_time} seconds" if cli.options[:debug] || cli.options[:display_time]
15
+ exit_status = RuboCop::CLI.new.run
23
16
  end
24
17
  exit exit_status
@@ -83,7 +83,7 @@ module RuboCop
83
83
  execute_runner
84
84
  @options.delete(:only)
85
85
  @config_store = ConfigStore.new
86
- @config_store.options_config = @options[:config] if @options[:config]
86
+ @config_store.apply_options!(@options)
87
87
  # Save the todo configuration of the LineLength cop.
88
88
  File.read(AUTO_GENERATED_FILE).lines.drop_while { |line| line.start_with?('#') }.join
89
89
  end
@@ -99,7 +99,7 @@ module RuboCop
99
99
 
100
100
  def reset_config_and_auto_gen_file
101
101
  @config_store = ConfigStore.new
102
- @config_store.options_config = @options[:config] if @options[:config]
102
+ @config_store.apply_options!(@options)
103
103
  File.open(AUTO_GENERATED_FILE, 'w') {} # create or truncate if exists
104
104
  add_inheritance_from_auto_generated_file(@options[:config])
105
105
  end
data/lib/rubocop/cli.rb CHANGED
@@ -37,6 +37,8 @@ module RuboCop
37
37
  #
38
38
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
39
39
  def run(args = ARGV)
40
+ time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
41
+
40
42
  @options, paths = Options.new.parse(args)
41
43
  @env = Environment.new(@options, @config_store, paths)
42
44
 
@@ -72,6 +74,9 @@ module RuboCop
72
74
  warn e.message
73
75
  warn e.backtrace
74
76
  STATUS_ERROR
77
+ ensure
78
+ elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_start
79
+ puts "Finished in #{elapsed_time} seconds" if @options[:debug] || @options[:display_time]
75
80
  end
76
81
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
77
82
 
@@ -159,8 +164,7 @@ module RuboCop
159
164
  set_options_to_pending_cops_reporter
160
165
  handle_editor_mode
161
166
 
162
- @config_store.options_config = @options[:config] if @options[:config]
163
- @config_store.force_default_config! if @options[:force_default_config]
167
+ @config_store.apply_options!(@options)
164
168
 
165
169
  handle_exiting_options
166
170
 
@@ -75,7 +75,9 @@ module RuboCop
75
75
 
76
76
  puts "configuration from #{absolute_path}" if debug?
77
77
 
78
- raise(TypeError, "Malformed configuration in #{absolute_path}") unless hash.is_a?(Hash)
78
+ unless hash.is_a?(Hash)
79
+ raise(ValidationError, "Malformed configuration in #{absolute_path}")
80
+ end
79
81
 
80
82
  hash
81
83
  end
@@ -25,6 +25,11 @@ module RuboCop
25
25
  @validated = true
26
26
  end
27
27
 
28
+ def apply_options!(options)
29
+ self.options_config = options[:config] if options[:config]
30
+ force_default_config! if options[:force_default_config]
31
+ end
32
+
28
33
  def options_config=(options_config)
29
34
  loaded_config = ConfigLoader.load_file(options_config)
30
35
  @options_config = ConfigLoader.merge_with_default(loaded_config, options_config)
@@ -35,8 +35,8 @@ module RuboCop
35
35
  # `false` is the same as `disabled` for backward compatibility.
36
36
  return false if ['disabled', false].include?(cop_config['AutoCorrect'])
37
37
 
38
- # When LSP is enabled, it is considered as editing source code,
39
- # and autocorrection with `AutoCorrect: contextual` will not be performed.
38
+ # When LSP is enabled or the `--editor-mode` option is on, it is considered as editing
39
+ # source code, and autocorrection with `AutoCorrect: contextual` will not be performed.
40
40
  return false if contextual_autocorrect? && LSP.enabled?
41
41
 
42
42
  # :safe_autocorrect is a derived option based on several command-line
@@ -94,7 +94,7 @@ module RuboCop
94
94
  end
95
95
 
96
96
  def surrounding_heredoc?(node)
97
- node.type?(:str, :dstr, :xstr) && node.heredoc?
97
+ node.any_str_type? && node.heredoc?
98
98
  end
99
99
 
100
100
  def heredoc_range(node)
@@ -106,7 +106,7 @@ module RuboCop
106
106
  end
107
107
 
108
108
  def string_continuation?(node)
109
- node.type?(:str, :dstr, :xstr) && node.source.match?(/\\\s*$/)
109
+ node.any_str_type? && node.source.match?(/\\\s*$/)
110
110
  end
111
111
 
112
112
  def multiline_string?(node)
@@ -29,10 +29,13 @@ module RuboCop
29
29
  def align_end(corrector, processed_source, node, align_to)
30
30
  @processed_source = processed_source
31
31
  whitespace = whitespace_range(node)
32
- return false unless whitespace.source.strip.empty?
33
-
34
32
  column = alignment_column(align_to)
35
- corrector.replace(whitespace, ' ' * column)
33
+
34
+ if whitespace.source.strip.empty?
35
+ corrector.replace(whitespace, ' ' * column)
36
+ else
37
+ corrector.insert_after(whitespace, "\n#{' ' * column}")
38
+ end
36
39
  end
37
40
 
38
41
  private
@@ -54,7 +57,7 @@ module RuboCop
54
57
  def inside_string_ranges(node)
55
58
  return [] unless node.is_a?(Parser::AST::Node)
56
59
 
57
- node.each_node(:str, :dstr, :xstr).filter_map { |n| inside_string_range(n) }
60
+ node.each_node(:any_str).filter_map { |n| inside_string_range(n) }
58
61
  end
59
62
 
60
63
  def inside_string_range(node)
@@ -6,7 +6,7 @@ module RuboCop
6
6
  class ForToEachCorrector
7
7
  extend NodePattern::Macros
8
8
 
9
- CORRECTION = '%<collection>s.each do |%<argument>s|'
9
+ CORRECTION = '%<collection>s%<dot>seach do |%<argument>s|'
10
10
 
11
11
  def initialize(for_node)
12
12
  @for_node = for_node
@@ -25,7 +25,12 @@ module RuboCop
25
25
  attr_reader :for_node, :variable_node, :collection_node
26
26
 
27
27
  def correction
28
- format(CORRECTION, collection: collection_source, argument: variable_node.source)
28
+ format(
29
+ CORRECTION,
30
+ collection: collection_source,
31
+ dot: collection_node.csend_type? ? '&.' : '.',
32
+ argument: variable_node.source
33
+ )
29
34
  end
30
35
 
31
36
  def collection_source
@@ -30,6 +30,8 @@ module RuboCop
30
30
  any_block: %i[block numblock itblock],
31
31
  any_def: %i[def defs],
32
32
  any_match_pattern: %i[match_pattern match_pattern_p],
33
+ any_str: %i[str dstr xstr],
34
+ any_sym: %i[sym dsym],
33
35
  argument: %i[arg optarg restarg kwarg kwoptarg kwrestarg blockarg forward_arg shadowarg],
34
36
  boolean: %i[true false],
35
37
  call: %i[send csend],
@@ -210,7 +212,7 @@ module RuboCop
210
212
  # A heredoc can be a `dstr` without interpolation, but if there is interpolation
211
213
  # there'll be a `begin` node, in which case, we cannot evaluate the pattern.
212
214
  def acceptable_heredoc?(node)
213
- node.type?(:str, :dstr) && node.heredoc? && node.each_child_node(:begin).none?
215
+ node.any_str_type? && node.heredoc? && node.each_child_node(:begin).none?
214
216
  end
215
217
 
216
218
  def process_pattern(pattern_node)
@@ -66,8 +66,9 @@ module RuboCop
66
66
  end
67
67
 
68
68
  def autocorrect_to_explicit_predicate(corrector, node, group_name)
69
- corrector.replace(node.selector, "#{group_name}_type?")
70
- corrector.remove(arguments_range(node))
69
+ range = node.loc.selector.begin.join(node.source_range.end)
70
+
71
+ corrector.replace(range, "#{group_name}_type?")
71
72
  end
72
73
 
73
74
  def autocorrect_keep_method(corrector, symbol_args, group_name, group_types)
@@ -76,7 +76,7 @@ module RuboCop
76
76
  end
77
77
 
78
78
  def on_send(node) # rubocop:disable InternalAffairs/OnSendWithoutOnCSend
79
- new_identifier = node.first_argument
79
+ return unless (new_identifier = node.first_argument)
80
80
  return unless new_identifier.basic_literal?
81
81
 
82
82
  new_identifier = new_identifier.value
@@ -3,7 +3,7 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module InternalAffairs
6
- # Check for useless `RESTRICT_ON_SEND`.
6
+ # Checks for useless `RESTRICT_ON_SEND`.
7
7
  #
8
8
  # @example
9
9
  # # bad
@@ -357,7 +357,7 @@ module RuboCop
357
357
  end
358
358
 
359
359
  def find_heredoc(node)
360
- node.each_node(:str, :dstr, :xstr).find(&:heredoc?)
360
+ node.each_node(:any_str).find(&:heredoc?)
361
361
  end
362
362
 
363
363
  def buffer
@@ -120,7 +120,7 @@ module RuboCop
120
120
  end
121
121
 
122
122
  def heredoc?(node)
123
- node.type?(:str, :dstr) && node.heredoc?
123
+ node.any_str_type? && node.heredoc?
124
124
  end
125
125
 
126
126
  def end_range(node)
@@ -76,28 +76,40 @@ module RuboCop
76
76
  # # good
77
77
  # class ErrorA < BaseError; end
78
78
  # class ErrorB < BaseError; end
79
- # class ErrorC < BaseError; end
80
79
  #
81
80
  # # good
82
81
  # class ErrorA < BaseError; end
83
82
  #
84
83
  # class ErrorB < BaseError; end
85
84
  #
86
- # class ErrorC < BaseError; end
85
+ # # good - DefLikeMacros: [memoize]
86
+ # memoize :attribute_a
87
+ # memoize :attribute_b
88
+ #
89
+ # # good
90
+ # memoize :attribute_a
91
+ #
92
+ # memoize :attribute_b
87
93
  #
88
94
  # @example AllowAdjacentOneLineDefs: false
89
95
  #
90
96
  # # bad
91
97
  # class ErrorA < BaseError; end
92
98
  # class ErrorB < BaseError; end
93
- # class ErrorC < BaseError; end
94
99
  #
95
100
  # # good
96
101
  # class ErrorA < BaseError; end
97
102
  #
98
103
  # class ErrorB < BaseError; end
99
104
  #
100
- # class ErrorC < BaseError; end
105
+ # # bad - DefLikeMacros: [memoize]
106
+ # memoize :attribute_a
107
+ # memoize :attribute_b
108
+ #
109
+ # # good
110
+ # memoize :attribute_a
111
+ #
112
+ # memoize :attribute_b
101
113
  #
102
114
  class EmptyLineBetweenDefs < Base
103
115
  include RangeHelp
@@ -158,6 +170,8 @@ module RuboCop
158
170
  def def_location(correction_node)
159
171
  if correction_node.any_block_type?
160
172
  correction_node.source_range.join(correction_node.children.first.source_range)
173
+ elsif correction_node.send_type?
174
+ correction_node.source_range
161
175
  else
162
176
  correction_node.loc.keyword.join(correction_node.loc.name)
163
177
  end
@@ -175,8 +189,14 @@ module RuboCop
175
189
  end
176
190
 
177
191
  def macro_candidate?(node)
178
- node.any_block_type? && node.children.first.macro? &&
179
- empty_line_between_macros.include?(node.children.first.method_name)
192
+ macro_candidate = if node.any_block_type?
193
+ node.send_node
194
+ elsif node.send_type?
195
+ node
196
+ end
197
+ return false unless macro_candidate
198
+
199
+ macro_candidate.macro? && empty_line_between_macros.include?(macro_candidate.method_name)
180
200
  end
181
201
 
182
202
  def method_candidate?(node)
@@ -240,7 +260,9 @@ module RuboCop
240
260
  end
241
261
 
242
262
  def def_start(node)
243
- if node.any_block_type? && node.children.first.send_type?
263
+ node = node.send_node if node.any_block_type?
264
+
265
+ if node.send_type?
244
266
  node.source_range.line
245
267
  else
246
268
  node.loc.keyword.line
@@ -252,11 +274,7 @@ module RuboCop
252
274
  end
253
275
 
254
276
  def end_loc(node)
255
- if node.any_def_type? && node.endless?
256
- node.source_range.end
257
- else
258
- node.loc.end
259
- end
277
+ node.source_range.end
260
278
  end
261
279
 
262
280
  def autocorrect_remove_lines(corrector, newline_pos, count)