rubocop 0.75.1 → 0.76.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +52 -53
  4. data/lib/rubocop.rb +10 -9
  5. data/lib/rubocop/ast/builder.rb +1 -0
  6. data/lib/rubocop/ast/node.rb +4 -0
  7. data/lib/rubocop/ast/node/return_node.rb +24 -0
  8. data/lib/rubocop/cli.rb +7 -4
  9. data/lib/rubocop/comment_config.rb +2 -2
  10. data/lib/rubocop/config.rb +7 -0
  11. data/lib/rubocop/config_loader.rb +1 -1
  12. data/lib/rubocop/config_loader_resolver.rb +2 -1
  13. data/lib/rubocop/config_obsoletion.rb +9 -0
  14. data/lib/rubocop/config_validator.rb +24 -15
  15. data/lib/rubocop/cop/commissioner.rb +15 -7
  16. data/lib/rubocop/cop/cop.rb +10 -6
  17. data/lib/rubocop/cop/corrector.rb +8 -7
  18. data/lib/rubocop/cop/generator/configuration_injector.rb +1 -1
  19. data/lib/rubocop/cop/layout/align_hash.rb +6 -2
  20. data/lib/rubocop/cop/layout/comment_indentation.rb +10 -13
  21. data/lib/rubocop/cop/layout/empty_comment.rb +7 -16
  22. data/lib/rubocop/cop/layout/end_of_line.rb +8 -3
  23. data/lib/rubocop/cop/layout/indent_first_argument.rb +9 -7
  24. data/lib/rubocop/cop/layout/indent_first_hash_element.rb +1 -1
  25. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  26. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +2 -0
  27. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +9 -7
  28. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -4
  29. data/lib/rubocop/cop/layout/space_inside_parens.rb +6 -6
  30. data/lib/rubocop/cop/layout/trailing_whitespace.rb +18 -2
  31. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -8
  32. data/lib/rubocop/cop/lint/missing_cop_enable_directive.rb +2 -2
  33. data/lib/rubocop/cop/lint/{unneeded_cop_disable_directive.rb → redundant_cop_disable_directive.rb} +23 -23
  34. data/lib/rubocop/cop/lint/{unneeded_cop_enable_directive.rb → redundant_cop_enable_directive.rb} +6 -8
  35. data/lib/rubocop/cop/lint/{unneeded_require_statement.rb → redundant_require_statement.rb} +1 -1
  36. data/lib/rubocop/cop/lint/{unneeded_splat_expansion.rb → redundant_splat_expansion.rb} +5 -5
  37. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +5 -6
  38. data/lib/rubocop/cop/lint/void.rb +4 -4
  39. data/lib/rubocop/cop/metrics/abc_size.rb +1 -1
  40. data/lib/rubocop/cop/metrics/line_length.rb +1 -4
  41. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +23 -6
  42. data/lib/rubocop/cop/mixin/method_complexity.rb +2 -1
  43. data/lib/rubocop/cop/mixin/statement_modifier.rb +5 -2
  44. data/lib/rubocop/cop/mixin/trailing_comma.rb +8 -6
  45. data/lib/rubocop/cop/naming/file_name.rb +12 -5
  46. data/lib/rubocop/cop/registry.rb +1 -1
  47. data/lib/rubocop/cop/style/attr.rb +2 -2
  48. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +6 -6
  49. data/lib/rubocop/cop/style/comment_annotation.rb +5 -5
  50. data/lib/rubocop/cop/style/copyright.rb +11 -7
  51. data/lib/rubocop/cop/style/double_cop_disable_directive.rb +2 -2
  52. data/lib/rubocop/cop/style/empty_case_condition.rb +2 -2
  53. data/lib/rubocop/cop/style/empty_literal.rb +2 -2
  54. data/lib/rubocop/cop/style/empty_method.rb +5 -5
  55. data/lib/rubocop/cop/style/format_string.rb +10 -7
  56. data/lib/rubocop/cop/style/format_string_token.rb +2 -0
  57. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +10 -0
  58. data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
  59. data/lib/rubocop/cop/style/if_unless_modifier.rb +9 -2
  60. data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
  61. data/lib/rubocop/cop/style/inverse_methods.rb +19 -13
  62. data/lib/rubocop/cop/style/line_end_concatenation.rb +14 -10
  63. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -9
  64. data/lib/rubocop/cop/style/multiline_when_then.rb +1 -1
  65. data/lib/rubocop/cop/style/nested_modifier.rb +4 -2
  66. data/lib/rubocop/cop/style/non_nil_check.rb +21 -9
  67. data/lib/rubocop/cop/style/{unneeded_capital_w.rb → redundant_capital_w.rb} +1 -1
  68. data/lib/rubocop/cop/style/{unneeded_condition.rb → redundant_condition.rb} +3 -3
  69. data/lib/rubocop/cop/style/{unneeded_interpolation.rb → redundant_interpolation.rb} +1 -1
  70. data/lib/rubocop/cop/style/{unneeded_percent_q.rb → redundant_percent_q.rb} +1 -1
  71. data/lib/rubocop/cop/style/redundant_return.rb +25 -21
  72. data/lib/rubocop/cop/style/{unneeded_sort.rb → redundant_sort.rb} +4 -4
  73. data/lib/rubocop/cop/style/safe_navigation.rb +13 -10
  74. data/lib/rubocop/cop/style/semicolon.rb +2 -2
  75. data/lib/rubocop/cop/style/special_global_vars.rb +5 -7
  76. data/lib/rubocop/cop/util.rb +1 -1
  77. data/lib/rubocop/cop/utils/format_string.rb +10 -18
  78. data/lib/rubocop/cop/variable_force.rb +7 -5
  79. data/lib/rubocop/node_pattern.rb +3 -1
  80. data/lib/rubocop/options.rb +12 -6
  81. data/lib/rubocop/result_cache.rb +1 -1
  82. data/lib/rubocop/runner.rb +32 -27
  83. data/lib/rubocop/target_finder.rb +12 -6
  84. data/lib/rubocop/version.rb +1 -1
  85. metadata +12 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 354a14aa737b4743d04d65393e8caae409513d2302b31aca36090441100f1bdb
