rubocop 1.18.4 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +65 -13
  4. data/lib/rubocop/cli.rb +18 -0
  5. data/lib/rubocop/config_loader.rb +2 -2
  6. data/lib/rubocop/config_loader_resolver.rb +21 -6
  7. data/lib/rubocop/cop/base.rb +2 -2
  8. data/lib/rubocop/cop/bundler/gem_filename.rb +103 -0
  9. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +12 -11
  10. data/lib/rubocop/cop/bundler/ordered_gems.rb +1 -1
  11. data/lib/rubocop/cop/correctors/lambda_literal_to_method_corrector.rb +2 -2
  12. data/lib/rubocop/cop/correctors/line_break_corrector.rb +1 -1
  13. data/lib/rubocop/cop/correctors/require_library_corrector.rb +23 -0
  14. data/lib/rubocop/cop/documentation.rb +1 -1
  15. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
  16. data/lib/rubocop/cop/internal_affairs/inherit_deprecated_cop_class.rb +34 -0
  17. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +71 -0
  18. data/lib/rubocop/cop/internal_affairs.rb +2 -0
  19. data/lib/rubocop/cop/layout/argument_alignment.rb +1 -1
  20. data/lib/rubocop/cop/layout/class_structure.rb +2 -1
  21. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +9 -0
  22. data/lib/rubocop/cop/layout/end_alignment.rb +3 -2
  23. data/lib/rubocop/cop/layout/hash_alignment.rb +7 -3
  24. data/lib/rubocop/cop/layout/heredoc_indentation.rb +0 -7
  25. data/lib/rubocop/cop/layout/leading_comment_space.rb +2 -2
  26. data/lib/rubocop/cop/layout/line_end_string_concatenation_indentation.rb +33 -14
  27. data/lib/rubocop/cop/layout/line_length.rb +1 -1
  28. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  29. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +3 -0
  30. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +22 -9
  31. data/lib/rubocop/cop/layout/single_line_block_chain.rb +15 -4
  32. data/lib/rubocop/cop/layout/space_after_not.rb +1 -0
  33. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -1
  34. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  35. data/lib/rubocop/cop/layout/space_around_operators.rb +8 -1
  36. data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -0
  37. data/lib/rubocop/cop/layout/space_before_comment.rb +1 -1
  38. data/lib/rubocop/cop/layout/space_inside_parens.rb +5 -5
  39. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
  40. data/lib/rubocop/cop/layout/trailing_whitespace.rb +24 -1
  41. data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +107 -0
  42. data/lib/rubocop/cop/lint/ambiguous_range.rb +105 -0
  43. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +5 -2
  44. data/lib/rubocop/cop/lint/debugger.rb +2 -4
  45. data/lib/rubocop/cop/lint/duplicate_methods.rb +8 -5
  46. data/lib/rubocop/cop/lint/empty_in_pattern.rb +1 -1
  47. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  48. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  49. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +67 -0
  50. data/lib/rubocop/cop/lint/number_conversion.rb +7 -1
  51. data/lib/rubocop/cop/lint/shadowed_argument.rb +1 -1
  52. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -3
  53. data/lib/rubocop/cop/lint/useless_times.rb +1 -1
  54. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
  55. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  56. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  57. data/lib/rubocop/cop/mixin/annotation_comment.rb +57 -34
  58. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  59. data/lib/rubocop/cop/mixin/documentation_comment.rb +5 -2
  60. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +19 -1
  61. data/lib/rubocop/cop/mixin/heredoc.rb +7 -0
  62. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -2
  63. data/lib/rubocop/cop/mixin/percent_array.rb +13 -7
  64. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +9 -1
  65. data/lib/rubocop/cop/mixin/require_library.rb +59 -0
  66. data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -1
  67. data/lib/rubocop/cop/naming/ascii_identifiers.rb +0 -3
  68. data/lib/rubocop/cop/naming/constant_name.rb +1 -1
  69. data/lib/rubocop/cop/naming/inclusive_language.rb +27 -10
  70. data/lib/rubocop/cop/style/accessor_grouping.rb +2 -2
  71. data/lib/rubocop/cop/style/and_or.rb +4 -0
  72. data/lib/rubocop/cop/style/ascii_comments.rb +0 -3
  73. data/lib/rubocop/cop/style/block_delimiters.rb +39 -6
  74. data/lib/rubocop/cop/style/case_equality.rb +6 -9
  75. data/lib/rubocop/cop/style/collection_methods.rb +2 -1
  76. data/lib/rubocop/cop/style/comment_annotation.rb +25 -39
  77. data/lib/rubocop/cop/style/commented_keyword.rb +2 -1
  78. data/lib/rubocop/cop/style/conditional_assignment.rb +19 -5
  79. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
  80. data/lib/rubocop/cop/style/documentation.rb +23 -8
  81. data/lib/rubocop/cop/style/double_negation.rb +12 -1
  82. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  83. data/lib/rubocop/cop/style/encoding.rb +26 -15
  84. data/lib/rubocop/cop/style/explicit_block_argument.rb +46 -11
  85. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
  86. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +11 -0
  87. data/lib/rubocop/cop/style/hash_except.rb +4 -3
  88. data/lib/rubocop/cop/style/hash_transform_keys.rb +0 -3
  89. data/lib/rubocop/cop/style/identical_conditional_branches.rb +30 -5
  90. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +3 -2
  91. data/lib/rubocop/cop/style/lambda_call.rb +1 -1
  92. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -6
  93. data/lib/rubocop/cop/style/method_def_parentheses.rb +10 -1
  94. data/lib/rubocop/cop/style/missing_else.rb +7 -0
  95. data/lib/rubocop/cop/style/mutable_constant.rb +68 -6
  96. data/lib/rubocop/cop/style/negated_if.rb +1 -1
  97. data/lib/rubocop/cop/style/negated_unless.rb +1 -1
  98. data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
  99. data/lib/rubocop/cop/style/not.rb +2 -2
  100. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
  101. data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
  102. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  103. data/lib/rubocop/cop/style/redundant_begin.rb +25 -0
  104. data/lib/rubocop/cop/style/redundant_condition.rb +2 -3
  105. data/lib/rubocop/cop/style/redundant_freeze.rb +4 -3
  106. data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
  107. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -3
  108. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +83 -0
  109. data/lib/rubocop/cop/style/redundant_sort.rb +19 -4
  110. data/lib/rubocop/cop/style/regexp_literal.rb +3 -3
  111. data/lib/rubocop/cop/style/return_nil.rb +2 -1
  112. data/lib/rubocop/cop/style/semicolon.rb +32 -24
  113. data/lib/rubocop/cop/style/single_line_block_params.rb +3 -1
  114. data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -0
  115. data/lib/rubocop/cop/style/special_global_vars.rb +21 -0
  116. data/lib/rubocop/cop/style/static_class.rb +1 -2
  117. data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
  118. data/lib/rubocop/cop/style/struct_inheritance.rb +3 -0
  119. data/lib/rubocop/cop/style/symbol_array.rb +3 -3
  120. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  121. data/lib/rubocop/cop/style/word_array.rb +23 -5
  122. data/lib/rubocop/cop/style/yoda_condition.rb +4 -7
  123. data/lib/rubocop/cop/util.rb +7 -2
  124. data/lib/rubocop/magic_comment.rb +44 -15
  125. data/lib/rubocop/options.rb +1 -1
  126. data/lib/rubocop/result_cache.rb +1 -1
  127. data/lib/rubocop/runner.rb +1 -2
  128. data/lib/rubocop/version.rb +1 -1
  129. data/lib/rubocop.rb +9 -2
  130. metadata +14 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca5a85edf6c093ecee74e82617e0c618424e907cbb6a71fb1f996492073a98e4
