rubocop 0.90.0 → 0.93.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +79 -3
  4. data/lib/rubocop.rb +20 -5
  5. data/lib/rubocop/cached_data.rb +2 -1
  6. data/lib/rubocop/cli/command/execute_runner.rb +8 -0
  7. data/lib/rubocop/comment_config.rb +9 -5
  8. data/lib/rubocop/config_loader.rb +3 -3
  9. data/lib/rubocop/config_regeneration.rb +33 -0
  10. data/lib/rubocop/config_store.rb +3 -3
  11. data/lib/rubocop/cop/bundler/duplicated_gem.rb +5 -1
  12. data/lib/rubocop/cop/bundler/gem_comment.rb +1 -0
  13. data/lib/rubocop/cop/bundler/insecure_protocol_source.rb +2 -0
  14. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -2
  15. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +10 -10
  16. data/lib/rubocop/cop/generator.rb +1 -1
  17. data/lib/rubocop/cop/internal_affairs/method_name_equal.rb +1 -0
  18. data/lib/rubocop/cop/internal_affairs/node_type_predicate.rb +1 -0
  19. data/lib/rubocop/cop/internal_affairs/offense_location_keyword.rb +1 -0
  20. data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -0
  21. data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -0
  22. data/lib/rubocop/cop/layout/array_alignment.rb +1 -0
  23. data/lib/rubocop/cop/layout/begin_end_alignment.rb +77 -0
  24. data/lib/rubocop/cop/layout/case_indentation.rb +4 -7
  25. data/lib/rubocop/cop/layout/class_structure.rb +1 -1
  26. data/lib/rubocop/cop/layout/def_end_alignment.rb +1 -1
  27. data/lib/rubocop/cop/layout/dot_position.rb +6 -9
  28. data/lib/rubocop/cop/layout/empty_line_after_guard_clause.rb +2 -2
  29. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +4 -12
  30. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +13 -8
  31. data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +2 -2
  32. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +1 -2
  33. data/lib/rubocop/cop/layout/end_alignment.rb +5 -10
  34. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +26 -4
  35. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +4 -13
  36. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +7 -7
  37. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +0 -4
  38. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +6 -21
  39. data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +3 -8
  40. data/lib/rubocop/cop/layout/space_inside_string_interpolation.rb +2 -2
  41. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +2 -0
  42. data/lib/rubocop/cop/lint/ambiguous_operator.rb +2 -0
  43. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +18 -1
  44. data/lib/rubocop/cop/lint/big_decimal_new.rb +1 -2
  45. data/lib/rubocop/cop/lint/boolean_symbol.rb +3 -0
  46. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +74 -0
  47. data/lib/rubocop/cop/lint/debugger.rb +2 -3
  48. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +1 -3
  49. data/lib/rubocop/cop/lint/duplicate_methods.rb +2 -4
  50. data/lib/rubocop/cop/lint/duplicate_require.rb +7 -2
  51. data/lib/rubocop/cop/lint/duplicate_rescue_exception.rb +2 -4
  52. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -0
  53. data/lib/rubocop/cop/lint/empty_file.rb +1 -4
  54. data/lib/rubocop/cop/lint/erb_new_arguments.rb +2 -0
  55. data/lib/rubocop/cop/lint/float_comparison.rb +2 -2
  56. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +2 -2
  57. data/lib/rubocop/cop/lint/hash_compare_by_identity.rb +37 -0
  58. data/lib/rubocop/cop/lint/identity_comparison.rb +51 -0
  59. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +2 -5
  60. data/lib/rubocop/cop/lint/inherit_exception.rb +2 -2
  61. data/lib/rubocop/cop/lint/mixed_regexp_capture_types.rb +1 -0
  62. data/lib/rubocop/cop/lint/multiple_comparison.rb +3 -1
  63. data/lib/rubocop/cop/lint/number_conversion.rb +1 -0
  64. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -2
  65. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
  66. data/lib/rubocop/cop/lint/raise_exception.rb +1 -0
  67. data/lib/rubocop/cop/lint/rand_one.rb +2 -1
  68. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +22 -12
  69. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +14 -4
  70. data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -0
  71. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +78 -0
  72. data/lib/rubocop/cop/lint/rescue_type.rb +0 -1
  73. data/lib/rubocop/cop/lint/send_with_mixin_argument.rb +3 -1
  74. data/lib/rubocop/cop/lint/shadowed_exception.rb +6 -6
  75. data/lib/rubocop/cop/lint/struct_new_override.rb +1 -0
  76. data/lib/rubocop/cop/lint/to_json.rb +16 -5
  77. data/lib/rubocop/cop/lint/unreachable_loop.rb +3 -6
  78. data/lib/rubocop/cop/lint/uri_escape_unescape.rb +3 -1
  79. data/lib/rubocop/cop/lint/uri_regexp.rb +2 -1
  80. data/lib/rubocop/cop/lint/useless_access_modifier.rb +3 -9
  81. data/lib/rubocop/cop/lint/useless_method_definition.rb +20 -27
  82. data/lib/rubocop/cop/lint/useless_times.rb +106 -0
  83. data/lib/rubocop/cop/metrics/block_length.rb +3 -1
  84. data/lib/rubocop/cop/metrics/class_length.rb +14 -6
  85. data/lib/rubocop/cop/metrics/utils/abc_size_calculator.rb +25 -16
  86. data/lib/rubocop/cop/mixin/comments_help.rb +3 -9
  87. data/lib/rubocop/cop/mixin/configurable_naming.rb +2 -2
  88. data/lib/rubocop/cop/mixin/configurable_numbering.rb +3 -3
  89. data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +9 -0
  90. data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -2
  91. data/lib/rubocop/cop/mixin/rescue_node.rb +1 -0
  92. data/lib/rubocop/cop/mixin/statement_modifier.rb +9 -3
  93. data/lib/rubocop/cop/mixin/visibility_help.rb +4 -16
  94. data/lib/rubocop/cop/naming/binary_operator_parameter_name.rb +1 -1
  95. data/lib/rubocop/cop/naming/file_name.rb +1 -1
  96. data/lib/rubocop/cop/offense.rb +15 -2
  97. data/lib/rubocop/cop/security/eval.rb +1 -0
  98. data/lib/rubocop/cop/security/json_load.rb +1 -0
  99. data/lib/rubocop/cop/security/marshal_load.rb +1 -0
  100. data/lib/rubocop/cop/security/open.rb +1 -0
  101. data/lib/rubocop/cop/security/yaml_load.rb +1 -0
  102. data/lib/rubocop/cop/style/access_modifier_declarations.rb +7 -11
  103. data/lib/rubocop/cop/style/accessor_grouping.rb +3 -0
  104. data/lib/rubocop/cop/style/alias.rb +2 -0
  105. data/lib/rubocop/cop/style/array_coercion.rb +4 -0
  106. data/lib/rubocop/cop/style/array_join.rb +1 -0
  107. data/lib/rubocop/cop/style/attr.rb +1 -0
  108. data/lib/rubocop/cop/style/auto_resource_cleanup.rb +2 -0
  109. data/lib/rubocop/cop/style/case_equality.rb +3 -0
  110. data/lib/rubocop/cop/style/case_like_if.rb +20 -4
  111. data/lib/rubocop/cop/style/class_and_module_children.rb +2 -0
  112. data/lib/rubocop/cop/style/class_check.rb +6 -9
  113. data/lib/rubocop/cop/style/class_equality_comparison.rb +64 -0
  114. data/lib/rubocop/cop/style/class_methods_definitions.rb +42 -16
  115. data/lib/rubocop/cop/style/class_vars.rb +1 -2
  116. data/lib/rubocop/cop/style/combinable_loops.rb +13 -11
  117. data/lib/rubocop/cop/style/comment_annotation.rb +6 -0
  118. data/lib/rubocop/cop/style/commented_keyword.rb +7 -8
  119. data/lib/rubocop/cop/style/conditional_assignment.rb +49 -60
  120. data/lib/rubocop/cop/style/date_time.rb +12 -1
  121. data/lib/rubocop/cop/style/dir.rb +1 -0
  122. data/lib/rubocop/cop/style/double_negation.rb +1 -0
  123. data/lib/rubocop/cop/style/empty_literal.rb +3 -1
  124. data/lib/rubocop/cop/style/eval_with_location.rb +1 -3
  125. data/lib/rubocop/cop/style/even_odd.rb +1 -0
  126. data/lib/rubocop/cop/style/expand_path_arguments.rb +2 -2
  127. data/lib/rubocop/cop/style/explicit_block_argument.rb +7 -3
  128. data/lib/rubocop/cop/style/float_division.rb +2 -0
  129. data/lib/rubocop/cop/style/for.rb +0 -4
  130. data/lib/rubocop/cop/style/format_string.rb +1 -4
  131. data/lib/rubocop/cop/style/format_string_token.rb +1 -1
  132. data/lib/rubocop/cop/style/hash_as_last_array_item.rb +24 -5
  133. data/lib/rubocop/cop/style/hash_transform_keys.rb +5 -11
  134. data/lib/rubocop/cop/style/hash_transform_values.rb +5 -11
  135. data/lib/rubocop/cop/style/if_unless_modifier.rb +0 -4
  136. data/lib/rubocop/cop/style/implicit_runtime_error.rb +1 -0
  137. data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -6
  138. data/lib/rubocop/cop/style/lambda_call.rb +3 -1
  139. data/lib/rubocop/cop/style/method_def_parentheses.rb +0 -4
  140. data/lib/rubocop/cop/style/mixin_usage.rb +8 -27
  141. data/lib/rubocop/cop/style/multiline_block_chain.rb +2 -2
  142. data/lib/rubocop/cop/style/multiline_ternary_operator.rb +14 -1
  143. data/lib/rubocop/cop/style/multiline_when_then.rb +1 -0
  144. data/lib/rubocop/cop/style/nested_ternary_operator.rb +2 -0
  145. data/lib/rubocop/cop/style/nil_comparison.rb +2 -0
  146. data/lib/rubocop/cop/style/non_nil_check.rb +2 -0
  147. data/lib/rubocop/cop/style/not.rb +1 -0
  148. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -3
  149. data/lib/rubocop/cop/style/one_line_conditional.rb +3 -1
  150. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +12 -1
  151. data/lib/rubocop/cop/style/preferred_hash_methods.rb +2 -0
  152. data/lib/rubocop/cop/style/raise_args.rb +2 -3
  153. data/lib/rubocop/cop/style/random_with_offset.rb +4 -3
  154. data/lib/rubocop/cop/style/redundant_assignment.rb +1 -9
  155. data/lib/rubocop/cop/style/redundant_begin.rb +36 -8
  156. data/lib/rubocop/cop/style/redundant_condition.rb +5 -1
  157. data/lib/rubocop/cop/style/redundant_conditional.rb +4 -5
  158. data/lib/rubocop/cop/style/redundant_exception.rb +1 -3
  159. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -0
  160. data/lib/rubocop/cop/style/redundant_freeze.rb +2 -1
  161. data/lib/rubocop/cop/style/redundant_interpolation.rb +6 -1
  162. data/lib/rubocop/cop/style/redundant_parentheses.rb +14 -6
  163. data/lib/rubocop/cop/style/redundant_percent_q.rb +9 -11
  164. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +39 -24
  165. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -15
  166. data/lib/rubocop/cop/style/redundant_return.rb +17 -17
  167. data/lib/rubocop/cop/style/redundant_self.rb +7 -9
  168. data/lib/rubocop/cop/style/redundant_self_assignment.rb +2 -2
  169. data/lib/rubocop/cop/style/redundant_sort.rb +12 -29
  170. data/lib/rubocop/cop/style/redundant_sort_by.rb +5 -9
  171. data/lib/rubocop/cop/style/rescue_standard_error.rb +20 -16
  172. data/lib/rubocop/cop/style/safe_navigation.rb +5 -0
  173. data/lib/rubocop/cop/style/sample.rb +2 -1
  174. data/lib/rubocop/cop/style/send.rb +2 -3
  175. data/lib/rubocop/cop/style/signal_exception.rb +2 -0
  176. data/lib/rubocop/cop/style/single_argument_dig.rb +1 -0
  177. data/lib/rubocop/cop/style/slicing_with_range.rb +2 -1
  178. data/lib/rubocop/cop/style/stderr_puts.rb +1 -0
  179. data/lib/rubocop/cop/style/string_concatenation.rb +17 -3
  180. data/lib/rubocop/cop/style/strip.rb +1 -0
  181. data/lib/rubocop/cop/style/ternary_parentheses.rb +2 -3
  182. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +4 -3
  183. data/lib/rubocop/cop/style/unpack_first.rb +1 -0
  184. data/lib/rubocop/cop/style/zero_length_predicate.rb +1 -5
  185. data/lib/rubocop/cop/util.rb +0 -1
  186. data/lib/rubocop/cop/variable_force/branch.rb +0 -4
  187. data/lib/rubocop/core_ext/string.rb +1 -1
  188. data/lib/rubocop/directive_comment.rb +32 -0
  189. data/lib/rubocop/ext/regexp_node.rb +23 -7
  190. data/lib/rubocop/formatter/disabled_config_formatter.rb +12 -5
  191. data/lib/rubocop/options.rb +37 -17
  192. data/lib/rubocop/result_cache.rb +38 -15
  193. data/lib/rubocop/rspec/cop_helper.rb +1 -1
  194. data/lib/rubocop/rspec/expect_offense.rb +5 -5
  195. data/lib/rubocop/runner.rb +37 -18
  196. data/lib/rubocop/target_finder.rb +27 -26
  197. data/lib/rubocop/target_ruby.rb +1 -1
  198. data/lib/rubocop/version.rb +6 -1
  199. metadata +19 -18
  200. data/lib/rubocop/cop/mixin/regexp_literal_help.rb +0 -43
  201. data/lib/rubocop/cop/tokens_util.rb +0 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39db2826fa916853dc6641e30da24937e009a06b843daf1a7cdb2eca458dfaad
