rubocop 1.19.0 → 1.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +86 -14
  4. data/lib/rubocop/config.rb +5 -0
  5. data/lib/rubocop/config_loader.rb +4 -2
  6. data/lib/rubocop/config_validator.rb +9 -1
  7. data/lib/rubocop/cop/base.rb +3 -3
  8. data/lib/rubocop/cop/bundler/gem_filename.rb +103 -0
  9. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +45 -21
  10. data/lib/rubocop/cop/bundler/ordered_gems.rb +3 -12
  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/ordered_gem_corrector.rb +11 -10
  14. data/lib/rubocop/cop/documentation.rb +1 -1
  15. data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +3 -12
  16. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +1 -1
  17. data/lib/rubocop/cop/generator.rb +14 -8
  18. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  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/dot_position.rb +25 -2
  22. data/lib/rubocop/cop/layout/end_alignment.rb +1 -1
  23. data/lib/rubocop/cop/layout/leading_comment_space.rb +1 -1
  24. data/lib/rubocop/cop/layout/line_length.rb +8 -6
  25. data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
  26. data/lib/rubocop/cop/layout/multiline_method_argument_line_breaks.rb +3 -0
  27. data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -0
  28. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +5 -4
  29. data/lib/rubocop/cop/layout/single_line_block_chain.rb +15 -4
  30. data/lib/rubocop/cop/layout/space_after_not.rb +1 -0
  31. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +2 -1
  32. data/lib/rubocop/cop/layout/space_around_keyword.rb +2 -2
  33. data/lib/rubocop/cop/layout/space_before_brackets.rb +1 -0
  34. data/lib/rubocop/cop/layout/space_inside_parens.rb +74 -24
  35. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +1 -1
  36. data/lib/rubocop/cop/lint/ambiguous_operator_precedence.rb +111 -0
  37. data/lib/rubocop/cop/lint/ambiguous_range.rb +8 -8
  38. data/lib/rubocop/cop/lint/assignment_in_condition.rb +7 -5
  39. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +18 -5
  40. data/lib/rubocop/cop/lint/boolean_symbol.rb +5 -0
  41. data/lib/rubocop/cop/lint/debugger.rb +2 -4
  42. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
  43. data/lib/rubocop/cop/lint/disjunctive_assignment_in_constructor.rb +24 -1
  44. data/lib/rubocop/cop/lint/else_layout.rb +9 -5
  45. data/lib/rubocop/cop/lint/empty_in_pattern.rb +1 -1
  46. data/lib/rubocop/cop/lint/erb_new_arguments.rb +1 -1
  47. data/lib/rubocop/cop/lint/float_out_of_range.rb +1 -1
  48. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +12 -3
  49. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +67 -0
  50. data/lib/rubocop/cop/lint/interpolation_check.rb +5 -0
  51. data/lib/rubocop/cop/lint/loop.rb +4 -3
  52. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +5 -1
  53. data/lib/rubocop/cop/lint/number_conversion.rb +12 -1
  54. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +1 -1
  55. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +4 -2
  56. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +17 -0
  57. data/lib/rubocop/cop/lint/percent_string_array.rb +10 -0
  58. data/lib/rubocop/cop/lint/raise_exception.rb +4 -0
  59. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +5 -4
  60. data/lib/rubocop/cop/lint/require_relative_self_path.rb +49 -0
  61. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +1 -1
  62. data/lib/rubocop/cop/lint/symbol_conversion.rb +1 -1
  63. data/lib/rubocop/cop/lint/triple_quotes.rb +1 -1
  64. data/lib/rubocop/cop/lint/unexpected_block_arity.rb +8 -3
  65. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -3
  66. data/lib/rubocop/cop/lint/useless_method_definition.rb +3 -2
  67. data/lib/rubocop/cop/lint/useless_setter_call.rb +7 -4
  68. data/lib/rubocop/cop/lint/useless_times.rb +4 -3
  69. data/lib/rubocop/cop/metrics/abc_size.rb +6 -0
  70. data/lib/rubocop/cop/metrics/perceived_complexity.rb +1 -1
  71. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +1 -1
  72. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  73. data/lib/rubocop/cop/mixin/annotation_comment.rb +57 -34
  74. data/lib/rubocop/cop/mixin/code_length.rb +1 -1
  75. data/lib/rubocop/cop/mixin/documentation_comment.rb +5 -2
  76. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +23 -1
  77. data/lib/rubocop/cop/mixin/heredoc.rb +1 -3
  78. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -2
  79. data/lib/rubocop/cop/mixin/ordered_gem_node.rb +9 -1
  80. data/lib/rubocop/cop/mixin/percent_array.rb +11 -3
  81. data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +9 -1
  82. data/lib/rubocop/cop/naming/ascii_identifiers.rb +0 -3
  83. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  84. data/lib/rubocop/cop/naming/constant_name.rb +1 -1
  85. data/lib/rubocop/cop/naming/inclusive_language.rb +9 -9
  86. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +5 -4
  87. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +7 -0
  88. data/lib/rubocop/cop/security/io_methods.rb +49 -0
  89. data/lib/rubocop/cop/security/json_load.rb +8 -7
  90. data/lib/rubocop/cop/security/open.rb +4 -0
  91. data/lib/rubocop/cop/security/yaml_load.rb +4 -0
  92. data/lib/rubocop/cop/style/accessor_grouping.rb +2 -2
  93. data/lib/rubocop/cop/style/and_or.rb +5 -0
  94. data/lib/rubocop/cop/style/arguments_forwarding.rb +13 -2
  95. data/lib/rubocop/cop/style/array_coercion.rb +21 -3
  96. data/lib/rubocop/cop/style/ascii_comments.rb +0 -3
  97. data/lib/rubocop/cop/style/block_delimiters.rb +23 -6
  98. data/lib/rubocop/cop/style/case_equality.rb +6 -9
  99. data/lib/rubocop/cop/style/case_like_if.rb +5 -0
  100. data/lib/rubocop/cop/style/class_and_module_children.rb +9 -0
  101. data/lib/rubocop/cop/style/collection_compact.rb +7 -5
  102. data/lib/rubocop/cop/style/collection_methods.rb +8 -6
  103. data/lib/rubocop/cop/style/combinable_loops.rb +3 -2
  104. data/lib/rubocop/cop/style/comment_annotation.rb +25 -39
  105. data/lib/rubocop/cop/style/commented_keyword.rb +4 -1
  106. data/lib/rubocop/cop/style/date_time.rb +5 -0
  107. data/lib/rubocop/cop/style/document_dynamic_eval_definition.rb +1 -1
  108. data/lib/rubocop/cop/style/documentation.rb +23 -8
  109. data/lib/rubocop/cop/style/double_negation.rb +27 -6
  110. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  111. data/lib/rubocop/cop/style/encoding.rb +26 -15
  112. data/lib/rubocop/cop/style/explicit_block_argument.rb +21 -11
  113. data/lib/rubocop/cop/style/float_division.rb +10 -2
  114. data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +7 -2
  115. data/lib/rubocop/cop/style/global_std_stream.rb +4 -0
  116. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +11 -0
  117. data/lib/rubocop/cop/style/hash_each_methods.rb +5 -0
  118. data/lib/rubocop/cop/style/hash_except.rb +4 -3
  119. data/lib/rubocop/cop/style/hash_transform_keys.rb +4 -6
  120. data/lib/rubocop/cop/style/hash_transform_values.rb +4 -6
  121. data/lib/rubocop/cop/style/identical_conditional_branches.rb +18 -16
  122. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +18 -4
  123. data/lib/rubocop/cop/style/infinite_loop.rb +4 -3
  124. data/lib/rubocop/cop/style/inverse_methods.rb +9 -2
  125. data/lib/rubocop/cop/style/lambda_call.rb +1 -1
  126. data/lib/rubocop/cop/style/line_end_concatenation.rb +13 -0
  127. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +6 -6
  128. data/lib/rubocop/cop/style/module_function.rb +8 -9
  129. data/lib/rubocop/cop/style/mutable_constant.rb +73 -6
  130. data/lib/rubocop/cop/style/negated_if.rb +1 -1
  131. data/lib/rubocop/cop/style/negated_unless.rb +1 -1
  132. data/lib/rubocop/cop/style/non_nil_check.rb +2 -2
  133. data/lib/rubocop/cop/style/not.rb +2 -2
  134. data/lib/rubocop/cop/style/numbered_parameters.rb +46 -0
  135. data/lib/rubocop/cop/style/numbered_parameters_limit.rb +50 -0
  136. data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
  137. data/lib/rubocop/cop/style/numeric_predicate.rb +5 -0
  138. data/lib/rubocop/cop/style/optional_arguments.rb +4 -0
  139. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +14 -4
  140. data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
  141. data/lib/rubocop/cop/style/percent_q_literals.rb +2 -2
  142. data/lib/rubocop/cop/style/preferred_hash_methods.rb +9 -4
  143. data/lib/rubocop/cop/style/raise_args.rb +1 -1
  144. data/lib/rubocop/cop/style/redundant_argument.rb +14 -7
  145. data/lib/rubocop/cop/style/redundant_begin.rb +25 -0
  146. data/lib/rubocop/cop/style/redundant_condition.rb +2 -3
  147. data/lib/rubocop/cop/style/redundant_fetch_block.rb +4 -0
  148. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +12 -3
  149. data/lib/rubocop/cop/style/redundant_freeze.rb +4 -4
  150. data/lib/rubocop/cop/style/redundant_interpolation.rb +1 -1
  151. data/lib/rubocop/cop/style/redundant_percent_q.rb +2 -3
  152. data/lib/rubocop/cop/style/redundant_self.rb +10 -0
  153. data/lib/rubocop/cop/style/redundant_self_assignment.rb +4 -3
  154. data/lib/rubocop/cop/style/redundant_self_assignment_branch.rb +23 -28
  155. data/lib/rubocop/cop/style/redundant_sort.rb +51 -18
  156. data/lib/rubocop/cop/style/regexp_literal.rb +3 -3
  157. data/lib/rubocop/cop/style/return_nil.rb +2 -1
  158. data/lib/rubocop/cop/style/safe_navigation.rb +13 -2
  159. data/lib/rubocop/cop/style/select_by_regexp.rb +106 -0
  160. data/lib/rubocop/cop/style/single_argument_dig.rb +5 -0
  161. data/lib/rubocop/cop/style/slicing_with_range.rb +13 -0
  162. data/lib/rubocop/cop/style/sole_nested_conditional.rb +4 -0
  163. data/lib/rubocop/cop/style/special_global_vars.rb +4 -0
  164. data/lib/rubocop/cop/style/static_class.rb +5 -5
  165. data/lib/rubocop/cop/style/string_chars.rb +4 -2
  166. data/lib/rubocop/cop/style/string_concatenation.rb +5 -1
  167. data/lib/rubocop/cop/style/string_hash_keys.rb +4 -0
  168. data/lib/rubocop/cop/style/struct_inheritance.rb +4 -0
  169. data/lib/rubocop/cop/style/swap_values.rb +4 -2
  170. data/lib/rubocop/cop/style/symbol_array.rb +3 -3
  171. data/lib/rubocop/cop/style/symbol_proc.rb +26 -0
  172. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +19 -0
  173. data/lib/rubocop/cop/style/trivial_accessors.rb +1 -1
  174. data/lib/rubocop/cop/style/word_array.rb +3 -3
  175. data/lib/rubocop/cop/style/yoda_condition.rb +24 -7
  176. data/lib/rubocop/cop/style/zero_length_predicate.rb +6 -0
  177. data/lib/rubocop/cop/util.rb +2 -2
  178. data/lib/rubocop/cops_documentation_generator.rb +17 -5
  179. data/lib/rubocop/magic_comment.rb +44 -15
  180. data/lib/rubocop/options.rb +126 -112
  181. data/lib/rubocop/result_cache.rb +1 -1
  182. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  183. data/lib/rubocop/rspec/expect_offense.rb +6 -2
  184. data/lib/rubocop/runner.rb +1 -2
  185. data/lib/rubocop/version.rb +1 -1
  186. data/lib/rubocop.rb +10 -2
  187. metadata +13 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 184ca6701160d34e5fe8f659e159842f397bfe07edbc27df159b7793fd8a0a3c