4
- data.tar.gz: 1ceb28336ce8913d79d4260000f5a86ca93190f5e36f6809d690aa20559674fa
3
+ metadata.gz: dd3bb4ebea9d6db387e52e92a0c9ffac3f6215f0b5b9bcd7d555e979c8fb9fa7
4
+ data.tar.gz: 208d08bf57f092a0857776924cb529db1324ecdf4696476475f51878f803b6ac
5
5
  SHA512:
6
- metadata.gz: c020a6c2b13ad36e18afac1a2293f7c30fec5d2d62a36f5f7ffea8887816985ec27b94295fba1e08f9f1b7f462c8b4ca28a4949a32baadcea17e15ff4181b0e3
7
- data.tar.gz: 06e9a6431dc25b8152b0b380d4de434409579fcb0b66da5335b434798889fd8f6d6a58064a044595b1a45b2bad7830e8045011c7e20e64f1337ccdd11a04e29c
6
+ metadata.gz: 9d32668f49f495948628017c042cbc292d62c4ba93d905635d47ecba7c12e69ff7cbff3999a6cccba62bbc27ff7b51827e1a00f41769c1dd711f342fe10e8519
7
+ data.tar.gz: 9798e105b8ea95245d153e9e295a95a593e49464f91ac8c508ce0900f7f2ef0e97759a1144044f32acb726e11d3552de1f5de8d2d477151606bfd39090df3260
data/README.md CHANGED
@@ -54,7 +54,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
54
54
  in your `Gemfile`:
55
55
 
56
56
  ```rb
57
- gem 'rubocop', '~> 1.18', require: false
57
+ gem 'rubocop', '~> 1.21', require: false
58
58
  ```
59
59
 
60
60
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
data/config/default.yml CHANGED
@@ -174,6 +174,20 @@ Bundler/GemComment:
174
174
  IgnoredGems: []
175
175
  OnlyFor: []
176
176
 
177
+ Bundler/GemFilename:
178
+ Description: 'Enforces the filename for managing gems.'
179
+ Enabled: true
180
+ VersionAdded: '1.20'
181
+ EnforcedStyle: 'Gemfile'
182
+ SupportedStyles:
183
+ - 'Gemfile'
184
+ - 'gems.rb'
185
+ Include:
186
+ - '**/Gemfile'
187
+ - '**/gems.rb'
188
+ - '**/Gemfile.lock'
189
+ - '**/gems.locked'
190
+
177
191
  Bundler/GemVersion:
178
192
  Description: 'Requires or forbids specifying gem versions.'
179
193
  Enabled: false
@@ -943,7 +957,6 @@ Layout/LineLength:
943
957
  Enabled: true
944
958
  VersionAdded: '0.25'
945
959
  VersionChanged: '1.4'
946
- AutoCorrect: true
947
960
  Max: 120
948
961
  # To make it possible to copy or click on URIs in the code, we allow lines
949
962
  # containing a URI to be longer than Max.
@@ -1434,6 +1447,20 @@ Lint/AmbiguousOperator:
1434
1447
  VersionAdded: '0.17'
1435
1448
  VersionChanged: '0.83'
1436
1449
 
1450
+ Lint/AmbiguousOperatorPrecedence:
1451
+ Description: >-
1452
+ Checks for expressions containing multiple binary operations with
1453
+ ambiguous precedence.
1454
+ Enabled: pending
1455
+ VersionAdded: '1.21'
1456
+
1457
+ Lint/AmbiguousRange:
1458
+ Description: Checks for ranges with ambiguous boundaries.
1459
+ Enabled: pending
1460
+ VersionAdded: '1.19'
1461
+ SafeAutoCorrect: false
1462
+ RequireParenthesesForMethodChains: false
1463
+
1437
1464
  Lint/AmbiguousRegexpLiteral:
1438
1465
  Description: >-
1439
1466
  Checks for ambiguous regexp literals in the first argument of
@@ -1512,6 +1539,11 @@ Lint/Debugger:
1512
1539
  Capybara:
1513
1540
  - save_and_open_page
1514
1541
  - save_and_open_screenshot
1542
+ debug.rb:
1543
+ - binding.b
1544
+ - binding.break
1545
+ - Kernel.binding.b
1546
+ - Kernel.binding.break
1515
1547
  Pry:
1516
1548
  - binding.pry
1517
1549
  - binding.remote_pry
@@ -1520,6 +1552,8 @@ Lint/Debugger:
1520
1552
  Rails:
1521
1553
  - debugger
1522
1554
  - Kernel.debugger
1555
+ RubyJard:
1556
+ - jard
1523
1557
  WebConsole:
1524
1558
  - binding.console
1525
1559
 
@@ -1743,6 +1777,11 @@ Lint/ImplicitStringConcatenation:
1743
1777
  Enabled: true
1744
1778
  VersionAdded: '0.36'
