rubocop 1.32.0 → 1.37.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/config/default.yml +104 -16
  4. data/config/obsoletion.yml +23 -1
  5. data/lib/rubocop/arguments_env.rb +17 -0
  6. data/lib/rubocop/arguments_file.rb +17 -0
  7. data/lib/rubocop/cache_config.rb +29 -0
  8. data/lib/rubocop/cli/command/{auto_genenerate_config.rb → auto_generate_config.rb} +2 -2
  9. data/lib/rubocop/cli/command/execute_runner.rb +7 -7
  10. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  11. data/lib/rubocop/cli/command/suggest_extensions.rb +53 -15
  12. data/lib/rubocop/config.rb +1 -1
  13. data/lib/rubocop/config_finder.rb +68 -0
  14. data/lib/rubocop/config_loader.rb +12 -40
  15. data/lib/rubocop/config_loader_resolver.rb +1 -5
  16. data/lib/rubocop/config_obsoletion/changed_parameter.rb +5 -0
  17. data/lib/rubocop/config_obsoletion/parameter_rule.rb +4 -0
  18. data/lib/rubocop/config_obsoletion.rb +7 -2
  19. data/lib/rubocop/cop/cop.rb +1 -1
  20. data/lib/rubocop/cop/correctors/parentheses_corrector.rb +58 -0
  21. data/lib/rubocop/cop/gemspec/require_mfa.rb +1 -1
  22. data/lib/rubocop/cop/generator/require_file_injector.rb +2 -2
  23. data/lib/rubocop/cop/generator.rb +1 -2
  24. data/lib/rubocop/cop/internal_affairs/numblock_handler.rb +69 -0
  25. data/lib/rubocop/cop/internal_affairs/single_line_comparison.rb +62 -0
  26. data/lib/rubocop/cop/internal_affairs.rb +2 -0
  27. data/lib/rubocop/cop/layout/block_alignment.rb +16 -12
  28. data/lib/rubocop/cop/layout/block_end_newline.rb +35 -5
  29. data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +5 -2
  30. data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +2 -0
  31. data/lib/rubocop/cop/layout/end_of_line.rb +4 -4
  32. data/lib/rubocop/cop/layout/first_argument_indentation.rb +7 -1
  33. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +2 -2
  34. data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +2 -2
  35. data/lib/rubocop/cop/layout/indentation_width.rb +6 -2
  36. data/lib/rubocop/cop/layout/line_length.rb +4 -1
  37. data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +1 -1
  38. data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -0
  39. data/lib/rubocop/cop/layout/redundant_line_break.rb +1 -1
  40. data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
  41. data/lib/rubocop/cop/layout/space_around_keyword.rb +1 -1
  42. data/lib/rubocop/cop/layout/space_before_block_braces.rb +2 -0
  43. data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +13 -9
  44. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +25 -9
  45. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +28 -3
  46. data/lib/rubocop/cop/legacy/corrections_proxy.rb +1 -1
  47. data/lib/rubocop/cop/legacy/corrector.rb +1 -1
  48. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +21 -8
  49. data/lib/rubocop/cop/lint/debugger.rb +26 -16
  50. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +4 -4
  51. data/lib/rubocop/cop/lint/duplicate_magic_comment.rb +73 -0
  52. data/lib/rubocop/cop/lint/duplicate_methods.rb +11 -1
  53. data/lib/rubocop/cop/lint/duplicate_regexp_character_class_element.rb +25 -6
  54. data/lib/rubocop/cop/lint/duplicate_require.rb +1 -1
  55. data/lib/rubocop/cop/lint/empty_block.rb +1 -1
  56. data/lib/rubocop/cop/lint/empty_class.rb +3 -1
  57. data/lib/rubocop/cop/lint/empty_conditional_body.rb +107 -1
  58. data/lib/rubocop/cop/lint/erb_new_arguments.rb +9 -9
  59. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +4 -0
  60. data/lib/rubocop/cop/lint/nested_method_definition.rb +50 -1
  61. data/lib/rubocop/cop/lint/next_without_accumulator.rb +25 -6
  62. data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +6 -6
  63. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +12 -0
  64. data/lib/rubocop/cop/lint/number_conversion.rb +24 -8
  65. data/lib/rubocop/cop/lint/ordered_magic_comments.rb +4 -5
  66. data/lib/rubocop/cop/lint/out_of_range_regexp_ref.rb +1 -1
  67. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +12 -1
  68. data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +7 -0
  69. data/lib/rubocop/cop/lint/redundant_require_statement.rb +29 -9
  70. data/lib/rubocop/cop/lint/redundant_safe_navigation.rb +9 -3
  71. data/lib/rubocop/cop/lint/redundant_with_index.rb +13 -10
  72. data/lib/rubocop/cop/lint/redundant_with_object.rb +12 -11
  73. data/lib/rubocop/cop/lint/require_parentheses.rb +1 -1
  74. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +3 -2
  75. data/lib/rubocop/cop/lint/shadowed_exception.rb +15 -10
  76. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +27 -3
  77. data/lib/rubocop/cop/lint/unreachable_loop.rb +9 -3
  78. data/lib/rubocop/cop/lint/unused_method_argument.rb +4 -0
  79. data/lib/rubocop/cop/lint/useless_access_modifier.rb +8 -6
  80. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +1 -1
  81. data/lib/rubocop/cop/lint/void.rb +2 -0
  82. data/lib/rubocop/cop/metrics/abc_size.rb +3 -1
  83. data/lib/rubocop/cop/metrics/block_length.rb +6 -7
  84. data/lib/rubocop/cop/metrics/method_length.rb +8 -8
  85. data/lib/rubocop/cop/mixin/allowed_methods.rb +20 -1
  86. data/lib/rubocop/cop/mixin/allowed_pattern.rb +17 -1
  87. data/lib/rubocop/cop/mixin/check_line_breakable.rb +1 -1
  88. data/lib/rubocop/cop/mixin/comments_help.rb +17 -1
  89. data/lib/rubocop/cop/mixin/enforce_superclass.rb +2 -1
  90. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +4 -0
  91. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +82 -4
  92. data/lib/rubocop/cop/mixin/hash_transform_method.rb +10 -6
  93. data/lib/rubocop/cop/mixin/method_complexity.rb +8 -13
  94. data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +1 -1
  95. data/lib/rubocop/cop/mixin/range_help.rb +4 -5
  96. data/lib/rubocop/cop/mixin/rescue_node.rb +3 -1
  97. data/lib/rubocop/cop/mixin/surrounding_space.rb +6 -5
  98. data/lib/rubocop/cop/naming/block_parameter_name.rb +1 -1
  99. data/lib/rubocop/cop/naming/constant_name.rb +2 -2
  100. data/lib/rubocop/cop/naming/inclusive_language.rb +1 -1
  101. data/lib/rubocop/cop/naming/predicate_name.rb +24 -3
  102. data/lib/rubocop/cop/style/access_modifier_declarations.rb +97 -1
  103. data/lib/rubocop/cop/style/accessor_grouping.rb +7 -3
  104. data/lib/rubocop/cop/style/arguments_forwarding.rb +2 -2
  105. data/lib/rubocop/cop/style/block_delimiters.rb +26 -7
  106. data/lib/rubocop/cop/style/case_equality.rb +40 -10
  107. data/lib/rubocop/cop/style/class_and_module_children.rb +4 -4
  108. data/lib/rubocop/cop/style/class_equality_comparison.rb +32 -7
  109. data/lib/rubocop/cop/style/class_methods_definitions.rb +2 -1
  110. data/lib/rubocop/cop/style/collection_compact.rb +6 -1
  111. data/lib/rubocop/cop/style/collection_methods.rb +2 -0
  112. data/lib/rubocop/cop/style/combinable_loops.rb +3 -1
  113. data/lib/rubocop/cop/style/double_negation.rb +2 -0
  114. data/lib/rubocop/cop/style/each_for_simple_loop.rb +41 -6
  115. data/lib/rubocop/cop/style/each_with_object.rb +39 -8
  116. data/lib/rubocop/cop/style/empty_block_parameter.rb +1 -1
  117. data/lib/rubocop/cop/style/empty_heredoc.rb +15 -1
  118. data/lib/rubocop/cop/style/empty_lambda_parameter.rb +1 -1
  119. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  120. data/lib/rubocop/cop/style/endless_method.rb +1 -1
  121. data/lib/rubocop/cop/style/explicit_block_argument.rb +4 -0
  122. data/lib/rubocop/cop/style/for.rb +2 -0
  123. data/lib/rubocop/cop/style/format_string_token.rb +21 -8
  124. data/lib/rubocop/cop/style/guard_clause.rb +27 -16
  125. data/lib/rubocop/cop/style/hash_each_methods.rb +3 -1
  126. data/lib/rubocop/cop/style/hash_except.rb +0 -4
  127. data/lib/rubocop/cop/style/hash_syntax.rb +17 -0
  128. data/lib/rubocop/cop/style/if_unless_modifier.rb +1 -1
  129. data/lib/rubocop/cop/style/inverse_methods.rb +8 -6
  130. data/lib/rubocop/cop/style/magic_comment_format.rb +307 -0
  131. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +15 -4
  132. data/lib/rubocop/cop/style/method_call_with_args_parentheses/require_parentheses.rb +5 -1
  133. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -7
  134. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +11 -6
  135. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +4 -1
  136. data/lib/rubocop/cop/style/multiline_block_chain.rb +3 -1
  137. data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +1 -1
  138. data/lib/rubocop/cop/style/negated_if_else_condition.rb +7 -1
  139. data/lib/rubocop/cop/style/next.rb +3 -5
  140. data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
  141. data/lib/rubocop/cop/style/numeric_literals.rb +16 -1
  142. data/lib/rubocop/cop/style/numeric_predicate.rb +28 -8
  143. data/lib/rubocop/cop/style/object_then.rb +2 -0
  144. data/lib/rubocop/cop/style/operator_method_call.rb +39 -0
  145. data/lib/rubocop/cop/style/perl_backrefs.rb +22 -1
  146. data/lib/rubocop/cop/style/proc.rb +4 -1
  147. data/lib/rubocop/cop/style/redundant_begin.rb +3 -0
  148. data/lib/rubocop/cop/style/redundant_condition.rb +24 -6
  149. data/lib/rubocop/cop/style/redundant_fetch_block.rb +1 -1
  150. data/lib/rubocop/cop/style/redundant_initialize.rb +3 -1
  151. data/lib/rubocop/cop/style/redundant_parentheses.rb +19 -22
  152. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +8 -1
  153. data/lib/rubocop/cop/style/redundant_self.rb +2 -0
  154. data/lib/rubocop/cop/style/redundant_sort.rb +21 -6
  155. data/lib/rubocop/cop/style/redundant_sort_by.rb +24 -8
  156. data/lib/rubocop/cop/style/redundant_string_escape.rb +173 -0
  157. data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
  158. data/lib/rubocop/cop/style/safe_navigation.rb +4 -2
  159. data/lib/rubocop/cop/style/single_line_block_params.rb +1 -1
  160. data/lib/rubocop/cop/style/sole_nested_conditional.rb +14 -5
  161. data/lib/rubocop/cop/style/static_class.rb +32 -1
  162. data/lib/rubocop/cop/style/symbol_array.rb +3 -1
  163. data/lib/rubocop/cop/style/symbol_proc.rb +38 -12
  164. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -13
  165. data/lib/rubocop/cop/style/top_level_method_definition.rb +3 -1
  166. data/lib/rubocop/cop/style/trailing_comma_in_block_args.rb +1 -1
  167. data/lib/rubocop/cop/style/word_array.rb +3 -1
  168. data/lib/rubocop/cop/util.rb +1 -1
  169. data/lib/rubocop/ext/range.rb +15 -0
  170. data/lib/rubocop/feature_loader.rb +94 -0
  171. data/lib/rubocop/formatter/clang_style_formatter.rb +1 -1
  172. data/lib/rubocop/formatter/disabled_config_formatter.rb +9 -3
  173. data/lib/rubocop/formatter/html_formatter.rb +3 -3
  174. data/lib/rubocop/formatter/markdown_formatter.rb +1 -1
  175. data/lib/rubocop/formatter/tap_formatter.rb +1 -1
  176. data/lib/rubocop/options.rb +13 -13
  177. data/lib/rubocop/result_cache.rb +22 -20
  178. data/lib/rubocop/rspec/shared_contexts.rb +13 -1
  179. data/lib/rubocop/runner.rb +4 -0
  180. data/lib/rubocop/server/cache.rb +41 -2
  181. data/lib/rubocop/server/cli.rb +26 -2
  182. data/lib/rubocop/server/client_command/exec.rb +5 -0
  183. data/lib/rubocop/server/core.rb +2 -1
  184. data/lib/rubocop/server/socket_reader.rb +5 -1
  185. data/lib/rubocop/server.rb +1 -1
  186. data/lib/rubocop/version.rb +8 -2
  187. data/lib/rubocop.rb +8 -3
  188. metadata +20 -9
  189. data/lib/rubocop/cop/mixin/ignored_methods.rb +0 -52
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 270faf06487f8a915ef6293944db136da6fb51ec09b5613be4b848a471c858bb
4
- data.tar.gz: 1c61746959019453862c2e90b8d3250ce3f9815b1eae286f1fd5b73fb267a1cb
3
+ metadata.gz: e928a8547def9cafd9cddc36b5a407aef7d46fdf9825941c7906073492d88668
4
+ data.tar.gz: 3ef9727850f93815ba310b7c3a8cf74e53a0ee18a0fcf6731fd97a3640ffe28d
5
5
  SHA512:
6
- metadata.gz: 86966e7ff42d0f514a447c8313cc9bdc13020ec1d375e584dba8ebae5bb535a1238380a57d55dfd697c735b3f9259f59939563f4b504f08570304e4ec1c2c7af
7
- data.tar.gz: ce35c98b8b51b8b59c6c2aeac880a0618067a68f7080a2e44408a7e283471b2b57f84e57c127144632b61eaa8edf6e4369d4702c2baa222cb3b37fad38606bd5
6
+ metadata.gz: f57e5d25375fe47734a6e198924db74b341501762dc8f54277a888788ab821215c96847940cec1af4d90673fe79ab906b451bf25bec90f9c8c080e78efc01111
7
+ data.tar.gz: 69cafbca956eaa49887596d255f6888057ede94f3621349398de95da5c477201f7bee7eae074ab4750ce0131dcb26d6dfdc77c31f5fcb478d2fc25d5ca73e68c
data/README.md CHANGED
@@ -46,14 +46,14 @@ If you'd rather install RuboCop using `bundler`, add a line for it in your `Gemf
46
46
  gem 'rubocop', require: false
47
47
  ```
48
48
 
49
- RuboCop is stable between major versions, both in terms of API and cop configuration.
49
+ RuboCop is stable between minor versions, both in terms of API and cop configuration.
50
50
  We aim to ease the maintenance of RuboCop extensions and the upgrades between RuboCop
51
51
  releases. All big changes are reserved for major releases.
52
52
  To prevent an unwanted RuboCop update you might want to use a conservative version lock
53
53
  in your `Gemfile`:
54
54
 
55
55
  ```rb