4
- data.tar.gz: 9a4ffd95ff0401aeee427555d1baf51517e06580becfa9243dac9c75305998aa
3
+ metadata.gz: b8ce11205d6a6bb518654cbe498544aa799fbb8d9c9057afd2f551edfc35bbb8
4
+ data.tar.gz: a1f79001991b28508ca7c9a79d75ed58f39ae0dcf2bad419d6a75919b3a3d539
5
5
  SHA512:
6
- metadata.gz: 7e502aeecd9ceaeec36624190f4e9b72d075eed552f2e6204e2e842db1a77758f5fd11336f01f400af45bb36b27f13885a27847b17b84595aeef90df6b0db63b
7
- data.tar.gz: e7ecf12bfc331ef99870f03e034a5154765ceb93c159fdde0fdf8802609c81fa3459250eb3bf6aa7ee140d5c80958783614f5da81585ba75ad9e252afdb8fc50
6
+ metadata.gz: a32001a91575c41b5ca71b6a148af79f45b2a7b8cbc3909a0dcbb7a652f5e62b6a79a84c14189eda64fd3d2a9e8c40d207c37c0f5a78a156e1f636c5191b995e
7
+ data.tar.gz: 9ac5df57938099031807a96bd87a7fb9c5f7f40c314528b4c3254edb45b1386ce199fa9c394c9e7531655d117df9d3d5215bd66e4a927b9b2b0878e0eac2a1f6
data/README.md CHANGED
@@ -22,7 +22,7 @@
22
22
  **RuboCop** is a Ruby static code analyzer (a.k.a. `linter`) and code formatter. Out of the box it