4
- data.tar.gz: 7bdbb625ae97e5e0f1a5ca6bfe0d93c71ac4a86a566ba13b987a293949486e51
3
+ metadata.gz: bd5622915d19930481b80ac553a18b3500306bca922491f83290451a3cd267c9
4
+ data.tar.gz: 73002e0e186887f12add4e88154bf2510280d531ecd66f73b9eb57fb842d7f2a
5
5
  SHA512:
6
- metadata.gz: bf54a562c567c28f118f5bf6bf0a9fb9e5987351559a001f80de025cb08793cd546731e80d3690dcce3ce8e0eda96381563ae307a5b0df303322c75331b8f14b
7
- data.tar.gz: 76fb85901be4d90de0697874bf0bea52c2a23e2b39fa9607ec797d6768465c4f903bc2645ebf41a504f526064aee2e0000f7bbd2701735787425770682b79ec8
6
+ metadata.gz: 7a866f9130e0388351acd83aee37bf7a15f1e64c94c51a3d58f3c439b90cbffb5a173837b48aae3ba86ab8005bbe73e6b088c905000910c4cf523395c8887b39
7
+ data.tar.gz: e8c2655aa3c419850da067790d456ed96c67bb43eee41d4cd9389185dbb9965329f405a2146949062daf57cd15a8e0d375b00df4df09fbc03fd06d9369f213ce
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.75.1', require: false
56
+ gem 'rubocop', '~> 0.76.0', require: false
57
57
  ```
58
58
 
59
59
  ## Quickstart
@@ -1512,6 +1512,29 @@ Lint/RandOne:
1512
1512
  Enabled: true
1513
1513
  VersionAdded: '0.36'
1514
1514
 
1515
+ Lint/RedundantCopDisableDirective:
1516
+ Description: >-
1517
+ Checks for rubocop:disable comments that can be removed.
1518
+ Note: this cop is not disabled when disabling all cops.
1519
+ It must be explicitly disabled.
1520
+ Enabled: true
1521
+ VersionAdded: '0.76'
1522
+
1523
+ Lint/RedundantCopEnableDirective:
1524
+ Description: Checks for rubocop:enable comments that can be removed.
1525
+ Enabled: true
1526
+ VersionAdded: '0.76'
1527
+
1528
+ Lint/RedundantRequireStatement:
1529
+ Description: 'Checks for unnecessary `require` statement.'
1530
+ Enabled: true
1531
+ VersionAdded: '0.76'
1532
+
1533
+ Lint/RedundantSplatExpansion:
1534
+ Description: 'Checks for splat unnecessarily being called on literals.'
1535
+ Enabled: true
1536
+ VersionChanged: '0.76'
1537
+
1515
1538
  Lint/RedundantWithIndex:
1516
1539
  Description: 'Checks for redundant `with_index`.'
1517
1540
  Enabled: true
@@ -1645,30 +1668,6 @@ Lint/UnifiedInteger:
1645
1668
  Enabled: true
1646
1669
  VersionAdded: '0.43'
1647
1670
 
1648
- Lint/UnneededCopDisableDirective:
1649
- Description: >-
1650
- Checks for rubocop:disable comments that can be removed.
1651
- Note: this cop is not disabled when disabling all cops.
1652
- It must be explicitly disabled.
1653
- Enabled: true
1654
- VersionAdded: '0.53'
1655
-
1656
- Lint/UnneededCopEnableDirective:
1657
- Description: Checks for rubocop:enable comments that can be removed.
1658
- Enabled: true
1659
- VersionAdded: '0.53'
1660
-
1661
- Lint/UnneededRequireStatement:
1662
- Description: 'Checks for unnecessary `require` statement.'
1663
- Enabled: true
1664
- VersionAdded: '0.51'
1665
-
1666
- Lint/UnneededSplatExpansion:
1667
- Description: 'Checks for splat unnecessarily being called on literals.'
1668
- Enabled: true
1669
- VersionAdded: '0.43'
1670
- VersionChanged: '0.74'
1671
-
1672
1671
  Lint/UnreachableCode:
1673
1672
  Description: 'Unreachable code.'
1674
1673
  Enabled: true
@@ -2076,6 +2075,7 @@ Naming/UncommunicativeMethodParamName:
2076
2075
  - at
2077
2076
  - ip
2078
2077
  - db
2078
+ - os
2079
2079
  # Blacklisted names that will register an offense
2080
2080
  ForbiddenNames: []
2081
2081
 
@@ -3402,6 +3402,16 @@ Style/RedundantBegin:
3402
3402
  VersionAdded: '0.10'
3403
3403
  VersionChanged: '0.21'
3404
3404
 
3405
+ Style/RedundantCapitalW:
3406
+ Description: 'Checks for %W when interpolation is not needed.'
3407
+ Enabled: true
3408
+ VersionAdded: '0.76'
3409
+
3410
+ Style/RedundantCondition:
3411
+ Description: 'Checks for unnecessary conditional expressions.'
3412
+ Enabled: true
3413
+ VersionAdded: '0.76'
3414
+
3405
3415
  Style/RedundantConditional:
3406
3416
  Description: "Don't return true/false from a conditional."
3407
3417
  Enabled: true
@@ -3420,11 +3430,22 @@ Style/RedundantFreeze:
3420
3430
  VersionAdded: '0.34'
3421
3431
  VersionChanged: '0.66'
3422
3432
 
3433
+ Style/RedundantInterpolation:
3434
+ Description: 'Checks for strings that are just an interpolated expression.'
3435
+ Enabled: true
3436
+ VersionAdded: '0.76'
3437
+
3423
3438
  Style/RedundantParentheses:
3424
3439
  Description: "Checks for parentheses that seem not to serve any purpose."
3425
3440
  Enabled: true
3426
3441
  VersionAdded: '0.36'
3427
3442
 
3443
+ Style/RedundantPercentQ:
3444
+ Description: 'Checks for %q/%Q when single quotes or double quotes would do.'
3445
+ StyleGuide: '#percent-q'
3446
+ Enabled: true
3447
+ VersionAdded: '0.76'
3448
+
3428
3449
  Style/RedundantReturn:
3429
3450
  Description: "Don't use return where it's not required."
3430
3451
  StyleGuide: '#no-explicit-return'
@@ -3441,6 +3462,13 @@ Style/RedundantSelf:
3441
3462
  VersionAdded: '0.10'
3442
3463
  VersionChanged: '0.13'
3443
3464
 
3465
+ Style/RedundantSort:
3466
+ Description: >-
3467
+ Use `min` instead of `sort.first`,
3468
+ `max_by` instead of `sort_by...last`, etc.
3469
+ Enabled: true
3470
+ VersionAdded: '0.76'
3471
+
3444
3472
  Style/RedundantSortBy:
3445
3473
  Description: 'Use `sort` instead of `sort_by { |x| x }`.'
3446
3474
  Enabled: true
@@ -3828,35 +3856,6 @@ Style/UnlessElse:
3828
3856
  Enabled: true
3829
3857
  VersionAdded: '0.9'
3830
3858
 
3831
- Style/UnneededCapitalW:
3832
- Description: 'Checks for %W when interpolation is not needed.'
3833
- Enabled: true
3834
- VersionAdded: '0.21'
3835
- VersionChanged: '0.24'
3836
-
3837
- Style/UnneededCondition:
3838
- Description: 'Checks for unnecessary conditional expressions.'
3839
- Enabled: true
3840
- VersionAdded: '0.57'
3841
-
3842
- Style/UnneededInterpolation:
3843
- Description: 'Checks for strings that are just an interpolated expression.'
3844
- Enabled: true
3845
- VersionAdded: '0.36'
3846
-
3847
- Style/UnneededPercentQ:
3848
- Description: 'Checks for %q/%Q when single quotes or double quotes would do.'
3849
- StyleGuide: '#percent-q'
3850
- Enabled: true
3851
- VersionAdded: '0.24'
3852
-
3853
- Style/UnneededSort:
3854
- Description: >-
3855
- Use `min` instead of `sort.first`,
3856
- `max_by` instead of `sort_by...last`, etc.
3857
- Enabled: true
3858
- VersionAdded: '0.55'
3859
-
3860
3859
  Style/UnpackFirst:
3861
3860
  Description: >-
3862
3861
  Checks for accessing the first element of `String#unpack`