56
- gem 'rubocop', '~> 1.32', require: false
56
+ gem 'rubocop', '~> 1.37', require: false
57
57
  ```
58
58
 
59
59
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
data/config/default.yml CHANGED
@@ -1502,7 +1502,9 @@ Lint/AmbiguousBlockAssociation:
1502
1502
  Enabled: true
1503
1503
  VersionAdded: '0.48'
1504
1504
  VersionChanged: '1.13'
1505
- IgnoredMethods: []
1505
+ AllowedMethods: []
1506
+ AllowedPatterns: []
1507
+ IgnoredMethods: [] # deprecated
1506
1508
 
1507
1509
  Lint/AmbiguousOperator:
1508
1510
  Description: >-
@@ -1602,6 +1604,7 @@ Lint/Debugger:
1602
1604
  # a user's configuration, but are otherwise not significant.
1603
1605
  Kernel:
1604
1606
  - binding.irb
1607
+ - Kernel.binding.irb
1605
1608
  Byebug:
1606
1609
  - byebug
1607
1610
  - remote_byebug
@@ -1619,6 +1622,9 @@ Lint/Debugger:
1619
1622
  - binding.pry
1620
1623
  - binding.remote_pry
1621
1624
  - binding.pry_remote
1625
+ - Kernel.binding.pry
1626
+ - Kernel.binding.remote_pry
1627
+ - Kernel.binding.pry_remote
1622
1628
  - Pry.rescue
1623
1629
  Rails:
1624
1630
  - debugger
@@ -1701,6 +1707,11 @@ Lint/DuplicateHashKey:
1701
1707
  VersionAdded: '0.34'
1702
1708
  VersionChanged: '0.77'
1703
1709
 
1710
+ Lint/DuplicateMagicComment:
1711
+ Description: 'Check for duplicated magic comments.'
1712
+ Enabled: pending
1713
+ VersionAdded: '1.37'
1714
+
1704
1715
  Lint/DuplicateMethods:
1705
1716
  Description: 'Check for duplicate method definitions.'
1706
1717
  Enabled: true
@@ -1751,8 +1762,10 @@ Lint/EmptyClass:
1751
1762
  Lint/EmptyConditionalBody:
1752
1763
  Description: 'Checks for the presence of `if`, `elsif` and `unless` branches without a body.'
1753
1764
  Enabled: true
1765
+ SafeAutoCorrect: false
1754
1766
  AllowComments: true
1755
1767
  VersionAdded: '0.89'
1768
+ VersionChanged: '1.34'
1756
1769
 
1757
1770
  Lint/EmptyEnsure:
1758
1771
  Description: 'Checks for empty ensure block.'
@@ -1949,6 +1962,8 @@ Lint/NestedMethodDefinition:
1949
1962
  Description: 'Do not use nested method definitions.'
1950
1963
  StyleGuide: '#no-nested-methods'
1951
1964
  Enabled: true
1965
+ AllowedMethods: []
1966
+ AllowedPatterns: []
1952
1967
  VersionAdded: '0.32'
1953
1968
 
1954
1969
  Lint/NestedPercentLiteral:
@@ -1970,6 +1985,7 @@ Lint/NoReturnInBeginEndBlocks:
1970
1985
 
1971
1986
  Lint/NonAtomicFileOperation:
1972
1987
  Description: Checks for non-atomic file operations.
1988
+ StyleGuide: '#atomic-file-operations'
1973
1989
  Enabled: pending
1974
1990
  VersionAdded: '1.31'
1975
1991
  SafeAutoCorrect: false
@@ -1991,7 +2007,9 @@ Lint/NumberConversion:
1991
2007
  VersionAdded: '0.53'
1992
2008
  VersionChanged: '1.1'
1993
2009
  SafeAutoCorrect: false
1994
- IgnoredMethods: []
2010
+ AllowedMethods: []
2011
+ AllowedPatterns: []
2012
+ IgnoredMethods: [] # deprecated
1995
2013
  IgnoredClasses:
1996
2014
  - Time
1997
2015
  - DateTime
@@ -2010,7 +2028,9 @@ Lint/OrAssignmentToConstant:
2010
2028
  Lint/OrderedMagicComments:
2011
2029
  Description: 'Checks the proper ordering of magic comments and whether a magic comment is not placed before a shebang.'
2012
2030
  Enabled: true
2031
+ SafeAutoCorrect: false
2013
2032
  VersionAdded: '0.53'
2033
+ VersionChanged: '1.37'
2014
2034
 
2015
2035
  Lint/OutOfRangeRegexpRef:
2016
2036
  Description: 'Checks for out of range reference for Regexp because it always returns nil.'
@@ -2443,7 +2463,9 @@ Metrics/AbcSize:
2443
2463
  VersionChanged: '1.5'
2444
2464
  # The ABC size is a calculated magnitude, so this number can be an Integer or
2445
2465
  # a Float.
2446
- IgnoredMethods: []
2466
+ AllowedMethods: []
2467
+ AllowedPatterns: []
2468
+ IgnoredMethods: [] # deprecated
2447
2469
  CountRepeatedAttributes: true
2448
2470
  Max: 17
2449
2471
 
@@ -2456,10 +2478,12 @@ Metrics/BlockLength:
2456
2478
  Max: 25
2457
2479
  CountAsOne: []
2458
2480
  ExcludedMethods: [] # deprecated, retained for backwards compatibility
2459
- IgnoredMethods:
2481
+ AllowedMethods:
2460
2482
  # By default, exclude the `#refine` method, as it tends to have larger