4
- data.tar.gz: d891042df8d86850afbf19b0d0e81f4255e909f0775b32eb675b3766d0266561
3
+ metadata.gz: '08520f6dcf324dcb95ce7191673f070e86c3b5c2613942d19e4c951119a43476'
4
+ data.tar.gz: 90fd28bb4692e3feb9973d0b711a181c90608b205741b4b68cc23df9a9d42142
5
5
  SHA512:
6
- metadata.gz: 6b0ed04638cfa650324684315fcf4c8a99b93fa66c1dce39efa7c76605bbd78a7c4e4b4d6fc6ac608d2ebbb52604f6f9fbccf23e5d097c637b1b6c879601d70b
7
- data.tar.gz: f1310e4f3a7285ecf642edf6e99500decb0d1aa74b676adf38ee6c65c9f1f4cf3124853102a50da51e896a6b9780b3db9156fa4e075f60139f01d239d13ab898
6
+ metadata.gz: 27a14f94b096be10618d7670ff591f4443ab4e09d8fce7f2604e686a1f7ab5544aaf53136c09a6ec62198f9f56950b5ab0c3cea64ee0ccd565e328b7ba131a5d
7
+ data.tar.gz: 419cf3d94cf235cf31b09d26cbed550937dcb1930797e3e28c97cfb27116b160732aeec5434de8e0c3417f6900bf795c1826d7941e49cf8f12e9a15c245472b4
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.19', require: false
57
+ gem 'rubocop', '~> 1.22', 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
@@ -130,7 +130,7 @@ AllCops:
130
130
  # What MRI version of the Ruby interpreter is the inspected code intended to