@@ -55,6 +55,7 @@ require_relative 'rubocop/ast/node/range_node'
55
55
  require_relative 'rubocop/ast/node/regexp_node'
56
56
  require_relative 'rubocop/ast/node/resbody_node'
57
57
  require_relative 'rubocop/ast/node/retry_node'
58
+ require_relative 'rubocop/ast/node/return_node'
58
59
  require_relative 'rubocop/ast/node/self_class_node'
59
60
  require_relative 'rubocop/ast/node/send_node'
60
61
  require_relative 'rubocop/ast/node/str_node'
@@ -321,6 +322,10 @@ require_relative 'rubocop/cop/lint/parentheses_as_grouped_expression'
321
322
  require_relative 'rubocop/cop/lint/percent_string_array'
322
323
  require_relative 'rubocop/cop/lint/percent_symbol_array'
323
324
  require_relative 'rubocop/cop/lint/rand_one'
325
+ require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
326
+ require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
327
+ require_relative 'rubocop/cop/lint/redundant_require_statement'
328
+ require_relative 'rubocop/cop/lint/redundant_splat_expansion'
324
329
  require_relative 'rubocop/cop/lint/redundant_with_index'
325
330
  require_relative 'rubocop/cop/lint/redundant_with_object'
326
331
  require_relative 'rubocop/cop/lint/regexp_as_condition'