2461
2483
  # associated blocks.
2462
2484
  - refine
2485
+ AllowedPatterns: []
2486
+ IgnoredMethods: [] # deprecated
2463
2487
  Exclude:
2464
2488
  - '**/*.gemspec'
2465
2489
 
@@ -2489,7 +2513,9 @@ Metrics/CyclomaticComplexity:
2489
2513
  Enabled: true
2490
2514
  VersionAdded: '0.25'
2491
2515
  VersionChanged: '0.81'
2492
- IgnoredMethods: []
2516
+ AllowedMethods: []
2517
+ AllowedPatterns: []
2518
+ IgnoredMethods: [] # deprecated
2493
2519
  Max: 7
2494
2520
 
2495
2521
  Metrics/MethodLength:
@@ -2502,7 +2528,9 @@ Metrics/MethodLength:
2502
2528
  Max: 10
2503
2529
  CountAsOne: []
2504
2530
  ExcludedMethods: [] # deprecated, retained for backwards compatibility
2505
- IgnoredMethods: []
2531
+ AllowedMethods: []
2532
+ AllowedPatterns: []
2533
+ IgnoredMethods: [] # deprecated
2506
2534
 
2507
2535
  Metrics/ModuleLength:
2508
2536
  Description: 'Avoid modules longer than 100 lines of code.'