131
131
  # run on? (If there is more than one, set this to the lowest version.)
132
132
  # If a value is specified for TargetRubyVersion then it is used. Acceptable
133
- # values are specificed as a float (i.e. 3.0); the teeny version of Ruby
133
+ # values are specified as a float (i.e. 3.0); the teeny version of Ruby
134
134
  # should not be included. If the project specifies a Ruby version in the
135
135
  # .tool-versions or .ruby-version files, Gemfile or gems.rb file, RuboCop will
136
136
  # try to determine the desired version of Ruby by inspecting the
@@ -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
@@ -195,6 +209,7 @@ Bundler/InsecureProtocolSource:
195
209
  'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
196
210
  Enabled: true
197
211
  VersionAdded: '0.50'
212
+ AllowHttpProtocol: true
198
213
  Include:
199
214
  - '**/*.gemfile'
200
215
  - '**/Gemfile'
@@ -943,7 +958,6 @@ Layout/LineLength:
943
958
  Enabled: true
944
959
  VersionAdded: '0.25'
945
960
  VersionChanged: '1.4'
946
- AutoCorrect: true
947
961
  Max: 120
948
962
  # To make it possible to copy or click on URIs in the code, we allow lines
949
963
  # containing a URI to be longer than Max.
@@ -1347,10 +1361,11 @@ Layout/SpaceInsideParens:
1347
1361
  StyleGuide: '#spaces-braces'
