rubocop 0.81.0 → 0.82.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +59 -13
  4. data/lib/rubocop.rb +4 -2
  5. data/lib/rubocop/ast/node.rb +1 -1
  6. data/lib/rubocop/ast/node/array_node.rb +13 -0
  7. data/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +8 -0
  8. data/lib/rubocop/cli.rb +10 -4
  9. data/lib/rubocop/config.rb +9 -1
  10. data/lib/rubocop/config_loader.rb +24 -15
  11. data/lib/rubocop/config_loader_resolver.rb +1 -1
  12. data/lib/rubocop/config_obsoletion.rb +1 -0
  13. data/lib/rubocop/config_validator.rb +16 -0
  14. data/lib/rubocop/cop/badge.rb +5 -5
  15. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +1 -1
  16. data/lib/rubocop/cop/corrector.rb +48 -24
  17. data/lib/rubocop/cop/correctors/alignment_corrector.rb +2 -2
  18. data/lib/rubocop/cop/correctors/condition_corrector.rb +1 -2
  19. data/lib/rubocop/cop/correctors/empty_line_corrector.rb +1 -1
  20. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +3 -3
  21. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
  22. data/lib/rubocop/cop/correctors/percent_literal_corrector.rb +1 -1
  23. data/lib/rubocop/cop/correctors/string_literal_corrector.rb +2 -2
  24. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -1
  25. data/lib/rubocop/cop/layout/dot_position.rb +1 -1
  26. data/lib/rubocop/cop/layout/end_of_line.rb +2 -2
  27. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +16 -10
  28. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +1 -1
  29. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +2 -2
  30. data/lib/rubocop/cop/layout/heredoc_indentation.rb +2 -2
  31. data/lib/rubocop/cop/layout/{tab.rb → indentation_style.rb} +48 -6
  32. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  33. data/lib/rubocop/cop/layout/line_length.rb +2 -2
  34. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  35. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +3 -3
  36. data/lib/rubocop/cop/layout/space_around_method_call_operator.rb +133 -0
  37. data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
  38. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +1 -1
  39. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +2 -2
  40. data/lib/rubocop/cop/layout/space_inside_range_literal.rb +2 -2
  41. data/lib/rubocop/cop/lint/boolean_symbol.rb +2 -2
  42. data/lib/rubocop/cop/lint/debugger.rb +1 -1
  43. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
  44. data/lib/rubocop/cop/lint/inherit_exception.rb +1 -1
  45. data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
  46. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +1 -1
  47. data/lib/rubocop/cop/lint/multiple_comparison.rb +1 -1
  48. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +2 -2
  49. data/lib/rubocop/cop/lint/number_conversion.rb +1 -1
  50. data/lib/rubocop/cop/lint/percent_string_array.rb +2 -2
  51. data/lib/rubocop/cop/lint/raise_exception.rb +42 -6
  52. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +1 -1
  53. data/lib/rubocop/cop/lint/unified_integer.rb +0 -2
  54. data/lib/rubocop/cop/lint/uri_regexp.rb +4 -4
  55. data/lib/rubocop/cop/mixin/hash_transform_method.rb +1 -1
  56. data/lib/rubocop/cop/mixin/line_length_help.rb +1 -1
  57. data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -3
  58. data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -1
  59. data/lib/rubocop/cop/naming/class_and_module_camel_case.rb +1 -1
  60. data/lib/rubocop/cop/naming/constant_name.rb +2 -1
  61. data/lib/rubocop/cop/naming/heredoc_delimiter_naming.rb +1 -1
  62. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +1 -1
  63. data/lib/rubocop/cop/registry.rb +11 -4
  64. data/lib/rubocop/cop/style/alias.rb +4 -4
  65. data/lib/rubocop/cop/style/and_or.rb +5 -6
  66. data/lib/rubocop/cop/style/array_join.rb +1 -1
  67. data/lib/rubocop/cop/style/case_equality.rb +24 -1
  68. data/lib/rubocop/cop/style/character_literal.rb +2 -2
  69. data/lib/rubocop/cop/style/conditional_assignment.rb +8 -8
  70. data/lib/rubocop/cop/style/copyright.rb +1 -1
  71. data/lib/rubocop/cop/style/dir.rb +1 -1
  72. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -0
  73. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +1 -1
  74. data/lib/rubocop/cop/style/each_for_simple_loop.rb +1 -1
  75. data/lib/rubocop/cop/style/each_with_object.rb +3 -3
  76. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  77. data/lib/rubocop/cop/style/even_odd.rb +1 -1
  78. data/lib/rubocop/cop/style/expand_path_arguments.rb +3 -3
  79. data/lib/rubocop/cop/style/exponential_notation.rb +119 -0
  80. data/lib/rubocop/cop/style/format_string.rb +2 -2
  81. data/lib/rubocop/cop/style/hash_each_methods.rb +3 -3
  82. data/lib/rubocop/cop/style/hash_syntax.rb +3 -5
  83. data/lib/rubocop/cop/style/hash_transform_values.rb +0 -3
  84. data/lib/rubocop/cop/style/if_unless_modifier.rb +23 -3
  85. data/lib/rubocop/cop/style/lambda.rb +2 -2
  86. data/lib/rubocop/cop/style/lambda_call.rb +2 -2
  87. data/lib/rubocop/cop/style/mixin_grouping.rb +1 -1
  88. data/lib/rubocop/cop/style/module_function.rb +2 -2
  89. data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
  90. data/lib/rubocop/cop/style/multiline_memoization.rb +1 -1
  91. data/lib/rubocop/cop/style/mutable_constant.rb +2 -4
  92. data/lib/rubocop/cop/style/next.rb +2 -2
  93. data/lib/rubocop/cop/style/nil_comparison.rb +1 -1
  94. data/lib/rubocop/cop/style/non_nil_check.rb +4 -4
  95. data/lib/rubocop/cop/style/not.rb +1 -1
  96. data/lib/rubocop/cop/style/numeric_literal_prefix.rb +1 -1
  97. data/lib/rubocop/cop/style/numeric_literals.rb +1 -1
  98. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  99. data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
  100. data/lib/rubocop/cop/style/or_assignment.rb +1 -1
  101. data/lib/rubocop/cop/style/percent_q_literals.rb +1 -1
  102. data/lib/rubocop/cop/style/perl_backrefs.rb +2 -2
  103. data/lib/rubocop/cop/style/proc.rb +1 -1
  104. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  105. data/lib/rubocop/cop/style/random_with_offset.rb +3 -3
  106. data/lib/rubocop/cop/style/redundant_condition.rb +3 -4
  107. data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
  108. data/lib/rubocop/cop/style/redundant_exception.rb +3 -3
  109. data/lib/rubocop/cop/style/redundant_interpolation.rb +2 -2
  110. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -2
  111. data/lib/rubocop/cop/style/redundant_return.rb +5 -7
  112. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  113. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  114. data/lib/rubocop/cop/style/return_nil.rb +1 -1
  115. data/lib/rubocop/cop/style/safe_navigation.rb +1 -1
  116. data/lib/rubocop/cop/style/self_assignment.rb +1 -1
  117. data/lib/rubocop/cop/style/special_global_vars.rb +1 -1
  118. data/lib/rubocop/cop/style/stabby_lambda_parentheses.rb +1 -4
  119. data/lib/rubocop/cop/style/string_hash_keys.rb +1 -1
  120. data/lib/rubocop/cop/style/symbol_array.rb +1 -1
  121. data/lib/rubocop/cop/style/symbol_literal.rb +2 -2
  122. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -2
  123. data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +2 -1
  124. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +3 -0
  125. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  126. data/lib/rubocop/cop/style/unpack_first.rb +0 -4
  127. data/lib/rubocop/cop/style/variable_interpolation.rb +1 -1
  128. data/lib/rubocop/cop/style/while_until_modifier.rb +1 -1
  129. data/lib/rubocop/cop/style/word_array.rb +1 -1
  130. data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -1
  131. data/lib/rubocop/formatter/formatter_set.rb +0 -1
  132. data/lib/rubocop/formatter/pacman_formatter.rb +1 -1
  133. data/lib/rubocop/options.rb +7 -1
  134. data/lib/rubocop/processed_source.rb +0 -3
  135. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  136. data/lib/rubocop/rspec/expect_offense.rb +1 -1
  137. data/lib/rubocop/rspec/shared_contexts.rb +0 -4
  138. data/lib/rubocop/runner.rb +1 -1
  139. data/lib/rubocop/target_ruby.rb +2 -2
  140. data/lib/rubocop/version.rb +1 -1
  141. metadata +7 -5
  142. data/lib/rubocop/formatter/disabled_lines_formatter.rb +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af0dab74354064816d5756cb5a49ab7160c444292ef32e9ee7980dff8a18110f