@@ -2530,7 +2558,9 @@ Metrics/PerceivedComplexity:
2530
2558
  Enabled: true
2531
2559
  VersionAdded: '0.25'
2532
2560
  VersionChanged: '0.81'
2533
- IgnoredMethods: []
2561
+ AllowedMethods: []
2562
+ AllowedPatterns: []
2563
+ IgnoredMethods: [] # deprecated
2534
2564
  Max: 8
2535
2565
 
2536
2566
  ################## Migration #############################
@@ -2773,6 +2803,7 @@ Naming/MethodParameterName:
2773
2803
  AllowNamesEndingInNumbers: true
2774
2804
  # Allowed names that will not register an offense
2775
2805
  AllowedNames:
2806
+ - as
2776
2807
  - at
2777
2808
  - by
2778
2809
  - db
@@ -2927,6 +2958,7 @@ Style/AccessModifierDeclarations:
2927
2958
  - inline
2928
2959
  - group
2929
2960
  AllowModifiersOnSymbols: true
2961
+ SafeAutoCorrect: false
2930
2962
 
2931
2963
  Style/AccessorGrouping:
2932
2964
  Description: 'Checks for grouping of accessors in `class` and `module` bodies.'
@@ -3061,7 +3093,7 @@ Style/BlockDelimiters:
3061
3093
  # This looks at the usage of a block's method to determine its type (e.g. is
3062
3094
  # the result of a `map` assigned to a variable or passed to another
3063
3095
  # method) but exceptions are permitted in the `ProceduralMethods`,
3064
- # `FunctionalMethods` and `IgnoredMethods` sections below.
3096
+ # `FunctionalMethods` and `AllowedMethods` sections below.
3065
3097
  - semantic
3066
3098
  # The `braces_for_chaining` style enforces braces around single line blocks
3067
3099
  # and do..end around multi-line blocks, except for multi-line blocks whose
@@ -3102,7 +3134,7 @@ Style/BlockDelimiters:
3102
3134
  - let!
3103
3135
  - subject
3104
3136
  - watch
3105
- IgnoredMethods:
3137
+ AllowedMethods:
3106
3138
  # Methods that can be either procedural or functional and cannot be
3107
3139
  # categorised from their usage alone, e.g.
3108
3140
  #
@@ -3119,6 +3151,8 @@ Style/BlockDelimiters:
3119
3151
  - lambda
3120
3152
  - proc
3121
3153
  - it
3154
+ AllowedPatterns: []
3155
+ IgnoredMethods: [] # deprecated
3122
3156
  # The AllowBracesOnProceduralOneLiners option is ignored unless the
3123
3157
  # EnforcedStyle is set to `semantic`. If so:
3124
3158
  #
@@ -3163,6 +3197,15 @@ Style/CaseEquality:
3163
3197
  # # good
3164
3198
  # String === "string"
3165
3199
  AllowOnConstant: false
3200
+ # If `AllowOnSelfClass` option is enabled, the cop will ignore violations when the receiver of
3201
+ # the case equality operator is `self.class`.
3202
+ #
3203
+ # # bad
3204
+ # some_class === object
3205
+ #
3206
+ # # good
3207
+ # self.class === object
3208
+ AllowOnSelfClass: false
3166
3209
 
3167
3210
  Style/CaseLikeIf:
3168
3211
  Description: 'Identifies places where `if-elsif` constructions can be replaced with `case-when`.'
@@ -3222,10 +3265,12 @@ Style/ClassEqualityComparison:
3222
3265
  StyleGuide: '#instance-of-vs-class-comparison'
3223
3266
  Enabled: true
3224
3267
  VersionAdded: '0.93'
3225
- IgnoredMethods:
3268
+ AllowedMethods:
3226
3269
  - ==
3227
3270
  - equal?
3228
3271
  - eql?
3272
+ AllowedPatterns: []
3273
+ IgnoredMethods: [] # deprecated
3229
3274
 
3230
3275
  Style/ClassMethods:
3231
3276
  Description: 'Use self when defining module/class methods.'
@@ -3687,7 +3732,9 @@ Style/FormatStringToken:
3687
3732
  MaxUnannotatedPlaceholdersAllowed: 1
3688
3733
  VersionAdded: '0.49'
3689
3734
  VersionChanged: '1.0'
3690
- IgnoredMethods: []
3735
+ AllowedMethods: []
3736
+ AllowedPatterns: []
3737
+ IgnoredMethods: [] # deprecated
3691
3738
 
3692
3739
  Style/FrozenStringLiteralComment:
3693
3740
  Description: >-
@@ -3812,6 +3859,8 @@ Style/HashSyntax:
3812
3859
  - never
3813
3860
  # accepts both shorthand and explicit use of hash literal value.
3814
3861
  - either
3862
+ # like "either", but will avoid mixing styles in a single hash
3863
+ - consistent
3815
3864
  # Force hashes that have a symbol value to use hash rockets