1745
1779
 
1780
+ Lint/IncompatibleIoSelectWithFiberScheduler:
1781
+ Description: 'Checks for `IO.select` that is incompatible with Fiber Scheduler.'
1782
+ Enabled: pending
1783
+ VersionAdded: '1.21'
1784
+
1746
1785
  Lint/IneffectiveAccessModifier:
1747
1786
  Description: >-
1748
1787
  Checks for attempts to use `private` or `protected` to set
@@ -1824,7 +1863,6 @@ Lint/MultipleComparison:
1824
1863
  Enabled: true
1825
1864
  VersionAdded: '0.47'
1826
1865
  VersionChanged: '1.1'
1827
- AllowMethodComparison: true
1828
1866
 
1829
1867
  Lint/NestedMethodDefinition:
1830
1868
  Description: 'Do not use nested method definitions.'
@@ -2536,8 +2574,9 @@ Naming/HeredocDelimiterNaming:
2536
2574
 
2537
2575
  Naming/InclusiveLanguage:
2538
2576
  Description: 'Recommend the use of inclusive language instead of problematic terms.'
2539
- Enabled: pending
2577
+ Enabled: false
2540
2578
  VersionAdded: '1.18'
2579
+ VersionChanged: '1.21'
2541
2580
  CheckIdentifiers: true
2542
2581
  CheckConstants: true
2543
2582
  CheckVariables: true
@@ -2557,6 +2596,7 @@ Naming/InclusiveLanguage:
2557
2596
  - denylist
2558
2597
  - block
2559
2598
  slave:
2599
+ WholeWord: true
2560
2600
  Suggestions: ['replica', 'secondary', 'follower']
2561
2601
 
2562
2602
  Naming/MemoizedInstanceVariableName:
@@ -2768,8 +2808,9 @@ Style/AndOr:
2768
2808
  Description: 'Use &&/|| instead of and/or.'
2769
2809
  StyleGuide: '#no-and-or-or'
2770
2810
  Enabled: true
2811
+ SafeAutoCorrect: false
2771
2812
  VersionAdded: '0.9'
2772
- VersionChanged: '0.25'
2813
+ VersionChanged: '1.21'
2773
2814
  # Whether `and` and `or` are banned only in conditionals (conditionals)
2774
2815
  # or completely (always).
2775
2816
  EnforcedStyle: conditionals
@@ -2803,9 +2844,9 @@ Style/ArrayJoin:
2803
2844
  Style/AsciiComments:
2804
2845
  Description: 'Use only ascii symbols in comments.'
2805
2846
  StyleGuide: '#english-comments'
2806
- Enabled: true
2847
+ Enabled: false
2807
2848
  VersionAdded: '0.9'
2808
- VersionChanged: '0.52'
2849
+ VersionChanged: '1.21'
2809
2850
  AllowedChars:
2810
2851
  - ©
2811
2852
 
@@ -2967,7 +3008,7 @@ Style/CaseEquality:
2967
3008
  Enabled: true
2968
3009
  VersionAdded: '0.9'
2969
3010
  VersionChanged: '0.89'
2970
- # If AllowOnConstant is enabled, the cop will ignore violations when the receiver of
3011
+ # If `AllowOnConstant` option is enabled, the cop will ignore violations when the receiver of
2971
3012
  # the case equality operator is a constant.
2972
3013
  #
2973
3014
  # # bad
@@ -3142,7 +3183,7 @@ Style/CommentAnnotation:
3142
3183
  StyleGuide: '#annotate-keywords'
3143
3184
  Enabled: true
3144
3185
  VersionAdded: '0.10'
3145
- VersionChanged: '1.3'
3186
+ VersionChanged: '1.20'
3146
3187
  Keywords:
3147
3188
  - TODO
3148
3189
  - FIXME
@@ -3155,8 +3196,9 @@ Style/CommentAnnotation:
3155
3196
  Style/CommentedKeyword:
3156
3197
  Description: 'Do not place comments on the same line as certain keywords.'
3157
3198
  Enabled: true
3199
+ SafeAutoCorrect: false
3158
3200
  VersionAdded: '0.51'
3159
- VersionChanged: '1.7'
3201
+ VersionChanged: '1.19'
3160
3202
 