@@ -341,10 +346,6 @@ require_relative 'rubocop/cop/lint/syntax'
341
346
  require_relative 'rubocop/cop/lint/to_json'
342
347
  require_relative 'rubocop/cop/lint/underscore_prefixed_variable_name'
343
348
  require_relative 'rubocop/cop/lint/unified_integer'
344
- require_relative 'rubocop/cop/lint/unneeded_cop_disable_directive'
345
- require_relative 'rubocop/cop/lint/unneeded_cop_enable_directive'
346
- require_relative 'rubocop/cop/lint/unneeded_require_statement'
347
- require_relative 'rubocop/cop/lint/unneeded_splat_expansion'
348
349
  require_relative 'rubocop/cop/lint/unreachable_code'
349
350
  require_relative 'rubocop/cop/lint/unused_block_argument'
350
351
  require_relative 'rubocop/cop/lint/unused_method_argument'
@@ -502,12 +503,17 @@ require_relative 'rubocop/cop/style/proc'
502
503
  require_relative 'rubocop/cop/style/raise_args'
503
504
  require_relative 'rubocop/cop/style/random_with_offset'
504
505
  require_relative 'rubocop/cop/style/redundant_begin'
506
+ require_relative 'rubocop/cop/style/redundant_capital_w'
507
+ require_relative 'rubocop/cop/style/redundant_condition'
505
508
  require_relative 'rubocop/cop/style/redundant_conditional'