23
23
  will enforce many of the guidelines outlined in the community [Ruby Style
24
24
  Guide](https://rubystyle.guide). Apart from reporting the problems discovered in your code,
25
- RuboCop can also automatically fix many of them you.
25
+ RuboCop can also automatically fix many of them for you.
26
26
 
27
27
  RuboCop is extremely flexible and most aspects of its behavior can be tweaked via various
28
28
  [configuration options](https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml).
@@ -49,7 +49,7 @@ haven't reached version 1.0 yet). To prevent an unwanted RuboCop update you
49
49
  might want to use a conservative version lock in your `Gemfile`:
50
50
 
51
51
  ```rb
52
- gem 'rubocop', '~> 0.90.0', require: false
52
+ gem 'rubocop', '~> 0.93.1', require: false
53
53
  ```
54
54
 
55
55
  ## Quickstart
@@ -117,6 +117,8 @@ AllCops:
117
117
  # CacheRootDirectory is ~ (nil), which it is by default, the root will be
118
118
  # taken from the environment variable `$XDG_CACHE_HOME` if it is set, or if
119
119
  # `$XDG_CACHE_HOME` is not set, it will be `$HOME/.cache/`.
120
+ # The CacheRootDirectory can be overwritten by passing the `--cache-root` command
121
+ # line option or by setting `$RUBOCOP_CACHE_ROOT` environment variable.
120
122
  CacheRootDirectory: ~
121
123
  # It is possible for a malicious user to know the location of RuboCop's cache
122
124
  # directory by looking at CacheRootDirectory, and create a symlink in its
@@ -309,6 +311,19 @@ Layout/AssignmentIndentation:
309
311
  # But it can be overridden by setting this parameter
310
312
  IndentationWidth: ~
311
313
 
314
+ Layout/BeginEndAlignment:
315
+ Description: 'Align ends corresponding to begins correctly.'
316
+ Enabled: pending
317
+ VersionAdded: '0.91'
318
+ # The value `start_of_line` means that `end` should be aligned the start of the line
319
+ # where the `begin` keyword is.
320
+ # The value `begin` means that `end` should be aligned with the `begin` keyword.
321
+ EnforcedStyleAlignWith: start_of_line
322
+ SupportedStylesAlignWith:
323
+ - start_of_line
324
+ - begin
325
+ Severity: warning
326
+
312
327
  Layout/BlockAlignment:
313
328
  Description: 'Align block ends correctly.'
314
329
  Enabled: true
@@ -1380,6 +1395,12 @@ Lint/CircularArgumentReference:
1380
1395
  Enabled: true
1381
1396
  VersionAdded: '0.33'
1382
1397
 
1398
+ Lint/ConstantDefinitionInBlock:
1399
+ Description: 'Do not define constants within a block.'
1400
+ StyleGuide: '#no-constant-definition-in-block'
1401
+ Enabled: pending
1402
+ VersionAdded: '0.91'
1403
+
1383
1404
  Lint/ConstantResolution:
1384
1405
  Description: 'Check that constants are fully qualified with `::`.'
1385
1406
  Enabled: false
@@ -1525,6 +1546,13 @@ Lint/FormatParameterMismatch:
1525
1546
  Enabled: true
1526
1547
  VersionAdded: '0.33'
1527
1548
 
1549
+ Lint/HashCompareByIdentity:
1550
+ Description: 'Prefer using `Hash#compare_by_identity` than using `object_id` for keys.'
1551
+ StyleGuide: '#identity-comparison'
1552
+ Enabled: pending
1553
+ Safe: false
1554
+ VersionAdded: '0.93'
1555
+
1528
1556
  Lint/HeredocMethodCallPosition:
1529
1557
  Description: >-
1530
1558
  Checks for the ordering of a method call where
@@ -1533,6 +1561,12 @@ Lint/HeredocMethodCallPosition:
1533
1561
  StyleGuide: '#heredoc-method-calls'
1534
1562
  VersionAdded: '0.68'
1535
1563
 
1564
+ Lint/IdentityComparison:
1565
+ Description: 'Prefer `equal?` over `==` when comparing `object_id`.'
1566
+ Enabled: pending
1567
+ StyleGuide: '#identity-comparison'
1568
+ VersionAdded: '0.91'
1569
+
1536
1570
  Lint/ImplicitStringConcatenation:
1537
1571
  Description: >-
1538
1572
  Checks for adjacent string literals on the same line, which
@@ -1719,6 +1753,19 @@ Lint/RedundantRequireStatement:
1719
1753
  Enabled: true
1720
1754
  VersionAdded: '0.76'
1721
1755
 
1756
+ Lint/RedundantSafeNavigation:
1757
+ Description: 'Checks for redundant safe navigation calls.'
1758
+ Enabled: pending
1759
+ VersionAdded: '0.93'
1760
+ AllowedMethods:
1761
+ - instance_of?
1762
+ - kind_of?
1763
+ - is_a?
1764
+ - eql?
1765
+ - respond_to?
1766
+ - equal?
1767
+ Safe: false
1768
+
1722
1769
  Lint/RedundantSplatExpansion:
1723
1770
  Description: 'Checks for splat unnecessarily being called on literals.'
1724
1771
  Enabled: true
@@ -1784,6 +1831,7 @@ Lint/SafeNavigationChain:
1784
1831
  - presence
1785
1832
  - try
1786
1833
  - try!
1834
+ - in?
1787
1835
 
1788
1836
  Lint/SafeNavigationConsistency:
1789
1837
  Description: >-
@@ -1966,6 +2014,12 @@ Lint/UselessSetterCall:
1966
2014
  VersionChanged: '0.80'
1967
2015
  Safe: false
1968
2016
 
2017
+ Lint/UselessTimes:
2018
+ Description: 'Checks for useless `Integer#times` calls.'
2019
+ Enabled: pending
2020
+ VersionAdded: '0.91'
2021
+ Safe: false
2022
+
1969
2023
  Lint/Void:
1970
2024
  Description: 'Possible use of operator/literal/variable in void context.'
1971
2025
  Enabled: true
@@ -2429,7 +2483,7 @@ Style/ArrayCoercion:
2429
2483
  with a variable you want to treat as an Array, but you're not certain it's an array.
2430
2484
  StyleGuide: '#array-coercion'
2431
2485
  Safe: false
2432
- Enabled: 'pending'
2486
+ Enabled: false
2433
2487
  VersionAdded: '0.88'
2434
2488
 
2435
2489
  Style/ArrayJoin:
@@ -2668,6 +2722,16 @@ Style/ClassCheck:
2668
2722
  - is_a?
2669
2723
  - kind_of?
2670
2724
 
2725
+ Style/ClassEqualityComparison:
2726
+ Description: 'Enforces the use of `Object#instance_of?` instead of class comparison for equality.'
2727
+ StyleGuide: '#instance-of-vs-class-comparison'
2728
+ Enabled: pending
2729
+ VersionAdded: '0.93'
2730
+ IgnoredMethods:
2731
+ - ==
2732
+ - equal?
2733
+ - eql?
2734
+
2671
2735
  Style/ClassMethods:
2672
2736
  Description: 'Use self when defining module/class methods.'
2673
2737
  StyleGuide: '#def-self-class-methods'
@@ -2829,7 +2893,8 @@ Style/DateTime:
2829
2893
  StyleGuide: '#date--time'
2830
2894
  Enabled: false
2831
2895
  VersionAdded: '0.51'
2832
- VersionChanged: '0.59'
2896
+ VersionChanged: '0.92'
2897
+ SafeAutoCorrect: false
2833
2898
  AllowCoercion: false
2834
2899
 
2835
2900
  Style/DefWithParentheses:
@@ -3074,6 +3139,7 @@ Style/GlobalStdStream:
3074
3139
  StyleGuide: '#global-stdout'
3075
3140
  Enabled: pending
3076
3141
  VersionAdded: '0.89'
3142
+ SafeAutoCorrect: false
3077
3143
 
3078
3144
  Style/GlobalVars:
3079
3145
  Description: 'Do not introduce global variables.'
@@ -3248,11 +3314,16 @@ Style/IpAddresses:
3248
3314
  Description: "Don't include literal IP addresses in code."
3249
3315
  Enabled: false
3250
3316
  VersionAdded: '0.58'
3251
- VersionChanged: '0.77'
3317
+ VersionChanged: '0.91'
3252
3318
  # Allow addresses to be permitted
3253
3319
  AllowedAddresses:
3254
3320
  - "::"
3255
3321
  # :: is a valid IPv6 address, but could potentially be legitimately in code
3322
+ Exclude:
3323
+ - '**/*.gemfile'
3324
+ - '**/Gemfile'
3325
+ - '**/gems.rb'
3326
+ - '**/*.gemspec'
3256
3327
 
3257
3328
  Style/KeywordParametersOrder:
3258
3329
  Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
@@ -3685,6 +3756,8 @@ Style/OptionalBooleanParameter:
3685
3756
  Enabled: pending
3686
3757
  Safe: false
3687
3758
  VersionAdded: '0.89'
3759
+ AllowedMethods:
3760
+ - respond_to_missing?
3688
3761
 
3689
3762
  Style/OrAssignment:
3690
3763
  Description: 'Recommend usage of double pipe equals (||=) where applicable.'
@@ -3953,6 +4026,8 @@ Style/SafeNavigation:
3953
4026
  This cop transforms usages of a method call safeguarded by
3954
4027
  a check for the existence of the object to
3955
4028
  safe navigation (`&.`).
4029
+ Auto-correction is unsafe as it assumes the object will
4030
+ be `nil` or truthy, but never `false`.
3956
4031
  Enabled: true
3957
4032
  VersionAdded: '0.43'
3958
4033
  VersionChanged: '0.77'
@@ -3965,6 +4040,7 @@ Style/SafeNavigation:
3965
4040
  - presence
3966
4041
  - try
3967
4042
  - try!
4043
+ SafeAutoCorrect: false
3968
4044
 
3969
4045
  Style/Sample:
3970
4046
  Description: >-
@@ -1,18 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'English'
4
+ before_us = $LOADED_FEATURES.dup
3
5
  require 'rainbow'
4
6
 
5
- require 'English'
6
7
  require 'set'
7
8
  require 'forwardable'
8
9
  require 'regexp_parser'
9
10
  require 'unicode/display_width/no_string_ext'
11
+
12
+ # we have to require RuboCop's version, before rubocop-ast's
13
+ require_relative 'rubocop/version'
10
14
  require 'rubocop-ast'
15
+
11
16
  require_relative 'rubocop/ast_aliases'
12
17
  require_relative 'rubocop/ext/regexp_node'
13
18
 
14
- require_relative 'rubocop/version'
15
-
16
19
  require_relative 'rubocop/core_ext/string'
17
20
  require_relative 'rubocop/ext/processed_source'
18
21
 
@@ -24,7 +27,6 @@ require_relative 'rubocop/string_interpreter'
24
27
  require_relative 'rubocop/error'
25
28
  require_relative 'rubocop/warning'
26
29
 
27
- require_relative 'rubocop/cop/tokens_util'
28
30
  require_relative 'rubocop/cop/util'
29
31
  require_relative 'rubocop/cop/offense'
30
32
  require_relative 'rubocop/cop/message_annotator'
@@ -103,7 +105,6 @@ require_relative 'rubocop/cop/mixin/percent_literal'
103
105
  require_relative 'rubocop/cop/mixin/preceding_following_alignment'
104
106
  require_relative 'rubocop/cop/mixin/preferred_delimiters'
105
107
  require_relative 'rubocop/cop/mixin/rational_literal'
106
- require_relative 'rubocop/cop/mixin/regexp_literal_help'
107
108
  require_relative 'rubocop/cop/mixin/rescue_node'
108
109
  require_relative 'rubocop/cop/mixin/safe_assignment'
109
110
  require_relative 'rubocop/cop/mixin/space_after_punctuation'
@@ -154,6 +155,7 @@ require_relative 'rubocop/cop/layout/access_modifier_indentation'
154
155
  require_relative 'rubocop/cop/layout/argument_alignment'
155
156
  require_relative 'rubocop/cop/layout/array_alignment'
156
157
  require_relative 'rubocop/cop/layout/assignment_indentation'
158
+ require_relative 'rubocop/cop/layout/begin_end_alignment'
157
159
  require_relative 'rubocop/cop/layout/block_alignment'
158
160
  require_relative 'rubocop/cop/layout/block_end_newline'
159
161
  require_relative 'rubocop/cop/layout/case_indentation'
@@ -250,6 +252,7 @@ require_relative 'rubocop/cop/lint/big_decimal_new'
250
252
  require_relative 'rubocop/cop/lint/binary_operator_with_identical_operands'
251
253
  require_relative 'rubocop/cop/lint/boolean_symbol'
252
254
  require_relative 'rubocop/cop/lint/circular_argument_reference'
255
+ require_relative 'rubocop/cop/lint/constant_definition_in_block'
253
256
  require_relative 'rubocop/cop/lint/constant_resolution'
254
257
  require_relative 'rubocop/cop/lint/debugger'
255
258
  require_relative 'rubocop/cop/lint/deprecated_class_methods'
@@ -275,7 +278,9 @@ require_relative 'rubocop/cop/lint/flip_flop'
275
278
  require_relative 'rubocop/cop/lint/float_comparison'
276
279
  require_relative 'rubocop/cop/lint/float_out_of_range'
277
280
  require_relative 'rubocop/cop/lint/format_parameter_mismatch'
281
+ require_relative 'rubocop/cop/lint/hash_compare_by_identity'
278
282
  require_relative 'rubocop/cop/lint/heredoc_method_call_position'
283
+ require_relative 'rubocop/cop/lint/identity_comparison'
279
284
  require_relative 'rubocop/cop/lint/implicit_string_concatenation'
280
285
  require_relative 'rubocop/cop/lint/inherit_exception'
281
286
  require_relative 'rubocop/cop/lint/ineffective_access_modifier'
@@ -303,6 +308,7 @@ require_relative 'rubocop/cop/lint/rand_one'
303
308
  require_relative 'rubocop/cop/lint/redundant_cop_disable_directive'
304
309
  require_relative 'rubocop/cop/lint/redundant_cop_enable_directive'
305
310
  require_relative 'rubocop/cop/lint/redundant_require_statement'
311
+ require_relative 'rubocop/cop/lint/redundant_safe_navigation'
306
312
  require_relative 'rubocop/cop/lint/redundant_splat_expansion'
307
313
  require_relative 'rubocop/cop/lint/redundant_string_coercion'
308
314
  require_relative 'rubocop/cop/lint/redundant_with_index'
@@ -340,6 +346,7 @@ require_relative 'rubocop/cop/lint/useless_assignment'
340
346
  require_relative 'rubocop/cop/lint/useless_else_without_rescue'
341
347
  require_relative 'rubocop/cop/lint/useless_method_definition'
342
348
  require_relative 'rubocop/cop/lint/useless_setter_call'
349
+ require_relative 'rubocop/cop/lint/useless_times'
343
350
  require_relative 'rubocop/cop/lint/void'
344
351
 
345
352
  require_relative 'rubocop/cop/metrics/utils/iterating_block'
@@ -392,6 +399,7 @@ require_relative 'rubocop/cop/style/case_like_if'
392
399
  require_relative 'rubocop/cop/style/character_literal'
393
400
  require_relative 'rubocop/cop/style/class_and_module_children'
394
401
  require_relative 'rubocop/cop/style/class_check'
402
+ require_relative 'rubocop/cop/style/class_equality_comparison'
395
403
  require_relative 'rubocop/cop/style/class_methods'
396
404
  require_relative 'rubocop/cop/style/class_methods_definitions'
397
405
  require_relative 'rubocop/cop/style/class_vars'
@@ -610,6 +618,7 @@ require_relative 'rubocop/config_obsoletion'
610
618
  require_relative 'rubocop/config_store'
611
619
  require_relative 'rubocop/config_validator'
612
620
  require_relative 'rubocop/target_finder'
621
+ require_relative 'rubocop/directive_comment'
613
622
  require_relative 'rubocop/comment_config'
614
623
  require_relative 'rubocop/magic_comment'
615
624
  require_relative 'rubocop/result_cache'
@@ -623,7 +632,13 @@ require_relative 'rubocop/cli/command/execute_runner'
623
632
  require_relative 'rubocop/cli/command/init_dotfile'
624
633
  require_relative 'rubocop/cli/command/show_cops'
625
634
  require_relative 'rubocop/cli/command/version'
635
+ require_relative 'rubocop/config_regeneration'
626
636
  require_relative 'rubocop/options'
627
637
  require_relative 'rubocop/remote_config'
628
638
  require_relative 'rubocop/target_ruby'
629
639
  require_relative 'rubocop/yaml_duplication_checker'
640
+
641
+ unless File.exist?("#{__dir__}/../rubocop.gemspec") # Check if we are a gem
642
+ RuboCop::ResultCache.rubocop_required_features = $LOADED_FEATURES - before_us
643
+ end
644
+ RuboCop::AST.rubocop_loaded if RuboCop::AST.respond_to?(:rubocop_loaded)
@@ -21,6 +21,7 @@ module RuboCop
21
21
  private
22
22
 
23
23
  def serialize_offense(offense)
24
+ status = :uncorrected if %i[corrected corrected_with_todo].include?(offense.status)
24
25
  {
25
26
  # Calling #to_s here ensures that the serialization works when using
26
27
  # other json serializers such as Oj. Some of these gems do not call
@@ -32,7 +33,7 @@ module RuboCop
32
33
  },
33
34
  message: message(offense),
34
35
  cop_name: offense.cop_name,
35
- status: :uncorrected
36
+ status: status || offense.status
36
37
  }