3161
3203
  Style/ConditionalAssignment:
3162
3204
  Description: >-
@@ -3603,8 +3645,9 @@ Style/IdenticalConditionalBranches:
3603
3645
  line at the end of each branch, which can validly be moved
3604
3646
  out of the conditional.
3605
3647
  Enabled: true
3648
+ SafeAutoCorrect: false
3606
3649
  VersionAdded: '0.36'
3607
- VersionChanged: '1.16'
3650
+ VersionChanged: '1.19'
3608
3651
 
3609
3652
  Style/IfInsideElse:
3610
3653
  Description: 'Finds if nodes inside else, which can be converted to elsif.'
@@ -3929,6 +3972,7 @@ Style/MultipleComparison:
3929
3972
  Enabled: true
3930
3973
  VersionAdded: '0.49'
3931
3974
  VersionChanged: '1.1'
3975
+ AllowMethodComparison: true
3932
3976
 
3933
3977
  Style/MutableConstant:
3934
3978
  Description: 'Do not assign mutable objects to constants.'
@@ -4152,6 +4196,7 @@ Style/OptionHash:
4152
4196
  - args
4153
4197
  - params
4154
4198
  - parameters
4199
+ Allowlist: []
4155
4200
 
4156
4201
  Style/OptionalArguments:
4157
4202
  Description: >-
@@ -4404,6 +4449,11 @@ Style/RedundantSelfAssignment:
4404
4449
  Safe: false
4405
4450
  VersionAdded: '0.90'
4406
4451
 
4452
+ Style/RedundantSelfAssignmentBranch:
4453
+ Description: 'Checks for places where conditional branch makes redundant self-assignment.'
4454
+ Enabled: pending
4455
+ VersionAdded: '1.19'
4456
+
4407
4457
  Style/RedundantSort:
4408
4458
  Description: >-
4409
4459
  Use `min` instead of `sort.first`,
@@ -4575,6 +4625,7 @@ Style/SpecialGlobalVars:
4575
4625
  VersionAdded: '0.13'
4576
4626
  VersionChanged: '0.36'
4577
4627
  SafeAutoCorrect: false
4628
+ RequireEnglish: true
4578
4629
  EnforcedStyle: use_english_names
4579
4630
  SupportedStyles:
4580
4631
  - use_perl_names
@@ -4675,8 +4726,9 @@ Style/StructInheritance:
4675
4726
  Description: 'Checks for inheritance from Struct.new.'
4676
4727
  StyleGuide: '#no-extend-struct-new'
4677
4728
  Enabled: true
4729
+ SafeAutoCorrect: false
4678
4730
  VersionAdded: '0.29'
4679
- VersionChanged: '0.86'
4731
+ VersionChanged: '1.20'
4680
4732
 
4681
4733
  Style/SwapValues:
4682
4734
  Description: 'This cop enforces the use of shorthand-style swapping of 2 variables.'
@@ -4895,7 +4947,7 @@ Style/VariableInterpolation:
4895
4947
 
4896
4948
  Style/WhenThen:
4897
4949
  Description: 'Use when x then ... for one-line cases.'
4898
- StyleGuide: '#one-line-cases'
4950
+ StyleGuide: '#no-when-semicolons'
4899
4951
  Enabled: true
4900
4952
  VersionAdded: '0.9'
4901
4953
 
@@ -4919,7 +4971,7 @@ Style/WordArray:
4919
4971
  StyleGuide: '#percent-w'
4920
4972
  Enabled: true
4921
4973
  VersionAdded: '0.9'
4922
- VersionChanged: '0.36'
4974
+ VersionChanged: '1.19'
4923
4975
  EnforcedStyle: percent
4924
4976
  SupportedStyles:
4925
4977
  # percent style: %w(word1 word2)
data/lib/rubocop/cli.rb CHANGED
@@ -8,6 +8,11 @@ module RuboCop
8
8
  STATUS_OFFENSES = 1
9
9
  STATUS_ERROR = 2
10
10
  STATUS_INTERRUPTED = 128 + Signal.list['INT']
11
+ DEFAULT_PARALLEL_OPTIONS = %i[
12
+ color debug display_style_guide display_time display_only_fail_level_offenses
13
+ display_only_failed except extra_details fail_level fix_layout format
14
+ ignore_disable_comments lint only only_guide_cops require safe
15
+ ].freeze
11
16
 