506
509
  require_relative 'rubocop/cop/style/redundant_exception'
507
510
  require_relative 'rubocop/cop/style/redundant_freeze'
511
+ require_relative 'rubocop/cop/style/redundant_interpolation'
508
512
  require_relative 'rubocop/cop/style/redundant_parentheses'
513
+ require_relative 'rubocop/cop/style/redundant_percent_q'
509
514
  require_relative 'rubocop/cop/style/redundant_return'
510
515
  require_relative 'rubocop/cop/style/redundant_self'
516
+ require_relative 'rubocop/cop/style/redundant_sort'
511
517
  require_relative 'rubocop/cop/style/redundant_sort_by'
512
518
  require_relative 'rubocop/cop/style/regexp_literal'
513
519
  require_relative 'rubocop/cop/style/rescue_modifier'
@@ -544,11 +550,6 @@ require_relative 'rubocop/cop/style/trailing_method_end_statement'
544
550
  require_relative 'rubocop/cop/style/trailing_underscore_variable'
545
551
  require_relative 'rubocop/cop/style/trivial_accessors'
546
552
  require_relative 'rubocop/cop/style/unless_else'
547
- require_relative 'rubocop/cop/style/unneeded_capital_w'
548
- require_relative 'rubocop/cop/style/unneeded_condition'
549
- require_relative 'rubocop/cop/style/unneeded_interpolation'
550
- require_relative 'rubocop/cop/style/unneeded_percent_q'
551
- require_relative 'rubocop/cop/style/unneeded_sort'
552
553
  require_relative 'rubocop/cop/style/unpack_first'
553
554
  require_relative 'rubocop/cop/style/variable_interpolation'
554
555
  require_relative 'rubocop/cop/style/when_then'
@@ -41,6 +41,7 @@ module RuboCop
41
41
  regexp: RegexpNode,
42
42
  resbody: ResbodyNode,
43
43
  retry: RetryNode,
44
+ return: ReturnNode,
44
45
  csend: SendNode,
45
46
  send: SendNode,
46
47
  str: StrNode,
@@ -469,6 +469,10 @@ module RuboCop
469
469
  parent&.send_type? && parent.arguments.include?(self)
470
470
  end
471
471
 
472
+ def boolean_type?
473
+ true_type? || false_type?
474
+ end
475
+
472
476
  def numeric_type?
473
477
  int_type? || float_type?
474
478
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module AST
5
+ # A node extension for `return` nodes. This will be used in place of a
6
+ # plain node when the builder constructs the AST, making its methods
7
+ # available to all `return` nodes within RuboCop.
8
+ class ReturnNode < Node
9
+ include MethodDispatchNode
10
+ include ParameterizedNode
11
+
12
+ # Returns the arguments of the `return`.
13
+ #
14
+ # @return [Array] The arguments of the `return`.
15
+ def arguments
16
+ if node_parts.one? && node_parts.first.begin_type?
17
+ node_parts.first.children
18
+ else
19
+ node_parts
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -83,18 +83,21 @@ module RuboCop
83
83
 
84
84
  def maybe_run_line_length_cop(paths)
85
85
  if !line_length_enabled?(@config_store.for(Dir.pwd))