1348
1362
  Enabled: true
1349
1363
  VersionAdded: '0.49'
1350
- VersionChanged: '0.55'
1364
+ VersionChanged: '1.22'
1351
1365
  EnforcedStyle: no_space
1352
1366
  SupportedStyles:
1353
1367
  - space
1368
+ - compact
1354
1369
  - no_space
1355
1370
 
1356
1371
  Layout/SpaceInsidePercentLiteralDelimiters:
@@ -1434,6 +1449,13 @@ Lint/AmbiguousOperator:
1434
1449
  VersionAdded: '0.17'
1435
1450
  VersionChanged: '0.83'
1436
1451
 
1452
+ Lint/AmbiguousOperatorPrecedence:
1453
+ Description: >-
1454
+ Checks for expressions containing multiple binary operations with
1455
+ ambiguous precedence.
1456
+ Enabled: pending
1457
+ VersionAdded: '1.21'
1458
+
1437
1459
  Lint/AmbiguousRange:
1438
1460
  Description: Checks for ranges with ambiguous boundaries.
1439
1461
  Enabled: pending
@@ -1471,9 +1493,9 @@ Lint/BinaryOperatorWithIdenticalOperands:
1471
1493
  Lint/BooleanSymbol:
1472
1494
  Description: 'Check for `:true` and `:false` symbols.'
1473
1495
  Enabled: true
1474
- Safe: false
1496
+ SafeAutoCorrect: false
1475
1497
  VersionAdded: '0.50'
1476
- VersionChanged: '0.83'
1498
+ VersionChanged: '1.22'
1477
1499
 
1478
1500
  Lint/CircularArgumentReference:
1479
1501
  Description: "Default values in optional keyword arguments and optional ordinal arguments should not refer back to the name of the argument."
@@ -1519,6 +1541,11 @@ Lint/Debugger:
1519
1541
  Capybara:
1520
1542
  - save_and_open_page
1521
1543
  - save_and_open_screenshot
1544
+ debug.rb:
1545
+ - binding.b
1546
+ - binding.break
1547
+ - Kernel.binding.b
1548
+ - Kernel.binding.break
1522
1549
  Pry:
1523
1550
  - binding.pry
1524
1551
  - binding.remote_pry
@@ -1527,6 +1554,8 @@ Lint/Debugger:
1527
1554
  Rails:
1528
1555
  - debugger
1529
1556
  - Kernel.debugger
1557
+ RubyJard:
1558
+ - jard
1530
1559
  WebConsole:
1531
1560
  - binding.console
1532
1561
 
@@ -1750,6 +1779,11 @@ Lint/ImplicitStringConcatenation:
1750
1779
  Enabled: true
1751
1780
  VersionAdded: '0.36'
1752
1781
 
1782
+ Lint/IncompatibleIoSelectWithFiberScheduler:
1783
+ Description: 'Checks for `IO.select` that is incompatible with Fiber Scheduler.'
1784
+ Enabled: pending
1785
+ VersionAdded: '1.21'
1786
+
1753
1787
  Lint/IneffectiveAccessModifier:
1754
1788
  Description: >-
1755
1789
  Checks for attempts to use `private` or `protected` to set