12
17
  class Finished < RuntimeError; end
13
18
 
@@ -37,6 +42,7 @@ module RuboCop
37
42
  else
38
43
  act_on_options
39
44
  validate_options_vs_config
45
+ parallel_by_default!
40
46
  apply_default_formatter
41
47
  execute_runners
42
48
  end
@@ -84,6 +90,18 @@ module RuboCop
84
90
  'with AllCops: UseCache: false is not allowed.'
85
91
  end
86
92
 
93
+ def parallel_by_default!
94
+ # See https://github.com/rubocop/rubocop/pull/4537 for JRuby and Windows constraints.
95
+ return if RUBY_ENGINE != 'ruby' || RuboCop::Platform.windows?
96
+
97
+ if (@options.keys - DEFAULT_PARALLEL_OPTIONS).empty? &&
98
+ @config_store.for_pwd.for_all_cops['UseCache'] != false
99
+ puts 'Use parallel by default.' if @options[:debug]
100
+
101
+ @options[:parallel] = true
102
+ end
103
+ end
104
+
87
105
  def act_on_options
88
106
  set_options_to_config_loader
89
107
 
@@ -143,7 +143,7 @@ module RuboCop
143
143
  PENDING_BANNER = <<~BANNER
144
144
  The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.
145
145
 
146
- Please also note that can also opt-in to new cops by default by adding this to your config:
146
+ Please also note that you can opt-in to new cops by default by adding this to your config:
147
147
  AllCops:
148
148
  NewCops: enable
149
149
  BANNER
@@ -161,7 +161,7 @@ module RuboCop
161
161
  def warn_pending_cop(cop)
162
162
  version = cop.metadata['VersionAdded'] || 'N/A'
163
163
 
164
- warn Rainbow("#{cop.name}: # (new in #{version})").yellow
164
+ warn Rainbow("#{cop.name}: # new in #{version}").yellow
165
165
  warn Rainbow(' Enabled: true').yellow
166
166
  end
167
167
 
@@ -108,7 +108,7 @@ module RuboCop
108
108
  result.delete(key)
109
109
  elsif merge_hashes?(base_hash, derived_hash, key)
110
110
  result[key] = merge(base_hash[key], derived_hash[key], **opts)
111
- elsif should_union?(base_hash, key, opts[:inherit_mode])
111
+ elsif should_union?(derived_hash, base_hash, opts[:inherit_mode], key)
112
112
  result[key] = base_hash[key] | derived_hash[key]
113
113
  elsif opts[:debug]
114
114
  warn_on_duplicate_setting(base_hash, derived_hash, key, **opts)
@@ -183,11 +183,26 @@ module RuboCop
183
183
  local_inherit || hash['inherit_mode'] || {}
184
184
  end
185
185
 
186
- def should_union?(base_hash, key, inherit_mode)
187
- base_hash[key].is_a?(Array) &&
188
- inherit_mode &&
189
- inherit_mode['merge'] &&
190
- inherit_mode['merge'].include?(key)
186
+ def should_union?(derived_hash, base_hash, root_mode, key)
187
+ return false unless base_hash[key].is_a?(Array)
188
+
189
+ derived_mode = derived_hash['inherit_mode']
190
+ return false if should_override?(derived_mode, key)
191
+ return true if should_merge?(derived_mode, key)
192
+
193
+ base_mode = base_hash['inherit_mode']
194
+ return false if should_override?(base_mode, key)
195
+ return true if should_merge?(base_mode, key)
196
+
197
+ should_merge?(root_mode, key)
198
+ end
199
+
200
+ def should_merge?(mode, key)
201
+ mode && mode['merge'] && mode['merge'].include?(key)
202
+ end
203
+
204
+ def should_override?(mode, key)
205
+ mode && mode['override'] && mode['override'].include?(key)
191
206
  end
192
207
 
193
208
  def merge_hashes?(base_hash, derived_hash, key)
@@ -222,8 +222,8 @@ module RuboCop
222
222
 
223
223
  def relevant_file?(file)
224
224
  file == RuboCop::AST::ProcessedSource::STRING_SOURCE_NAME ||