3816
3865
  UseHashRocketsWithSymbolValues: false
3817
3866
  # Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
@@ -3988,6 +4037,26 @@ Style/LineEndConcatenation:
3988
4037
  VersionAdded: '0.18'
3989
4038
  VersionChanged: '0.64'
3990
4039
 
4040
+ Style/MagicCommentFormat:
4041
+ Description: 'Use a consistent style for magic comments.'
4042
+ Enabled: pending
4043
+ VersionAdded: '1.35'
4044
+ EnforcedStyle: snake_case
4045
+ SupportedStyles:
4046
+ # `snake` will enforce the magic comment is written
4047
+ # in snake case (words separated by underscores).
4048
+ # Eg: froze_string_literal: true
4049
+ - snake_case
4050
+ # `kebab` will enforce the magic comment is written
4051
+ # in kebab case (words separated by hyphens).
4052
+ # Eg: froze-string-literal: true
4053
+ - kebab_case
4054
+ DirectiveCapitalization: lowercase
4055
+ ValueCapitalization: ~
4056
+ SupportedCapitalizations:
4057
+ - lowercase
4058
+ - uppercase
4059
+
3991
4060
  Style/MapCompactWithConditionalBlock:
3992
4061
  Description: 'Prefer `select` or `reject` over `map { ... }.compact`.'
3993
4062
  Enabled: pending
@@ -4006,7 +4075,8 @@ Style/MethodCallWithArgsParentheses:
4006
4075
  VersionAdded: '0.47'
4007
4076
  VersionChanged: '1.7'
4008
4077
  IgnoreMacros: true
4009
- IgnoredMethods: []
4078
+ AllowedMethods: []
4079
+ IgnoredMethods: [] # deprecated
4010
4080
  AllowedPatterns: []
4011
4081
  IgnoredPatterns: [] # deprecated
4012
4082
  IncludedMacros: []
@@ -4023,7 +4093,9 @@ Style/MethodCallWithoutArgsParentheses:
4023
4093
  Description: 'Do not use parentheses for method calls with no arguments.'
4024
4094
  StyleGuide: '#method-invocation-parens'
4025
4095
  Enabled: true
4026
- IgnoredMethods: []
4096
+ AllowedMethods: []
4097
+ AllowedPatterns: []
4098
+ IgnoredMethods: [] # deprecated
4027
4099
  VersionAdded: '0.47'
4028
4100
  VersionChanged: '0.55'
4029
4101
 
@@ -4375,6 +4447,7 @@ Style/NumericLiterals:
4375
4447
  Strict: false
4376
4448
  # You can specify allowed numbers. (e.g. port number 3000, 8080, and etc)
4377
4449
  AllowedNumbers: []
4450
+ AllowedPatterns: []
4378
4451
 
4379
4452
  Style/NumericPredicate:
4380
4453
  Description: >-
@@ -4393,7 +4466,9 @@ Style/NumericPredicate:
4393
4466
  SupportedStyles:
4394
4467
  - predicate
4395
4468
  - comparison
4396
- IgnoredMethods: []
4469
+ AllowedMethods: []
4470
+ AllowedPatterns: []
4471
+ IgnoredMethods: [] # deprecated
4397
4472
  # Exclude RSpec specs because assertions like `expect(1).to be > 0` cause
4398
4473
  # false positives.
4399
4474
  Exclude:
@@ -4432,6 +4507,12 @@ Style/OpenStructUse:
4432
4507
  Enabled: pending
4433
4508
  VersionAdded: '1.23'
4434
4509
 
4510
+ Style/OperatorMethodCall:
4511
+ Description: 'Checks for redundant dot before operator method call.'
4512
+ StyleGuide: '#operator-method-call'
4513
+ Enabled: pending
4514
+ VersionAdded: '1.37'
4515
+
4435
4516
  Style/OptionHash:
4436
4517
  Description: "Don't use option hashes when you can use keyword arguments."
4437
4518
  Enabled: false
@@ -4726,6 +4807,11 @@ Style/RedundantSortBy:
4726
4807
  Enabled: true
4727
4808
  VersionAdded: '0.36'
4728
4809
 
4810
+ Style/RedundantStringEscape:
4811
+ Description: 'Checks for redundant escapes in string literals.'
4812
+ Enabled: pending
4813
+ VersionAdded: '1.37'
4814
+
4729
4815
  Style/RegexpLiteral:
4730
4816
  Description: 'Use / or %r around regular expressions.'
4731
4817
  StyleGuide: '#percent-r'
@@ -5030,11 +5116,13 @@ Style/SymbolProc:
5030
5116
  VersionAdded: '0.26'
5031
5117
  VersionChanged: '1.28'
5032
5118
  AllowMethodsWithArguments: false
5033
- # A list of method names to be ignored by the check.
5119
+ # A list of method names to be always allowed by the check.
5034
5120
  # The names should be fairly unique, otherwise you'll end up ignoring lots of code.
5035
- IgnoredMethods:
5121
+ AllowedMethods:
5036
5122
  - respond_to
5037
5123
  - define_method
5124
+ AllowedPatterns: []
5125
+ IgnoredMethods: [] # deprecated
5038
5126
  AllowComments: false
5039
5127
 
5040
5128
  Style/TernaryParentheses:
@@ -187,7 +187,9 @@ changed_parameters:
187
187
  - Metrics/BlockLength
188
188
  - Metrics/MethodLength
189
189
  parameters: ExcludedMethods