@@ -2013,6 +2047,11 @@ Lint/RequireParentheses:
2013
2047
  Enabled: true
2014
2048
  VersionAdded: '0.18'
2015
2049
 
2050
+ Lint/RequireRelativeSelfPath:
2051
+ Description: 'Checks for uses a file requiring itself with `require_relative`.'
2052
+ Enabled: pending
2053
+ VersionAdded: '1.22'
2054
+
2016
2055
  Lint/RescueException:
2017
2056
  Description: 'Avoid rescuing the Exception class.'
2018
2057
  StyleGuide: '#no-blind-rescues'
@@ -2542,8 +2581,9 @@ Naming/HeredocDelimiterNaming:
2542
2581
 
2543
2582
  Naming/InclusiveLanguage:
2544
2583
  Description: 'Recommend the use of inclusive language instead of problematic terms.'
2545
- Enabled: pending
2584
+ Enabled: false
2546
2585
  VersionAdded: '1.18'
2586
+ VersionChanged: '1.21'
2547
2587
  CheckIdentifiers: true
2548
2588
  CheckConstants: true
2549
2589
  CheckVariables: true
@@ -2699,6 +2739,14 @@ Security/Eval:
2699
2739
  Enabled: true
2700
2740
  VersionAdded: '0.47'
2701
2741
 
2742
+ Security/IoMethods:
2743
+ Description: >-
2744
+ Checks for the first argument to `IO.read`, `IO.binread`, `IO.write`, `IO.binwrite`,
2745
+ `IO.foreach`, and `IO.readlines`.
2746
+ Enabled: pending
2747
+ Safe: false
2748
+ VersionAdded: '1.22'
2749
+
2702
2750
  Security/JSONLoad:
2703
2751
  Description: >-
2704
2752
  Prefer usage of `JSON.parse` over `JSON.load` due to potential
@@ -2775,8 +2823,9 @@ Style/AndOr:
2775
2823
  Description: 'Use &&/|| instead of and/or.'
2776
2824
  StyleGuide: '#no-and-or-or'
2777
2825
  Enabled: true
2826
+ SafeAutoCorrect: false
2778
2827
  VersionAdded: '0.9'
2779
- VersionChanged: '0.25'
2828
+ VersionChanged: '1.21'
2780
2829
  # Whether `and` and `or` are banned only in conditionals (conditionals)
2781
2830
  # or completely (always).
2782
2831
  EnforcedStyle: conditionals
@@ -2810,9 +2859,9 @@ Style/ArrayJoin:
2810
2859
  Style/AsciiComments:
2811
2860
  Description: 'Use only ascii symbols in comments.'
2812
2861
  StyleGuide: '#english-comments'
2813
- Enabled: true
2862
+ Enabled: false
2814
2863
  VersionAdded: '0.9'
2815
- VersionChanged: '0.52'
2864
+ VersionChanged: '1.21'
2816
2865
  AllowedChars:
2817
2866
  - ©
2818
2867
 
@@ -2974,7 +3023,7 @@ Style/CaseEquality:
2974
3023
  Enabled: true
2975
3024
  VersionAdded: '0.9'
2976
3025
  VersionChanged: '0.89'
2977
- # If AllowOnConstant is enabled, the cop will ignore violations when the receiver of
3026
+ # If `AllowOnConstant` option is enabled, the cop will ignore violations when the receiver of
2978
3027
  # the case equality operator is a constant.
2979
3028
  #
2980
3029
  # # bad
@@ -3149,7 +3198,7 @@ Style/CommentAnnotation:
3149
3198
  StyleGuide: '#annotate-keywords'
3150
3199
  Enabled: true
3151
3200
  VersionAdded: '0.10'
3152
- VersionChanged: '1.3'
3201
+ VersionChanged: '1.20'
3153
3202
  Keywords:
3154
3203
  - TODO
3155
3204
  - FIXME
@@ -3669,7 +3718,7 @@ Style/InPatternThen:
3669
3718
  Style/InfiniteLoop:
3670
3719
  Description: >-
3671
3720
  Use Kernel#loop for infinite loops.
3672
- This cop is unsafe in the body may raise a `StopIteration` exception.
3721
+ This cop is unsafe if the body may raise a `StopIteration` exception.
3673
3722
  Safe: false
3674
3723
  StyleGuide: '#infinite-loop'
3675
3724
  Enabled: true
@@ -4095,6 +4144,21 @@ Style/Not:
4095
4144
  VersionAdded: '0.9'
4096
4145
  VersionChanged: '0.20'
4097
4146
 