86
- puts Rainbow("#{PHASE_1} #{PHASE_1_DISABLED}").yellow
87
- ''
86
+ skip_line_length_cop(PHASE_1_DISABLED)
88
87
  elsif !same_max_line_length?(
89
88
  @config_store.for(Dir.pwd), ConfigLoader.default_configuration
90
89
  )
91
- puts Rainbow("#{PHASE_1} #{PHASE_1_OVERRIDDEN}").yellow
92
- ''
90
+ skip_line_length_cop(PHASE_1_OVERRIDDEN)
93
91
  else
94
92
  run_line_length_cop_auto_gen_config(paths)
95
93
  end
96
94
  end
97
95
 
96
+ def skip_line_length_cop(reason)
97
+ puts Rainbow("#{PHASE_1} #{reason}").yellow
98
+ ''
99
+ end
100
+
98
101
  def line_length_enabled?(config)
99
102
  line_length_cop(config)['Enabled']
100
103
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  # This class parses the special `rubocop:disable` comments in a source
5
5
  # and provides a way to check if each cop is enabled at arbitrary line.
6
6
  class CommentConfig
7
- UNNEEDED_DISABLE = 'Lint/UnneededCopDisableDirective'
7
+ REDUNDANT_DISABLE = 'Lint/RedundantCopDisableDirective'
8
8
 
9
9
  COP_NAME_PATTERN = '([A-Z]\w+/)?(?:[A-Z]\w+)'
10
10
  COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}"
@@ -152,7 +152,7 @@ module RuboCop
152
152
  end
153
153
 
154
154
  def all_cop_names
155
- @all_cop_names ||= Cop::Cop.registry.names - [UNNEEDED_DISABLE]
155
+ @all_cop_names ||= Cop::Cop.registry.names - [REDUNDANT_DISABLE]
156
156
  end
157
157
 
158
158
  def comment_only_line?(line_number)
@@ -53,6 +53,13 @@ module RuboCop
53
53
  @signature ||= Digest::SHA1.hexdigest(to_s)
54
54
  end
55
55
 
56
+ # True if this is a config file that is shipped with RuboCop
57
+ def internal?
58
+ base_config_path = File.expand_path(File.join(ConfigLoader::RUBOCOP_HOME,
59
+ 'config'))
60
+ File.expand_path(loaded_path).start_with?(base_config_path)
61
+ end
62
+
56
63
  def make_excludes_absolute
57
64
  each_key do |key|
58
65
  @validator.validate_section_presence(key)
@@ -46,7 +46,7 @@ module RuboCop
46
46
 
47
47
  add_missing_namespaces(path, hash)
48
48
 
49
- resolver.resolve_inheritance_from_gems(hash, hash.delete('inherit_gem'))
49
+ resolver.resolve_inheritance_from_gems(hash)
50
50
  resolver.resolve_inheritance(path, hash, file, debug?)
51
51
 
52
52
  hash.delete('inherit_from')
@@ -35,7 +35,8 @@ module RuboCop
35
35
  end
36
36
  end
37
37
 
38
- def resolve_inheritance_from_gems(hash, gems)
38
+ def resolve_inheritance_from_gems(hash)
39
+ gems = hash.delete('inherit_gem')
39
40
  (gems || {}).each_pair do |gem_name, config_path|
40
41
  if gem_name == 'rubocop'
41
42
  raise ArgumentError,
@@ -4,10 +4,19 @@ module RuboCop
4
4
  # This class handles obsolete configuration.
5
5
  class ConfigObsoletion