225
- file_name_matches_any?(file, 'Include', true) &&
226
- !file_name_matches_any?(file, 'Exclude', false)
225
+ (file_name_matches_any?(file, 'Include', true) &&
226
+ !file_name_matches_any?(file, 'Exclude', false))
227
227
  end
228
228
 
229
229
  def excluded_file?(file)
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Bundler
6
+ # This cop verifies that a project contains Gemfile or gems.rb file and correct
7
+ # associated lock file based on the configuration.
8
+ #
9
+ # @example EnforcedStyle: Gemfile (default)
10
+ # # bad
11
+ # Project contains gems.rb and gems.locked files
12
+ #
13
+ # # bad
14
+ # Project contains Gemfile and gems.locked file
15
+ #
16
+ # # good
17
+ # Project contains Gemfile and Gemfile.lock
18
+ #
19
+ # @example EnforcedStyle: gems.rb
20
+ # # bad
21
+ # Project contains Gemfile and Gemfile.lock files
22
+ #
23
+ # # bad
24
+ # Project contains gems.rb and Gemfile.lock file
25
+ #
26
+ # # good
27
+ # Project contains gems.rb and gems.locked files
28
+ class GemFilename < Base
29
+ include ConfigurableEnforcedStyle
30
+ include RangeHelp
31
+
32
+ MSG_GEMFILE_REQUIRED = '`gems.rb` file was found but `Gemfile` is required '\
33
+ '(file path: %<file_path>s).'
34
+ MSG_GEMS_RB_REQUIRED = '`Gemfile` was found but `gems.rb` file is required '\
35
+ '(file path: %<file_path>s).'
36
+ MSG_GEMFILE_MISMATCHED = 'Expected a `Gemfile.lock` with `Gemfile` but found '\
37
+ '`gems.locked` file (file path: %<file_path>s).'
38
+ MSG_GEMS_RB_MISMATCHED = 'Expected a `gems.locked` file with `gems.rb` but found '\
39
+ '`Gemfile.lock` (file path: %<file_path>s).'
40
+ GEMFILE_FILES = %w[Gemfile Gemfile.lock].freeze
41
+ GEMS_RB_FILES = %w[gems.rb gems.locked].freeze
42
+
43
+ def on_new_investigation
44
+ file_path = processed_source.file_path
45
+ basename = File.basename(file_path)
46
+ return if expected_gemfile?(basename)
47
+
48
+ register_offense(file_path, basename)
49
+ end
50
+
51
+ private
52
+
53
+ def register_offense(file_path, basename)
54
+ register_gemfile_offense(file_path, basename) if gemfile_offense?(basename)
55
+ register_gems_rb_offense(file_path, basename) if gems_rb_offense?(basename)
56
+ end
57
+
58
+ def register_gemfile_offense(file_path, basename)
59
+ message = case basename
60
+ when 'gems.rb'
61
+ MSG_GEMFILE_REQUIRED
62
+ when 'gems.locked'
63
+ MSG_GEMFILE_MISMATCHED
64
+ end
65
+
66
+ add_global_offense(format(message, file_path: file_path))
67
+ end
68
+
69
+ def register_gems_rb_offense(file_path, basename)
70
+ message = case basename
71
+ when 'Gemfile'
72
+ MSG_GEMS_RB_REQUIRED
73
+ when 'Gemfile.lock'
74
+ MSG_GEMS_RB_MISMATCHED
75
+ end
76
+
77
+ add_global_offense(format(message, file_path: file_path))
78
+ end
79
+
80
+ def gemfile_offense?(basename)
81
+ gemfile_required? && GEMS_RB_FILES.include?(basename)
82
+ end
83
+
84
+ def gems_rb_offense?(basename)
85
+ gems_rb_required? && GEMFILE_FILES.include?(basename)
86
+ end
87
+
88
+ def expected_gemfile?(basename)
89
+ (gemfile_required? && GEMFILE_FILES.include?(basename)) ||
90
+ (gems_rb_required? && GEMS_RB_FILES.include?(basename))
91
+ end
92
+
93
+ def gemfile_required?
94
+ style == :Gemfile
95
+ end
96
+
97
+ def gems_rb_required?
98
+ style == :'gems.rb'
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end