4147
+ Style/NumberedParameters:
4148
+ Description: 'Restrict the usage of numbered parameters.'
4149
+ Enabled: pending
4150
+ VersionAdded: '1.22'
4151
+ EnforcedStyle: allow_single_line
4152
+ SupportedStyles:
4153
+ - allow_single_line
4154
+ - disallow
4155
+
4156
+ Style/NumberedParametersLimit:
4157
+ Description: 'Avoid excessive numbered params in a single block.'
4158
+ Enabled: pending
4159
+ VersionAdded: '1.22'
4160
+ Max: 1
4161
+
4098
4162
  Style/NumericLiteralPrefix:
4099
4163
  Description: 'Use smallcase prefixes for numeric literals.'
4100
4164
  StyleGuide: '#numeric-literal-prefixes'
@@ -4105,7 +4169,6 @@ Style/NumericLiteralPrefix:
4105
4169
  - zero_with_o
4106
4170
  - zero_only
4107
4171
 
4108
-
4109
4172
  Style/NumericLiterals:
4110
4173
  Description: >-
4111
4174
  Add underscores to large numeric literals to improve their
@@ -4426,6 +4489,8 @@ Style/RedundantSort:
4426
4489
  `max_by` instead of `sort_by...last`, etc.
4427
4490
  Enabled: true
4428
4491
  VersionAdded: '0.76'
4492
+ VersionChanged: '1.22'
4493
+ Safe: false
4429
4494
 
4430
4495
  Style/RedundantSortBy:
4431
4496
  Description: 'Use `sort` instead of `sort_by { |x| x }`.'
@@ -4506,6 +4571,12 @@ Style/Sample:
4506
4571
  Enabled: true
4507
4572
  VersionAdded: '0.30'
4508
4573
 
4574
+ Style/SelectByRegexp:
4575
+ Description: 'Prefer grep/grep_v to select/reject with a regexp match.'
4576
+ Enabled: pending
4577
+ SafeAutoCorrect: false
4578
+ VersionAdded: '1.22'
4579
+
4509
4580
  Style/SelfAssignment:
4510
4581
  Description: >-
4511
4582
  Checks for places where self-assignment shorthand should have
@@ -4692,8 +4763,9 @@ Style/StructInheritance:
4692
4763
  Description: 'Checks for inheritance from Struct.new.'
4693
4764
  StyleGuide: '#no-extend-struct-new'
4694
4765
  Enabled: true
4766
+ SafeAutoCorrect: false
4695
4767
  VersionAdded: '0.29'
4696
- VersionChanged: '0.86'
4768
+ VersionChanged: '1.20'
4697
4769
 
4698
4770
  Style/SwapValues:
4699
4771
  Description: 'This cop enforces the use of shorthand-style swapping of 2 variables.'
@@ -51,6 +51,11 @@ module RuboCop
51
51
  self
52
52
  end
53
53
 
54
+ def validate_after_resolution
55
+ @validator.validate_after_resolution
56
+ self
57
+ end
58
+
54
59
  def_delegators :@hash, :[], :[]=, :delete, :dig, :each, :key?, :keys, :each_key,
55
60
  :fetch, :map, :merge, :replace, :to_h, :to_hash, :transform_values
56
61
  def_delegators :@validator, :validate, :target_ruby_version
@@ -101,6 +101,8 @@ module RuboCop
101
101
  return default_configuration if config_file == DEFAULT_FILE
102
102
 
103
103
  config = load_file(config_file, check: check)
104
+ config.validate_after_resolution if check
105
+
104
106
  if ignore_parent_exclusion?
105
107
  print 'Ignoring AllCops/Exclude from parent folders' if debug?
106
108
  else
@@ -143,7 +145,7 @@ module RuboCop
143
145
  PENDING_BANNER = <<~BANNER
144
146
  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
147
 
146
- Please also note that can also opt-in to new cops by default by adding this to your config:
148
+ Please also note that you can opt-in to new cops by default by adding this to your config:
147
149
  AllCops:
148
150
  NewCops: enable
149
151
  BANNER
@@ -161,7 +163,7 @@ module RuboCop
161
163
  def warn_pending_cop(cop)
162
164
  version = cop.metadata['VersionAdded'] || 'N/A'
163
165
 
164
- warn Rainbow("#{cop.name}: # (new in #{version})").yellow
166
+ warn Rainbow("#{cop.name}: # new in #{version}").yellow
165
167
  warn Rainbow(' Enabled: true').yellow
166
168
  end
167
169
 
@@ -44,7 +44,6 @@ module RuboCop
44
44
  check_obsoletions
45
45
 
46
46
  alert_about_unrecognized_cops(invalid_cop_names)
47
- check_target_ruby
48
47
  validate_new_cops_parameter
49
48
  validate_parameter_names(valid_cop_names)