37
38
  end
38
39
 
@@ -8,6 +8,9 @@ module RuboCop
8
8
  class ExecuteRunner < Base
9
9
  include Formatter::TextUtil
10
10
 
11
+ # Combination of short and long formatter names.
12
+ INTEGRATION_FORMATTERS = %w[h html j json ju junit].freeze
13
+
11
14
  self.command_name = :execute_runner
12
15
 
13
16
  def run
@@ -61,6 +64,11 @@ module RuboCop
61
64
  end
62
65
 
63
66
  def maybe_print_corrected_source
67
+ # Integration tools (like RubyMine) expect to have only the JSON result
68
+ # when specifying JSON format. Similar HTML and JUnit are targeted as well.
69
+ # See: https://github.com/rubocop-hq/rubocop/issues/8673
70
+ return if INTEGRATION_FORMATTERS.include?(@options[:format])
71
+
64
72
  # If we are asked to autocorrect source code read from stdin, the only
65
73
  # reasonable place to write it is to stdout
66
74
  # Unfortunately, we also write other information to stdout
@@ -41,12 +41,15 @@ module RuboCop
41
41
  end
42
42
 
43
43
  def extra_enabled_comments
44
- extra_enabled_comments_with_names([], {})
44
+ extra_enabled_comments_with_names(
45
+ extras: Hash.new { |h, k| h[k] = [] },
46
+ names: Hash.new(0)
47
+ )
45
48
  end