4
- data.tar.gz: 96288aa5f77f19813ef7cac495f7c86d912f3be28da021b01d30136a2ef28f99
3
+ metadata.gz: 9e04c6e897293df4ef1c7bf05a0c0077512e2cba797a7caee484b1c08a7300ad
4
+ data.tar.gz: 92fbc98b5068e5c30bf83d058e3cfe774a1a65cc90608027ff8d6624c8c2910c
5
5
  SHA512:
6
- metadata.gz: 015244a9c6aff6e2d5640e68b286127944418221bb8c76db04273c5c35b5bc41e03bf7d85c44a3b630a0dd8a24f5a4531ddaf61adb0b75a0b39e2e6c2e08d8cf
7
- data.tar.gz: 8e209ee81ebf1d5a3215292c7d7eddabaacb64e0fa1da7935372495ad13e5bdd896b7fd27fde25fc0e8ffaa7d1b0873f47c40f505d4828e23a52f0ca2ee847e6
6
+ metadata.gz: cacf128617d233de65c2061d0300d345357840b151f65c78a2463fa23830115dcaa667cc2110ef39cacd14d957e626fc3fb4857443e40a1ab0fb485ce9cbfeed
7
+ data.tar.gz: f7a095da673a5b32de33293c6056c580995d1b2ad913e2891c1740ab1ffb42896f1b0c69491eb75656907b60e4de6f6a58a119c8936cff26d1ed678bc1159e0c
data/README.md CHANGED
@@ -53,7 +53,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
53
53
  might want to use a conservative version lock in your `Gemfile`:
54
54
 
55
55
  ```rb
56
- gem 'rubocop', '~> 0.81.0', require: false
56
+ gem 'rubocop', '~> 0.82.0', require: false
57
57
  ```
58
58
 
59
59
  ## Quickstart
@@ -73,7 +73,7 @@ You can read a lot more about RuboCop in its [official docs](https://docs.ruboco
73
73
 
74
74
  RuboCop supports the following Ruby implementations:
75
75
 
76
- * MRI 2.3+
76
+ * MRI 2.4+
77
77
  * JRuby 9.2+
78
78
 
79
79
  ## Team
@@ -97,6 +97,14 @@ AllCops:
97
97
  # to true in the same configuration.
98
98
  EnabledByDefault: false
99
99
  DisabledByDefault: false
100
+ # New cops introduced between major versions are set to a special pending status
101
+ # and are not enabled by default with warning message.
102
+ # Change this behavior by overriding either `NewCops: enable` or `NewCops: disable`.
103
+ # When `NewCops` is `enable`, pending cops are enabled in bulk. Can be overridden by
104
+ # the `--enable-pending-cops` command-line option.
105
+ # When `NewCops` is `disable`, pending cops are disabled in bulk. Can be overridden by
106
+ # the `--disable-pending-cops` command-line option.
107
+ NewCops: pending
100
108
  # Enables the result cache if `true`. Can be overridden by the `--cache` command
101
109
  # line option.
102
110
  UseCache: true
@@ -125,7 +133,7 @@ AllCops:
125
133
  # followed by the Gemfile.lock or gems.locked file. (Although the Ruby version
126
134
  # is specified in the Gemfile or gems.rb file, RuboCop reads the final value
127
135
  # from the lock file.) If the Ruby version is still unresolved, RuboCop will
128
- # use the oldest officially supported Ruby version (currently Ruby 2.3).
136
+ # use the oldest officially supported Ruby version (currently Ruby 2.4).
129
137
  TargetRubyVersion: ~
130
138
 
131
139
  #################### Bundler ###############################
@@ -793,6 +801,22 @@ Layout/IndentationConsistency:
793
801
  # A reference to `EnforcedStyle: indented_internal_methods`.
794
802
  - https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions
795
803
 
804
+ Layout/IndentationStyle:
805
+ Description: 'Consistent indentation either with tabs only or spaces only.'
806
+ StyleGuide: '#spaces-indentation'
807
+ Enabled: true
808
+ VersionAdded: '0.49'
809
+ VersionChanged: '0.82'
810
+ # By default, the indentation width from Layout/IndentationWidth is used
811
+ # But it can be overridden by setting this parameter
812
+ # It is used during auto-correction to determine how many spaces should
813
+ # replace each tab.
814
+ IndentationWidth: ~
815
+ EnforcedStyle: spaces
816
+ SupportedStyles:
817
+ - spaces
818
+ - tabs
819
+
796
820
  Layout/IndentationWidth:
797
821
  Description: 'Use 2 spaces for indentation.'
798
822
  StyleGuide: '#spaces-indentation'
@@ -1080,6 +1104,11 @@ Layout/SpaceAroundKeyword:
1080
1104
  Enabled: true
1081
1105
  VersionAdded: '0.49'
1082
1106
 
1107
+ Layout/SpaceAroundMethodCallOperator:
1108
+ Description: 'Checks method call operators to not have spaces around them.'
1109
+ Enabled: pending
1110
+ VersionAdded: '0.82'
1111
+
1083
1112
  Layout/SpaceAroundOperators:
1084
1113
  Description: 'Use a single space around operators.'
1085
1114
  StyleGuide: '#spaces-operators'
@@ -1250,18 +1279,6 @@ Layout/SpaceInsideStringInterpolation:
1250
1279
  - space
1251
1280
  - no_space
1252
1281
 
1253
- Layout/Tab:
1254
- Description: 'No hard tabs.'
1255
- StyleGuide: '#spaces-indentation'
1256
- Enabled: true
1257
- VersionAdded: '0.49'
1258
- VersionChanged: '0.51'
1259
- # By default, the indentation width from Layout/IndentationWidth is used
1260
- # But it can be overridden by setting this parameter
1261
- # It is used during auto-correction to determine how many spaces should
1262
- # replace each tab.
1263
- IndentationWidth: ~
1264
-
1265
1282
  Layout/TrailingEmptyLines:
1266
1283
  Description: 'Checks trailing blank lines and final newline.'
1267
1284
  StyleGuide: '#newline-eof'
@@ -1567,6 +1584,8 @@ Lint/RaiseException:
1567
1584
  StyleGuide: '#raise-exception'
1568
1585
  Enabled: pending
1569
1586
  VersionAdded: '0.81'
1587
+ AllowedImplicitNamespaces:
1588
+ - 'Gem'
1570
1589
 
1571
1590
  Lint/RandOne:
1572
1591
  Description: >-
@@ -2409,6 +2428,15 @@ Style/CaseEquality:
2409
2428
  StyleGuide: '#no-case-equality'
2410
2429
  Enabled: true
2411
2430
  VersionAdded: '0.9'
2431
+ # If AllowOnConstant is enabled, the cop will ignore violations when the receiver of
2432
+ # the case equality operator is a constant.
2433
+ #
2434
+ # # bad
2435
+ # /string/ === "string"
2436
+ #
2437
+ # # good
2438
+ # String === "string"
2439
+ AllowOnConstant: false
2412
2440
 
2413
2441
  Style/CharacterLiteral:
2414
2442
  Description: 'Checks for uses of character literals.'
@@ -2449,6 +2477,7 @@ Style/ClassAndModuleChildren:
2449
2477
 
2450
2478
  Style/ClassCheck:
2451
2479
  Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.'
2480
+ StyleGuide: '#is-a-vs-kind-of'
2452
2481
  Enabled: true
2453
2482
  VersionAdded: '0.24'
2454
2483
  EnforcedStyle: is_a?
@@ -2616,6 +2645,12 @@ Style/Dir:
2616
2645
  Enabled: true
2617
2646
  VersionAdded: '0.50'
2618
2647
 
2648
+ Style/DisableCopsWithinSourceCodeDirective:
2649
+ Description: >-
2650
+ Forbids disabling/enabling cops within source code.
2651
+ Enabled: false
2652
+ VersionAdded: '0.82'
2653
+
2619
2654
  Style/Documentation:
2620
2655
  Description: 'Document classes and non-namespace modules.'
2621
2656
  Enabled: true
@@ -2734,6 +2769,17 @@ Style/ExpandPathArguments:
2734
2769
  Enabled: true
2735
2770
  VersionAdded: '0.53'
2736
2771
 
2772
+ Style/ExponentialNotation:
2773
+ Description: 'When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).'
2774
+ StyleGuide: '#exponential-notation'
2775
+ Enabled: pending
2776
+ VersionAdded: '0.82'
2777
+ EnforcedStyle: scientific
2778
+ SupportedStyles:
2779
+ - scientific
2780
+ - engineering
2781
+ - integral
2782
+
2737
2783
  Style/FloatDivision:
2738
2784
  Description: 'For performing float division, coerce one side only.'
2739
2785
  StyleGuide: '#float-division'
@@ -235,6 +235,7 @@ require_relative 'rubocop/cop/layout/hash_alignment'
235
235
  require_relative 'rubocop/cop/layout/heredoc_argument_closing_parenthesis'
236
236
  require_relative 'rubocop/cop/layout/heredoc_indentation'
237
237
  require_relative 'rubocop/cop/layout/indentation_consistency'
238
+ require_relative 'rubocop/cop/layout/indentation_style'
238
239
  require_relative 'rubocop/cop/layout/indentation_width'
239
240
  require_relative 'rubocop/cop/layout/initial_indentation'
240
241
  require_relative 'rubocop/cop/layout/leading_comment_space'
@@ -261,6 +262,7 @@ require_relative 'rubocop/cop/layout/space_after_semicolon'
261
262
  require_relative 'rubocop/cop/layout/space_around_block_parameters'
262
263
  require_relative 'rubocop/cop/layout/space_around_equals_in_parameter_default'
263
264
  require_relative 'rubocop/cop/layout/space_around_keyword'
265
+ require_relative 'rubocop/cop/layout/space_around_method_call_operator'
264
266
  require_relative 'rubocop/cop/layout/space_around_operators'
265
267
  require_relative 'rubocop/cop/layout/space_before_block_braces'
266
268
  require_relative 'rubocop/cop/layout/space_before_comma'
@@ -277,7 +279,6 @@ require_relative 'rubocop/cop/layout/space_inside_percent_literal_delimiters'
277
279
  require_relative 'rubocop/cop/layout/space_inside_range_literal'
278
280
  require_relative 'rubocop/cop/layout/space_inside_reference_brackets'
279
281
  require_relative 'rubocop/cop/layout/space_inside_string_interpolation'
280
- require_relative 'rubocop/cop/layout/tab'
281
282
  require_relative 'rubocop/cop/layout/trailing_empty_lines'
282
283
  require_relative 'rubocop/cop/layout/trailing_whitespace'
283
284
 
@@ -423,6 +424,7 @@ require_relative 'rubocop/cop/style/copyright'
423
424
  require_relative 'rubocop/cop/style/date_time'
424
425
  require_relative 'rubocop/cop/style/def_with_parentheses'
425
426
  require_relative 'rubocop/cop/style/dir'
427
+ require_relative 'rubocop/cop/style/disable_cops_within_source_code_directive'
426
428
  require_relative 'rubocop/cop/style/documentation_method'
427
429
  require_relative 'rubocop/cop/style/documentation'
428
430
  require_relative 'rubocop/cop/style/double_cop_disable_directive'
@@ -440,6 +442,7 @@ require_relative 'rubocop/cop/style/end_block'
440
442
  require_relative 'rubocop/cop/style/eval_with_location'
441
443
  require_relative 'rubocop/cop/style/even_odd'
442
444
  require_relative 'rubocop/cop/style/expand_path_arguments'
445
+ require_relative 'rubocop/cop/style/exponential_notation'
443
446
  require_relative 'rubocop/cop/style/float_division'
444
447
  require_relative 'rubocop/cop/style/for'
445
448
  require_relative 'rubocop/cop/style/format_string'
@@ -585,7 +588,6 @@ require_relative 'rubocop/formatter/simple_text_formatter'
585
588
  # relies on simple text
586
589
  require_relative 'rubocop/formatter/clang_style_formatter'
587
590
  require_relative 'rubocop/formatter/disabled_config_formatter'
588
- require_relative 'rubocop/formatter/disabled_lines_formatter'
589
591
  require_relative 'rubocop/formatter/emacs_style_formatter'
590
592
  require_relative 'rubocop/formatter/file_list_formatter'
591
593
  require_relative 'rubocop/formatter/fuubar_style_formatter'
@@ -116,7 +116,7 @@ module RuboCop
116
116
  #
117
117
  # @return [Integer] the index of the receiver node in its siblings
118
118
  def sibling_index
119
- parent.children.index { |sibling| sibling.equal?(self) }
119
+ parent&.children&.index { |sibling| sibling.equal?(self) }
120
120
  end
121
121
 
122
122
  # Common destructuring method. This can be used to normalize
@@ -18,6 +18,19 @@ module RuboCop
18
18
  each_child_node.to_a
19
19
  end
20
20
 
21
+ # Calls the given block for all values in the `array` literal.
22
+ #
23
+ # @yieldparam [Node] node each node
24
+ # @return [self] if a block is given
25
+ # @return [Enumerator] if no block is given
26
+ def each_value(&block)
27
+ return to_enum(__method__) unless block_given?
28
+
29
+ values.each(&block)
30
+
31
+ self
32
+ end
33
+
21
34
  # Checks whether the `array` literal is delimited by square brackets.
22
35
  #
23
36
  # @return [Boolean] whether the array is enclosed in square brackets
@@ -121,6 +121,14 @@ module RuboCop
121
121
  loc.respond_to?(:dot) && loc.dot && loc.dot.is?('::')
122
122
  end
123
123
 
124
+ # Checks whether the dispatched method uses a safe navigation operator to
125
+ # connect the receiver and the method name.
126
+ #
127
+ # @return [Boolean] whether the method was called with a connecting dot
128
+ def safe_navigation?
129
+ loc.respond_to?(:dot) && loc.dot && loc.dot.is?('&.')
130
+ end
131
+
124
132
  # Checks whether the *explicit* receiver of this method dispatch is
125
133
  # `self`.
126
134
  #
@@ -83,10 +83,7 @@ module RuboCop
83
83
  end
84
84
 
85
85
  def act_on_options
86
- ConfigLoader.debug = @options[:debug]
87
- ConfigLoader.auto_gen_config = @options[:auto_gen_config]
88
- ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
89
- ConfigLoader.options_config = @options[:config]
86
+ set_options_to_config_loader
90
87
 
91
88
  @config_store.options_config = @options[:config] if @options[:config]
92
89
  @config_store.force_default_config! if @options[:force_default_config]
@@ -102,6 +99,15 @@ module RuboCop
102
99
  end
103
100
  end
104
101
 
102
+ def set_options_to_config_loader
103
+ ConfigLoader.debug = @options[:debug]
104
+ ConfigLoader.auto_gen_config = @options[:auto_gen_config]
105
+ ConfigLoader.disable_pending_cops = @options[:disable_pending_cops]
106
+ ConfigLoader.enable_pending_cops = @options[:enable_pending_cops]
107
+ ConfigLoader.ignore_parent_exclusion = @options[:ignore_parent_exclusion]
108
+ ConfigLoader.options_config = @options[:config]
109
+ end
110
+
105
111
  def handle_exiting_options
106
112
  return unless Options::EXITING_OPTIONS.any? { |o| @options.key? o }
107
113
 
@@ -47,7 +47,7 @@ module RuboCop
47
47
  end
48
48
 
49
49
  def_delegators :@hash, :[], :[]=, :delete, :each, :key?, :keys, :each_key,
50
- :map, :merge, :to_h, :to_hash
50
+ :map, :merge, :to_h, :to_hash, :transform_values
51
51
  def_delegators :@validator, :validate, :target_ruby_version
52
52
 
53
53
  def to_s
@@ -116,6 +116,14 @@ module RuboCop
116
116
  @for_all_cops ||= self['AllCops'] || {}
117
117
  end
118
118
 
119
+ def disabled_new_cops?
120
+ for_all_cops['NewCops'] == 'disable'
121
+ end
122
+
123
+ def enabled_new_cops?
124
+ for_all_cops['NewCops'] == 'enable'
125
+ end
126
+
119
127
  def file_to_include?(file)
120
128
  relative_file_path = path_relative_to_config(file)
121
129
 
@@ -24,7 +24,7 @@ module RuboCop
24
24
  include FileFinder
25
25
 
26
26
  attr_accessor :debug, :auto_gen_config, :ignore_parent_exclusion,
27
- :options_config
27
+ :options_config, :disable_pending_cops, :enable_pending_cops
28
28
  attr_writer :default_configuration
29
29
 
30
30
  alias debug? debug
@@ -55,7 +55,10 @@ module RuboCop
55
55
  end
56
56
 
57
57
  def add_missing_namespaces(path, hash)
58
- hash.keys.each do |key|
58
+ # Using `hash.each_key` will cause the
59
+ # `can't add a new key into hash during iteration` error
60
+ hash_keys = hash.keys
61
+ hash_keys.each do |key|
59
62
  q = Cop::Cop.qualified_cop_name(key, path)
60
63
  next if q == key
61
64
 
@@ -76,30 +79,35 @@ module RuboCop
76
79
  # user's home directory is checked. If there's no .rubocop.yml
77
80
  # there either, the path to the default file is returned.
78
81
  def configuration_file_for(target_dir)
79
- find_project_dotfile(target_dir) ||
80
- find_user_dotfile ||
81
- find_user_xdg_config ||
82
- DEFAULT_FILE
82
+ find_project_dotfile(target_dir) || find_user_dotfile ||
83
+ find_user_xdg_config || DEFAULT_FILE
83
84
  end
84
85
 
85
86
  def configuration_from_file(config_file)
86
- config = load_file(config_file)
87
- return config if config_file == DEFAULT_FILE
87
+ return ConfigLoader.default_configuration if config_file == DEFAULT_FILE
88
88
 
89
+ config = load_file(config_file)
89
90
  if ignore_parent_exclusion?
90
91
  print 'Ignoring AllCops/Exclude from parent folders' if debug?
91
92
  else
92
93
  add_excludes_from_files(config, config_file)
93
94
  end
95
+
94
96
  merge_with_default(config, config_file).tap do |merged_config|
95
- warn_on_pending_cops(merged_config.pending_cops)
97
+ unless possible_new_cops?(config)
98
+ warn_on_pending_cops(merged_config.pending_cops)
99
+ end
96
100
  end
97
101
  end
98
102
 
103
+ def possible_new_cops?(config)
104
+ disable_pending_cops || enable_pending_cops ||
105
+ config.disabled_new_cops? || config.enabled_new_cops?
106
+ end
107
+
99
108
  def add_excludes_from_files(config, config_file)
100
- found_files =
101
- find_files_upwards(DOTFILE, config_file) +
102
- [find_user_dotfile, find_user_xdg_config].compact
109
+ found_files = find_files_upwards(DOTFILE, config_file) +
110
+ [find_user_dotfile, find_user_xdg_config].compact
103
111
 
104
112
  return if found_files.empty?
105
113
  return if PathUtil.relative_path(found_files.last) ==
@@ -198,7 +206,9 @@ module RuboCop
198
206
  def write_config_file(file_name, file_string, rubocop_yml_contents)
199
207
  File.open(file_name, 'w') do |f|
200
208
  f.write "inherit_from:#{file_string}\n"
201
- f.write "\n#{rubocop_yml_contents}" if rubocop_yml_contents =~ /\S/
209
+ if /\S/.match?(rubocop_yml_contents)
210
+ f.write "\n#{rubocop_yml_contents}"
211
+ end
202
212
  end
203
213
  end
204
214
 
@@ -250,8 +260,7 @@ module RuboCop
250
260
 
251
261
  def yaml_safe_load(yaml_code, filename)
252
262
  if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
253
- SafeYAML.load(yaml_code, filename,
254
- whitelisted_tags: %w[!ruby/regexp])
263
+ SafeYAML.load(yaml_code, filename, whitelisted_tags: %w[!ruby/regexp])
255
264
  # Ruby 2.6+
256
265
  elsif Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0')
257
266
  YAML.safe_load(
@@ -181,7 +181,7 @@ module RuboCop
181
181
  end
182
182
 
183
183
  def transform(config)
184
- Hash[config.map { |cop, params| [cop, yield(params)] }]
184
+ config.transform_values { |params| yield(params) }
185
185
  end
186
186
 
187
187
  def gem_config_path(gem_name, relative_config_path)
@@ -17,6 +17,7 @@ module RuboCop
17
17
  'Layout/IndentHash' => 'Layout/FirstHashElementIndentation',
18
18
  'Layout/IndentHeredoc' => 'Layout/HeredocIndentation',
19
19
  'Layout/LeadingBlankLines' => 'Layout/LeadingEmptyLines',
20
+ 'Layout/Tab' => 'Layout/IndentationStyle',
20
21
  'Layout/TrailingBlankLines' => 'Layout/TrailingEmptyLines',
21
22
  'Lint/DuplicatedKey' => 'Lint/DuplicateHashKey',
22
23
  'Lint/EndInMethod' => 'Style/EndBlock',
@@ -13,6 +13,7 @@ module RuboCop
13
13
  INTERNAL_PARAMS = %w[Description StyleGuide
14
14
  VersionAdded VersionChanged VersionRemoved
15
15
  Reference Safe SafeAutoCorrect].freeze
16
+ NEW_COPS_VALUES = %w[pending disable enable].freeze
16
17
 
17
18
  def_delegators :@config, :smart_loaded_path, :for_all_cops
18
19
 
@@ -22,6 +23,7 @@ module RuboCop
22
23
  @target_ruby = TargetRuby.new(config)
23
24
  end
24
25
 
26
+ # rubocop:disable Metrics/AbcSize
25
27
  def validate
26
28
  check_cop_config_value(@config)
27
29
  reject_conflicting_safe_settings
@@ -37,11 +39,13 @@ module RuboCop
37
39
 
38
40
  alert_about_unrecognized_cops(invalid_cop_names)
39
41
  check_target_ruby
42
+ validate_new_cops_parameter
40
43
  validate_parameter_names(valid_cop_names)
41
44
  validate_enforced_styles(valid_cop_names)
42
45
  validate_syntax_cop
43
46
  reject_mutually_exclusive_defaults
44
47
  end
48
+ # rubocop:enable Metrics/AbcSize
45
49
 
46
50
  def target_ruby_version
47
51
  target_ruby.version
@@ -107,6 +111,18 @@ module RuboCop
107
111
  'It\'s not possible to disable this cop.'
108
112
  end
109
113
 
114
+ def validate_new_cops_parameter
115
+ new_cop_parameter = @config.for_all_cops['NewCops']
116
+ return if new_cop_parameter.nil? ||
117
+ NEW_COPS_VALUES.include?(new_cop_parameter)
118
+
119
+ message = "invalid #{new_cop_parameter} for `NewCops` found in" \
120
+ "#{smart_loaded_path}\n" \
121
+ "Valid choices are: #{NEW_COPS_VALUES.join(', ')}"
122
+
123
+ raise ValidationError, message
124
+ end
125
+
110
126
  def validate_parameter_names(valid_cop_names)
111
127
  valid_cop_names.each do |name|
112
128
  validate_section_presence(name)