50
49
  validate_enforced_styles(valid_cop_names)
@@ -52,6 +51,15 @@ module RuboCop
52
51
  reject_mutually_exclusive_defaults
53
52
  end
54
53
 
54
+ # Validations that should only be run after all config resolving has
55
+ # taken place:
56
+ # * The target ruby version is only checked once the entire inheritance
57
+ # chain has been loaded so that only the final value is validated, and
58
+ # any obsolete but overridden values are ignored.
59
+ def validate_after_resolution
60
+ check_target_ruby
61
+ end
62
+
55
63
  def target_ruby_version
56
64
  target_ruby.version
57
65
  end
@@ -24,7 +24,7 @@ module RuboCop
24
24
  # `add_global_offense`. Use the `processed_source` method to
25
25
  # get the currently processed source being investigated.
26
26
  #
27
- # In case of invalid syntax / unparseable content,
27
+ # In case of invalid syntax / unparsable content,
28
28
  # the callback `on_other_file` is called instead of all the other
29
29
  # `on_...` callbacks.
30
30
  #
@@ -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
@@ -3,18 +3,21 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module Bundler
6
- # The symbol argument `:gemcutter`, `:rubygems`, and `:rubyforge`
7
- # are deprecated. So please change your source to URL string that
8
- # 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
6
+ # Passing symbol arguments to `source` (e.g. `source :rubygems`) is
7
+ # deprecated because they default to using HTTP requests. Instead, specify
8
+ # `'https://rubygems.org'` if possible, or `'http://rubygems.org'` if not.
9
9
  #
10
- # This autocorrect will replace these symbols with 'https://rubygems.org'.
11
- # Because it is secure, HTTPS request is strongly recommended. And in
12
- # most use cases HTTPS will be fine.
10
+ # When autocorrecting, this cop will replace symbol arguments with
11
+ # `'https://rubygems.org'`.
13
12
  #
14
- # However, it don't replace all `sources` of `http://` with `https://`.
15
- # For example, when specifying an internal gem server using HTTP on the
16
- # intranet, a use case where HTTPS cannot be specified was considered.
17
- # Consider using HTTP only if you cannot use HTTPS.
13
+ # This cop will not replace existing sources that use `http://`. This may
14
+ # be necessary where HTTPS is not available. For example, where using an
15
+ # internal gem server via an intranet, or where HTTPS is prohibited.
16
+ # However, you should strongly prefer `https://` where possible, as it is
17
+ # more secure.
18
+ #
19
+ # If you don't allow `http://`, please set `false` to `AllowHttpProtocol`.
20
+ # This option is `true` by default for safe autocorrection.
18
21
  #
19
22
  # @example
20
23
  # # bad
@@ -24,7 +27,17 @@ module RuboCop
24
27
  #
25
28
  # # good
26
29
  # source 'https://rubygems.org' # strongly recommended
30
+ #
31
+ # @example AllowHttpProtocol: true (default)
32
+ #
33
+ # # good
34
+ # source 'http://rubygems.org' # use only if HTTPS is unavailable
35
+ #
36
+ # @example AllowHttpProtocol: false
37
+ #
38
+ # # bad
27
39
  # source 'http://rubygems.org'
40
+ #
28
41
  class InsecureProtocolSource < Base
29
42
  include RangeHelp
30
43
  extend AutoCorrector
@@ -33,29 +46,40 @@ module RuboCop
33
46
  'are insecure. ' \
34
47
  "Please change your source to 'https://rubygems.org' " \
35
48
  "if possible, or 'http://rubygems.org' if not."
49
+ MSG_HTTP_PROTOCOL = 'Use `https://rubygems.org` instead of `http://rubygems.org`.'
36
50
 
37
51
  RESTRICT_ON_SEND = %i[source].freeze
38
52
 
39
53
  # @!method insecure_protocol_source?(node)
40
54
  def_node_matcher :insecure_protocol_source?, <<~PATTERN
41
55
  (send nil? :source
42
- $(sym ${:gemcutter :rubygems :rubyforge}))
56
+ ${(sym :gemcutter) (sym :rubygems) (sym :rubyforge) (:str "http://rubygems.org")})
43
57
  PATTERN
44
58
 
45
59
  def on_send(node)
46
- insecure_protocol_source?(node) do |source_node, source|
47
- message = format(MSG, source: source)
48
-
49
- add_offense(
50
- source_node,
51
- message: message
52
- ) do |corrector|
53
- corrector.replace(
54
- source_node, "'https://rubygems.org'"
55
- )
60
+ insecure_protocol_source?(node) do |source_node|
61
+ source = source_node.value
62
+ use_http_protocol = source == 'http://rubygems.org'
63
+
64
+ return if allow_http_protocol? && use_http_protocol
65
+
66
+ message = if use_http_protocol
67
+ MSG_HTTP_PROTOCOL
68
+ else
69
+ format(MSG, source: source)
70
+ end
71
+
72
+ add_offense(source_node, message: message) do |corrector|
73
+ corrector.replace(source_node, "'https://rubygems.org'")
56
74
  end