46
49
 
47
50
  private
48
51
 
49
- def extra_enabled_comments_with_names(extras, names)
52
+ def extra_enabled_comments_with_names(extras:, names:)
50
53
  each_directive do |comment, cop_names, disabled|
51
54
  next unless comment_only_line?(comment.loc.expression.line)
52
55
 
@@ -190,18 +193,19 @@ module RuboCop
190
193
  enabled_cops += 1
191
194
  end
192
195
 
193
- extras << [comment, 'all'] if enabled_cops.zero?
196
+ extras[comment] << 'all' if enabled_cops.zero?
194
197
  end
195
198
 
199
+ # Collect cops that have been disabled or enabled by name in a directive comment
200
+ # so that `Lint/RedundantCopEnableDirective` can register offenses correctly.
196
201
  def handle_switch(cop_names, names, disabled, extras, comment)
197
202
  cop_names.each do |name|
198
- names[name] ||= 0
199
203
  if disabled
200
204
  names[name] += 1
201
205
  elsif (names[name]).positive?
202
206
  names[name] -= 1
203
207
  else
204
- extras << [comment, name]
208
+ extras[comment] << name
205
209
  end
206
210
  end
207
211
  end
@@ -129,9 +129,9 @@ module RuboCop
129
129
 
130
130
  def default_configuration