190
- alternative: IgnoredMethods
190
+ alternatives:
191
+ - AllowedMethods
192
+ - AllowedPatterns
191
193
  severity: warning
192
194
  - cops: Lint/Debugger
193
195
  parameters: DebuggerReceivers
@@ -202,6 +204,26 @@ changed_parameters:
202
204
  parameters: IgnoredPatterns
203
205
  alternative: AllowedPatterns
204
206
  severity: warning
207
+ - cops:
208
+ - Lint/AmbiguousBlockAssociation
209
+ - Lint/NumberConversion
210
+ - Metrics/AbcSize
211
+ - Metrics/BlockLength
212
+ - Metrics/CyclomaticComplexity
213
+ - Metrics/MethodLength
214
+ - Metrics/PerceivedComplexity
215
+ - Style/BlockDelimiters
216
+ - Style/ClassEqualityComparison
217
+ - Style/FormatStringToken
218
+ - Style/MethodCallWithArgsParentheses
219
+ - Style/MethodCallWithoutArgsParentheses
220
+ - Style/NumericPredicate
221
+ - Style/SymbolLiteral
222
+ parameters: IgnoredMethods
223
+ alternatives:
224
+ - AllowedMethods
225
+ - AllowedPatterns
226
+ severity: warning
205
227
 
206
228
  # Enforced styles that have been removed or replaced
207
229
  changed_enforced_styles:
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ # This is a class that reads optional command line arguments to rubocop from environment variable.
5
+ # @api private
6
+ class ArgumentsEnv
7
+ def self.read_as_arguments
8
+ if (arguments = ENV.fetch('RUBOCOP_OPTS', '')).empty?
9
+ []
10
+ else
11
+ require 'shellwords'
12
+
13
+ Shellwords.split(arguments)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ # This is a class that reads optional command line arguments to rubocop from .rubocop file.
5
+ # @api private
6
+ class ArgumentsFile
7
+ def self.read_as_arguments
8
+ if File.exist?('.rubocop') && !File.directory?('.rubocop')
9
+ require 'shellwords'
10
+
11
+ File.read('.rubocop').shellsplit
12
+ else
13
+ []
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ # This class represents the cache config of the caching RuboCop runs.
5
+ # @api private
6
+ class CacheConfig
7
+ def self.root_dir
8
+ root = ENV.fetch('RUBOCOP_CACHE_ROOT', nil)
9
+ root ||= yield
10
+ root ||= if ENV.key?('XDG_CACHE_HOME')
11
+ # Include user ID in the path to make sure the user has write
12
+ # access.
13
+ File.join(ENV.fetch('XDG_CACHE_HOME'), Process.uid.to_s)
14
+ else
15
+ # On FreeBSD, the /home path is a symbolic link to /usr/home
16
+ # and the $HOME environment variable returns the /home path.
17
+ #
18
+ # As $HOME is a built-in environment variable, FreeBSD users
19
+ # always get a warning message.
20
+ #
21
+ # To avoid raising warn log messages on FreeBSD, we retrieve
22
+ # the real path of the home folder.
23
+ File.join(File.realpath(Dir.home), '.cache')
24
+ end
25
+
26
+ File.join(root, 'rubocop_cache')
27
+ end
28
+ end
29
+ end
@@ -98,7 +98,7 @@ module RuboCop
98
98
  def add_inheritance_from_auto_generated_file(config_file)
99
99
  file_string = " #{relative_path_to_todo_from_options_config}"
100
100
 
101
- config_file ||= ConfigLoader::DOTFILE
101
+ config_file ||= ConfigFinder::DOTFILE
102
102
 
103
103
  if File.exist?(config_file)
104
104
  files = Array(ConfigLoader.load_yaml_configuration(config_file)['inherit_from'])
@@ -113,7 +113,7 @@ module RuboCop
113
113
  write_config_file(config_file, file_string, rubocop_yml_contents)
114
114
 
115
115
  puts "Added inheritance from `#{relative_path_to_todo_from_options_config}` " \
116
- "in `#{ConfigLoader::DOTFILE}`."
116
+ "in `#{ConfigFinder::DOTFILE}`."
117
117
  end
118
118
 
119
119
  def existing_configuration(config_file)
@@ -41,13 +41,13 @@ module RuboCop
41
41
 
42
42
  def with_redirect
43
43
  if @options[:stderr]
44
- orig_stdout = $stdout.dup
45
- $stdout.reopen($stderr)
46
-
47
- result = yield
48
-
49
- $stdout.reopen(orig_stdout)
50
- result
44
+ orig_stdout = $stdout
45
+ begin
46
+ $stdout = $stderr
47
+ yield
48
+ ensure
49
+ $stdout = orig_stdout
50
+ end
51
51
  else
52
52
  yield
53
53
  end
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # Generate a .rubocop.yml file in the current directory.
7
7
  # @api private
8
8
  class InitDotfile < Base
9
- DOTFILE = ConfigLoader::DOTFILE
9
+ DOTFILE = ConfigFinder::DOTFILE
10
10
 
11
11
  self.command_name = :init
12
12
 
@@ -17,20 +17,10 @@ module RuboCop
17
17
  def run
18
18
  return if skip? || extensions.none?
19
19
 
20
- puts
21
- puts 'Tip: Based on detected gems, the following ' \
22
- 'RuboCop extension libraries might be helpful:'
23
-
24
- extensions.sort.each do |extension|
25
- puts " * #{extension} (https://rubygems.org/gems/#{extension})"
26
- end
20
+ print_install_suggestions if not_installed_extensions.any?
21
+ print_load_suggestions if installed_and_not_loaded_extensions.any?
27
22
 