57
75
  end
58
76
  end
77
+
78
+ private
79
+
80
+ def allow_http_protocol?
81
+ cop_config.fetch('AllowHttpProtocol', true)
82
+ end
59
83
  end
60
84
  end
61
85
  end
@@ -24,15 +24,15 @@ module RuboCop
24
24
  # gem 'rubocop'
25
25
  # # For tests
26
26
  # gem 'rspec'
27
- class OrderedGems < Cop # rubocop:disable InternalAffairs/InheritDeprecatedCopClass
28
- include ConfigurableEnforcedStyle
27
+ class OrderedGems < Base
28
+ extend AutoCorrector
29
29
  include OrderedGemNode
30
30
 
31
31
  MSG = 'Gems should be sorted in an alphabetical order within their '\
32
32
  'section of the Gemfile. '\
33
33
  'Gem `%<previous>s` should appear before `%<current>s`.'
34
34
 
35
- def investigate(processed_source)
35
+ def on_new_investigation
36
36
  return if processed_source.blank?
37
37
 
38
38
  gem_declarations(processed_source.ast)
@@ -44,15 +44,6 @@ module RuboCop
44
44
  end
45
45
  end
46
46
 
47
- def autocorrect(node)
48
- OrderedGemCorrector.correct(
49
- processed_source,
50
- node,
51
- previous_declaration(node),
52
- treat_comments_as_separators
53
- )
54
- end
55
-
56
47
  private
57
48
 
58
49
  def previous_declaration(node)
@@ -87,8 +87,8 @@ module RuboCop
87
87
  end
88
88
 
89
89
  def needs_separating_space?
90
- block_begin.begin_pos == arguments_end_pos &&
91
- selector_end.end_pos == arguments_begin_pos ||
90
+ (block_begin.begin_pos == arguments_end_pos &&
91
+ selector_end.end_pos == arguments_begin_pos) ||
92
92
  block_begin.begin_pos == selector_end.end_pos
93
93
  end
94
94
 
@@ -28,7 +28,7 @@ module RuboCop
28
28
  indent_steps: 1)
29
29
  corrector.insert_before(
30
30
  range,
31
- "\n#{' ' * (node.loc.keyword.column + indent_steps * configured_width)}"
31
+ "\n#{' ' * (node.loc.keyword.column + (indent_steps * configured_width))}"
32
32
  )
33
33
  end
34
34
 
@@ -4,9 +4,10 @@ module RuboCop
4
4
  module Cop
5
5
  # This auto-corrects gem dependency order
6
6
  class OrderedGemCorrector
7
- extend OrderedGemNode
8
-
9
7
  class << self
8
+ include OrderedGemNode
9
+ include RangeHelp
10
+
10
11
  attr_reader :processed_source, :comments_as_separators
11
12
 
12
13
  def correct(processed_source, node,
@@ -17,24 +18,24 @@ module RuboCop
17
18
  current_range = declaration_with_comment(node)
18
19
  previous_range = declaration_with_comment(previous_declaration)
19
20
 
20
- ->(corrector) do swap_range(corrector, current_range, previous_range) end
21
+ ->(corrector) { swap_range(corrector, current_range, previous_range) }
21
22
  end
22
23
 
23
24
  private
24
25
 
25
26
  def declaration_with_comment(node)
26
27
  buffer = processed_source.buffer
27
- begin_pos = get_source_range(node, comments_as_separators).begin_pos
28
+ begin_pos = range_by_whole_lines(get_source_range(node, comments_as_separators)).begin_pos
28
29
  end_line = buffer.line_for_position(node.loc.expression.end_pos)
29
- end_pos = buffer.line_range(end_line).end_pos
30
- Parser::Source::Range.new(buffer, begin_pos, end_pos)
30
+ end_pos = range_by_whole_lines(buffer.line_range(end_line),
31
+ include_final_newline: true).end_pos
32
+
33
+ range_between(begin_pos, end_pos)
31
34
  end
32
35
 
33
36
  def swap_range(corrector, range1, range2)
34
- src1 = range1.source
35
- src2 = range2.source
36
- corrector.replace(range1, src2)
37
- corrector.replace(range2, src1)
37
+ corrector.insert_before(range2, range1.source)
38
+ corrector.remove(range1)
38
39
  end
39
40
  end
40
41
  end