6
6
  RENAMED_COPS = {
7
+ 'Lint/UnneededCopDisableDirective' => 'Lint/RedundantCopDisableDirective',
8
+ 'Lint/UnneededCopEnableDirective' => 'Lint/RedundantCopEnableDirective',
9
+ 'Lint/UnneededRequireStatement' => 'Lint/RedundantRequireStatement',
10
+ 'Lint/UnneededSplatExpansion' => 'Lint/RedundantSplatExpansion',
7
11
  'Style/SingleSpaceBeforeFirstArg' => 'Layout/SpaceBeforeFirstArg',
8
12
  'Style/MethodCallParentheses' => 'Style/MethodCallWithoutArgsParentheses',
9
13
  'Style/DeprecatedHashMethods' => 'Style/PreferredHashMethods',
10
14
  'Style/OpMethod' => 'Naming/BinaryOperatorParameterName',
15
+ 'Style/UnneededCapitalW' => 'Style/RedundantCapitalW',
16
+ 'Style/UnneededCondition' => 'Style/RedundantCondition',
17
+ 'Style/UnneededInterpolation' => 'Style/RedundantInterpolation',
18
+ 'Style/UnneededPercentQ' => 'Style/RedundantPercentQ',
19
+ 'Style/UnneededSort' => 'Style/RedundantSort',
11
20
  'Layout/FirstParameterIndentation' => 'Layout/IndentFirstArgument',
12
21
  'Layout/IndentArray' => 'Layout/IndentFirstArrayElement',
13
22
  'Layout/IndentHash' => 'Layout/IndentFirstHashElement'
@@ -10,8 +10,9 @@ module RuboCop
10
10
 
11
11
  COMMON_PARAMS = %w[Exclude Include Severity inherit_mode
12
12
  AutoCorrect StyleGuide Details].freeze
13
- INTERNAL_PARAMS = %w[Description StyleGuide VersionAdded
14
- VersionChanged Reference Safe SafeAutoCorrect].freeze
13
+ INTERNAL_PARAMS = %w[Description StyleGuide
14
+ VersionAdded VersionChanged VersionRemoved
15
+ Reference Safe SafeAutoCorrect].freeze
15
16
 
16
17
  # 2.3 is the oldest officially supported Ruby version.
17
18
  DEFAULT_RUBY_VERSION = 2.3
@@ -32,10 +33,7 @@ module RuboCop
32
33
 
33
34
  def validate
34
35
  # Don't validate RuboCop's own files. Avoids infinite recursion.
35
- base_config_path = File.expand_path(File.join(ConfigLoader::RUBOCOP_HOME,
36
- 'config'))
37
- return if File.expand_path(@config.loaded_path)
38
- .start_with?(base_config_path)
36
+ return if @config.internal?
39
37
 
40
38
  valid_cop_names, invalid_cop_names = @config.keys.partition do |key|
41
39
  ConfigLoader.default_configuration.key?(key)
@@ -128,21 +126,32 @@ module RuboCop
128
126
  def validate_parameter_names(valid_cop_names)
129
127
  valid_cop_names.each do |name|
130
128
  validate_section_presence(name)
131
- default_config = ConfigLoader.default_configuration[name]
129
+ each_invalid_parameter(name) do |param, supported_params|
130
+ # FIXME: Remove .to_s, which works around a JRuby bug:
131
+ # https://github.com/jruby/jruby/issues/5935
132
+ warn Rainbow(<<~MESSAGE).yellow.to_s
133
+ Warning: #{name} does not support #{param} parameter.
132
134
 
133
- @config[name].each_key do |param|
134
- next if COMMON_PARAMS.include?(param) || default_config.key?(param)
135
+ Supported parameters are:
135
136
 
136
- message =
137
- "Warning: #{name} does not support #{param} parameter.\n\n" \
138
- "Supported parameters are:\n\n" \
139
- " - #{(default_config.keys - INTERNAL_PARAMS).join("\n - ")}\n"
140
-
141
- warn Rainbow(message).yellow.to_s
137
+ - #{supported_params.join("\n - ")}
138
+ MESSAGE
142
139
  end
143
140
  end
144
141
  end
145
142
 
143
+ def each_invalid_parameter(cop_name)
144
+ default_config = ConfigLoader.default_configuration[cop_name]
145
+
146
+ @config[cop_name].each_key do |param|
147
+ next if COMMON_PARAMS.include?(param) || default_config.key?(param)
148
+
149
+ supported_params = default_config.keys - INTERNAL_PARAMS
150
+
151
+ yield param, supported_params
152
+ end
153
+ end
154
+
146
155
  def validate_enforced_styles(valid_cop_names)
147
156
  valid_cop_names.each do |name|
148
157
  styles = @config[name].select { |key, _| key.start_with?('Enforced') }