131
131
  @default_configuration ||= begin
132
- print 'Default ' if debug?
133
- load_file(DEFAULT_FILE)
134
- end
132
+ print 'Default ' if debug?
133
+ load_file(DEFAULT_FILE)
134
+ end
135
135
  end
136
136
 
137
137
  # Returns the path rubocop inferred as the root of the project. No file
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ # This class handles collecting the options for regenerating a TODO file.
5
+ # @api private
6
+ class ConfigRegeneration
7
+ AUTO_GENERATED_FILE = RuboCop::CLI::Command::AutoGenerateConfig::AUTO_GENERATED_FILE
8
+ COMMAND_REGEX = /(?<=`rubocop )(.*?)(?=`)/.freeze
9
+ DEFAULT_OPTIONS = { auto_gen_config: true }.freeze
10
+
11
+ # Get options from the comment in the TODO file, and parse them as options
12
+ def options
13
+ # If there's no existing TODO file, generate one
14
+ return DEFAULT_OPTIONS unless todo_exists?
15
+
16
+ match = generation_command.match(COMMAND_REGEX)
17
+ return DEFAULT_OPTIONS unless match
18
+
19
+ options = match[1].split(' ')
20
+ Options.new.parse(options).first
21
+ end
22
+
23
+ private
24
+
25
+ def todo_exists?
26
+ File.exist?(AUTO_GENERATED_FILE) && !File.empty?(AUTO_GENERATED_FILE)
27
+ end
28
+
29
+ def generation_command
30
+ File.foreach(AUTO_GENERATED_FILE).take(2).last
31
+ end
32
+ end
33
+ end