28
- puts
29
- puts 'You can opt out of this message by adding the following to your config ' \
30
- '(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions ' \
31
- 'for more options):'
32
- puts ' AllCops:'
33
- puts ' SuggestExtensions: false'
23
+ print_opt_out_instruction
34
24
 
35
25
  puts if @options[:display_time]
36
26
  end
@@ -48,15 +38,63 @@ module RuboCop
48
38
  !INCLUDED_FORMATTERS.include?(current_formatter)
49
39
  end
50
40
 
41
+ def print_install_suggestions
42
+ puts
43
+ puts 'Tip: Based on detected gems, the following ' \
44
+ 'RuboCop extension libraries might be helpful:'
45
+
46
+ not_installed_extensions.sort.each do |extension|
47
+ puts " * #{extension} (https://rubygems.org/gems/#{extension})"
48
+ end
49
+ end
50
+
51
+ def print_load_suggestions
52
+ puts
53
+ puts 'The following RuboCop extension libraries are installed but not loaded in config:'
54
+
55
+ installed_and_not_loaded_extensions.sort.each do |extension|
56
+ puts " * #{extension}"
57
+ end
58
+ end
59
+
60
+ def print_opt_out_instruction
61
+ puts
62
+ puts 'You can opt out of this message by adding the following to your config ' \
63
+ '(see https://docs.rubocop.org/rubocop/extensions.html#extension-suggestions ' \
64
+ 'for more options):'
65
+ puts ' AllCops:'
66
+ puts ' SuggestExtensions: false'
67
+ end
68
+
51
69
  def current_formatter
52
70
  @options[:format] || @config_store.for_pwd.for_all_cops['DefaultFormatter'] || 'p'
53
71
  end
54
72
 
55
- def extensions
73
+ def all_extensions
56
74
  return [] unless lockfile.dependencies.any?
57
75
 
58
76
  extensions = @config_store.for_pwd.for_all_cops['SuggestExtensions'] || {}
59
- extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys - installed_gems
77
+ extensions.select { |_, v| (Array(v) & dependent_gems).any? }.keys
78
+ end
79
+
80
+ def extensions
81
+ not_installed_extensions + installed_and_not_loaded_extensions
82
+ end
83
+
84
+ def installed_extensions
85
+ all_extensions & installed_gems
86
+ end
87
+
88
+ def not_installed_extensions
89
+ all_extensions - installed_gems
90
+ end
91
+
92
+ def loaded_extensions
93
+ @config_store.for_pwd.loaded_features.to_a
94
+ end
95
+
96
+ def installed_and_not_loaded_extensions
97
+ installed_extensions - loaded_extensions
60
98
  end
61
99
 
62
100
  def lockfile
@@ -242,7 +242,7 @@ module RuboCop
242
242
  return nil unless loaded_path
243
243
 
244
244
  base_path = base_dir_for_path_parameters
245
- ['gems.locked', 'Gemfile.lock'].each do |file_name|
245
+ ['Gemfile.lock', 'gems.locked'].each do |file_name|
246
246
  path = find_file_upwards(file_name, base_path)
247
247
  return path if path
248
248
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'file_finder'
4
+
5
+ module RuboCop
6
+ # This class has methods related to finding configuration path.
7
+ # @api private
8
+ class ConfigFinder
9
+ DOTFILE = '.rubocop.yml'
10
+ XDG_CONFIG = 'config.yml'
11
+ RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
12
+ DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
13
+
14
+ class << self
15
+ include FileFinder
16
+
17
+ attr_writer :project_root
18
+
19
+ def find_config_path(target_dir)
20
+ find_project_dotfile(target_dir) || find_user_dotfile || find_user_xdg_config ||
21
+ DEFAULT_FILE
22
+ end
23
+
24
+ # Returns the path RuboCop inferred as the root of the project. No file
25
+ # searches will go past this directory.
26
+ def project_root
27
+ @project_root ||= find_project_root
28
+ end
29
+
30
+ private
31
+
32
+ def find_project_root
33
+ pwd = Dir.pwd
34
+ gems_file = find_last_file_upwards('Gemfile', pwd) || find_last_file_upwards('gems.rb', pwd)
35
+ return unless gems_file
36
+
37
+ File.dirname(gems_file)
38
+ end
39
+
40
+ def find_project_dotfile(target_dir)
41
+ find_file_upwards(DOTFILE, target_dir, project_root)
42
+ end
43
+
44
+ def find_user_dotfile
45
+ return unless ENV.key?('HOME')
46
+
47
+ file = File.join(Dir.home, DOTFILE)
48
+
49
+ return file if File.exist?(file)
50
+ end
51
+
52
+ def find_user_xdg_config
53
+ xdg_config_home = expand_path(ENV.fetch('XDG_CONFIG_HOME', '~/.config'))
54
+ xdg_config = File.join(xdg_config_home, 'rubocop', XDG_CONFIG)
55
+
56
+ return xdg_config if File.exist?(xdg_config)
57
+ end
58
+
59
+ def expand_path(path)
60
+ File.expand_path(path)
61
+ rescue ArgumentError
62
+ # Could happen because HOME or ID could not be determined. Fall back on
63
+ # using the path literally in that case.
64
+ path
65
+ end
66
+ end
67
+ end
68
+ end