rubocop 1.22.3 → 1.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +2 -3
  4. data/config/default.yml +110 -19
  5. data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -1
  6. data/lib/rubocop/cli/command/init_dotfile.rb +1 -1
  7. data/lib/rubocop/cli/command/show_docs_url.rb +48 -0
  8. data/lib/rubocop/cli/command/suggest_extensions.rb +1 -1
  9. data/lib/rubocop/cli.rb +2 -1
  10. data/lib/rubocop/config_loader_resolver.rb +1 -1
  11. data/lib/rubocop/cop/badge.rb +7 -1
  12. data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
  13. data/lib/rubocop/cop/correctors/each_to_for_corrector.rb +1 -1
  14. data/lib/rubocop/cop/correctors/if_then_corrector.rb +55 -0
  15. data/lib/rubocop/cop/documentation.rb +19 -2
  16. data/lib/rubocop/cop/gemspec/date_assignment.rb +2 -10
  17. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -10
  18. data/lib/rubocop/cop/gemspec/require_mfa.rb +145 -0
  19. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +10 -3
  20. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -10
  21. data/lib/rubocop/cop/generator.rb +7 -11
  22. data/lib/rubocop/cop/internal_affairs/redundant_context_config_parameter.rb +46 -0
  23. data/lib/rubocop/cop/internal_affairs/redundant_method_dispatch_node.rb +47 -0
  24. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +3 -1
  25. data/lib/rubocop/cop/internal_affairs.rb +2 -0
  26. data/lib/rubocop/cop/layout/argument_alignment.rb +36 -9
  27. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  28. data/lib/rubocop/cop/layout/comment_indentation.rb +31 -2
  29. data/lib/rubocop/cop/layout/dot_position.rb +4 -0
  30. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +22 -1
  31. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +5 -1
  32. data/lib/rubocop/cop/layout/hash_alignment.rb +7 -2
  33. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +7 -8
  34. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +1 -1
  35. data/lib/rubocop/cop/layout/space_after_colon.rb +1 -1
  36. data/lib/rubocop/cop/layout/space_before_first_arg.rb +4 -0
  37. data/lib/rubocop/cop/layout/space_in_lambda_literal.rb +11 -5
  38. data/lib/rubocop/cop/lint/ambiguous_range.rb +2 -2
  39. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +5 -1
  40. data/lib/rubocop/cop/lint/constant_definition_in_block.rb +1 -1
  41. data/lib/rubocop/cop/lint/deprecated_class_methods.rb +16 -4
  42. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +6 -0
  43. data/lib/rubocop/cop/lint/each_with_object_argument.rb +1 -1
  44. data/lib/rubocop/cop/lint/incompatible_io_select_with_fiber_scheduler.rb +10 -5
  45. data/lib/rubocop/cop/lint/inherit_exception.rb +19 -28
  46. data/lib/rubocop/cop/lint/number_conversion.rb +5 -2
  47. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +10 -6
  48. data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +5 -0
  49. data/lib/rubocop/cop/lint/symbol_conversion.rb +3 -2
  50. data/lib/rubocop/cop/lint/useless_ruby2_keywords.rb +117 -0
  51. data/lib/rubocop/cop/lint/useless_times.rb +13 -9
  52. data/lib/rubocop/cop/metrics/block_length.rb +1 -0
  53. data/lib/rubocop/cop/metrics/cyclomatic_complexity.rb +0 -9
  54. data/lib/rubocop/cop/metrics/method_length.rb +1 -0
  55. data/lib/rubocop/cop/metrics/module_length.rb +1 -1
  56. data/lib/rubocop/cop/metrics/parameter_lists.rb +1 -1
  57. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  58. data/lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb +1 -1
  59. data/lib/rubocop/cop/mixin/enforce_superclass.rb +5 -0
  60. data/lib/rubocop/cop/mixin/gemspec_help.rb +30 -0
  61. data/lib/rubocop/cop/mixin/hash_alignment_styles.rb +4 -3
  62. data/lib/rubocop/cop/mixin/hash_shorthand_syntax.rb +82 -0
  63. data/lib/rubocop/cop/mixin/line_length_help.rb +17 -6
  64. data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +3 -1
  65. data/lib/rubocop/cop/mixin/string_literals_help.rb +1 -5
  66. data/lib/rubocop/cop/naming/block_forwarding.rb +121 -0
  67. data/lib/rubocop/cop/naming/file_name.rb +37 -4
  68. data/lib/rubocop/cop/naming/method_parameter_name.rb +1 -1
  69. data/lib/rubocop/cop/security/open.rb +11 -1
  70. data/lib/rubocop/cop/security/yaml_load.rb +9 -3
  71. data/lib/rubocop/cop/style/character_literal.rb +8 -1
  72. data/lib/rubocop/cop/style/collection_compact.rb +31 -13
  73. data/lib/rubocop/cop/style/combinable_loops.rb +2 -2
  74. data/lib/rubocop/cop/style/def_with_parentheses.rb +16 -11
  75. data/lib/rubocop/cop/style/documentation.rb +1 -1
  76. data/lib/rubocop/cop/style/empty_case_condition.rb +10 -0
  77. data/lib/rubocop/cop/style/empty_method.rb +1 -1
  78. data/lib/rubocop/cop/style/file_read.rb +112 -0
  79. data/lib/rubocop/cop/style/file_write.rb +124 -0
  80. data/lib/rubocop/cop/style/for.rb +4 -0
  81. data/lib/rubocop/cop/style/format_string_token.rb +2 -1
  82. data/lib/rubocop/cop/style/hash_conversion.rb +2 -1
  83. data/lib/rubocop/cop/style/hash_syntax.rb +36 -0
  84. data/lib/rubocop/cop/style/hash_transform_keys.rb +6 -6
  85. data/lib/rubocop/cop/style/hash_transform_values.rb +6 -6
  86. data/lib/rubocop/cop/style/if_inside_else.rb +15 -0
  87. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +1 -1
  88. data/lib/rubocop/cop/style/lambda_call.rb +12 -20
  89. data/lib/rubocop/cop/style/map_to_hash.rb +68 -0
  90. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +20 -0
  91. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +3 -1
  92. data/lib/rubocop/cop/style/method_def_parentheses.rb +17 -13
  93. data/lib/rubocop/cop/style/nested_file_dirname.rb +66 -0
  94. data/lib/rubocop/cop/style/numeric_literals.rb +10 -1
  95. data/lib/rubocop/cop/style/one_line_conditional.rb +18 -39
  96. data/lib/rubocop/cop/style/open_struct_use.rb +69 -0
  97. data/lib/rubocop/cop/style/optional_boolean_parameter.rb +3 -2
  98. data/lib/rubocop/cop/style/parentheses_around_condition.rb +12 -2
  99. data/lib/rubocop/cop/style/quoted_symbols.rb +11 -1
  100. data/lib/rubocop/cop/style/redundant_begin.rb +2 -6
  101. data/lib/rubocop/cop/style/redundant_interpolation.rb +17 -3
  102. data/lib/rubocop/cop/style/redundant_regexp_character_class.rb +5 -1
  103. data/lib/rubocop/cop/style/redundant_self.rb +1 -1
  104. data/lib/rubocop/cop/style/safe_navigation.rb +1 -5
  105. data/lib/rubocop/cop/style/sample.rb +5 -3
  106. data/lib/rubocop/cop/style/select_by_regexp.rb +6 -1
  107. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -2
  108. data/lib/rubocop/cop/style/sole_nested_conditional.rb +53 -13
  109. data/lib/rubocop/cop/style/string_concatenation.rb +7 -1
  110. data/lib/rubocop/cop/style/swap_values.rb +2 -0
  111. data/lib/rubocop/cop/style/ternary_parentheses.rb +16 -2
  112. data/lib/rubocop/cop/style/trailing_comma_in_array_literal.rb +1 -1
  113. data/lib/rubocop/cop/style/trailing_comma_in_hash_literal.rb +1 -1
  114. data/lib/rubocop/cop/style/unless_else.rb +4 -0
  115. data/lib/rubocop/cop/team.rb +1 -1
  116. data/lib/rubocop/cop/util.rb +9 -1
  117. data/lib/rubocop/cop/variable_force.rb +1 -5
  118. data/lib/rubocop/cops_documentation_generator.rb +2 -2
  119. data/lib/rubocop/formatter/disabled_config_formatter.rb +16 -2
  120. data/lib/rubocop/formatter/html_formatter.rb +5 -2
  121. data/lib/rubocop/formatter/json_formatter.rb +4 -1
  122. data/lib/rubocop/options.rb +14 -3
  123. data/lib/rubocop/remote_config.rb +2 -4
  124. data/lib/rubocop/result_cache.rb +1 -1
  125. data/lib/rubocop/rspec/shared_contexts.rb +4 -0
  126. data/lib/rubocop/runner.rb +1 -1
  127. data/lib/rubocop/target_ruby.rb +1 -1
  128. data/lib/rubocop/version.rb +1 -1
  129. data/lib/rubocop/yaml_duplication_checker.rb +1 -1
  130. data/lib/rubocop.rb +12 -0
  131. metadata +22 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f74b024d0339618cd4782bd451e3bbe8be65eab0a5f3dbfc1d2137c74848c6fa
4
- data.tar.gz: ef762c615b2d68f52d5aac425abea13a40d097f1b7885cd1558a991dd23c136d
3
+ metadata.gz: 10e6b8905d81b2204fd3d0bf60d3278cd902d0cefc2ed387bf2c317062b46034
4
+ data.tar.gz: f27011464d465728f1fa470c85c4779c2b148b3cdc872247c5a25d421f269076
5
5
  SHA512:
6
- metadata.gz: bfdba4bbc01e69d2a0873272815dc9c03d5e95f2dce5f02186b38f2f9e1e28ae34df246e6b548cdccf0831bace4f02bfad334f59548b2bf67430431b5760731b
7
- data.tar.gz: 662e06452c13b66a949e7a8035bc6b4b31e7af7a3cf161b9802634365a53a0b2452aeb7741ab13387186483cdf9027dc5cca736734d5d3022f78362bfabf9a5c
6
+ metadata.gz: 215ee2bb6f0699fdedcd82c7795c40e2350c33fdfbd48117dbb2fdcaa957bcbff9a65ad9c95b9666d4b9c70d6a2e2d8b6ec6904c3c3f01cbbfa8fee2319c9518
7
+ data.tar.gz: 0b33b7c3aecf2b7482e19cdbf1a94a56f21d3cb14035c68c62ce0572385edb34a59faa1ea5fb21d9504b04e18f797b0419c6ade76ff70604311b9f899e28b39d
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-21 Bozhidar Batsov
1
+ Copyright (c) 2012-22 Bozhidar Batsov
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -9,7 +9,6 @@
9
9
  [![Actions Status](https://github.com/rubocop/rubocop/workflows/CI/badge.svg?branch=master)](https://github.com/rubocop/rubocop/actions?query=workflow%3ACI)
10
10
  [![Test Coverage](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/test_coverage)](https://codeclimate.com/github/rubocop/rubocop/test_coverage)
11
11
  [![Maintainability](https://api.codeclimate.com/v1/badges/d2d67f728e88ea84ac69/maintainability)](https://codeclimate.com/github/rubocop/rubocop/maintainability)
12
- [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=rubocop&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=rubocop&package-manager=bundler&version-scheme=semver)
13
12
  [![Discord](https://img.shields.io/badge/chat-on%20discord-7289da.svg?sanitize=true)](https://discord.gg/wJjWvGRDmm)
14
13
 
15
14
  > Role models are important. <br/>
@@ -54,7 +53,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
54
53
  in your `Gemfile`:
55
54
 
56
55
  ```rb
57
- gem 'rubocop', '~> 1.22', require: false
56
+ gem 'rubocop', '~> 1.26', require: false
58
57
  ```
59
58
 
60
59
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
@@ -245,5 +244,5 @@ RuboCop's changelog is available [here](CHANGELOG.md).
245
244
 
246
245
  ## Copyright
247
246
 
248
- Copyright (c) 2012-2021 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
247
+ Copyright (c) 2012-2022 Bozhidar Batsov. See [LICENSE.txt](LICENSE.txt) for
249
248
  further details.
data/config/default.yml CHANGED
@@ -78,6 +78,8 @@ AllCops:
78
78
  # When specifying style guide URLs, any paths and/or fragments will be
79
79
  # evaluated relative to the base URL.
80
80
  StyleGuideBaseURL: https://rubystyle.guide
81
+ # Documentation URLs will be constructed using the base URL.
82
+ DocumentationBaseURL: https://docs.rubocop.org/rubocop
81
83
  # Extra details are not displayed in offense messages by default. Change
82
84
  # behavior by overriding ExtraDetails, or by giving the
83
85
  # `-E/--extra-details` option.
@@ -150,6 +152,7 @@ AllCops:
150
152
  rubocop-minitest: [minitest]
151
153
  rubocop-sequel: [sequel]
152
154
  rubocop-rake: [rake]
155
+ rubocop-graphql: [graphql]
153
156
 
154
157
  #################### Bundler ###############################
155
158
 
@@ -258,6 +261,15 @@ Gemspec/OrderedDependencies:
258
261
  Include:
259
262
  - '**/*.gemspec'
260
263
 
264
+ Gemspec/RequireMFA:
265
+ Description: 'Checks that the gemspec has metadata to require Multi-Factor Authentication from RubyGems.'
266
+ Enabled: pending
267
+ VersionAdded: '1.23'
268
+ Reference:
269
+ - https://guides.rubygems.org/mfa-requirement-opt-in/
270
+ Include:
271
+ - '**/*.gemspec'
272
+
261
273
  Gemspec/RequiredRubyVersion:
262
274
  Description: 'Checks that `required_ruby_version` of gemspec is specified and equal to `TargetRubyVersion` of .rubocop.yml.'
263
275
  Enabled: true
@@ -418,13 +430,13 @@ Layout/ClassStructure:
418
430
  - prepend
419
431
  - extend
420
432
  ExpectedOrder:
421
- - module_inclusion
422
- - constants
423
- - public_class_methods
424
- - initializer
425
- - public_methods
426
- - protected_methods
427
- - private_methods
433
+ - module_inclusion
434
+ - constants
435
+ - public_class_methods
436
+ - initializer
437
+ - public_methods
438
+ - protected_methods
439
+ - private_methods
428
440
 
429
441
  Layout/ClosingHeredocIndentation:
430
442
  Description: 'Checks the indentation of here document closings.'
@@ -439,7 +451,11 @@ Layout/ClosingParenthesisIndentation:
439
451
  Layout/CommentIndentation:
440
452
  Description: 'Indentation of comments.'
441
453
  Enabled: true
454
+ # When true, allows comments to have extra indentation if that aligns them
455
+ # with a comment on the preceding line.
456
+ AllowForAlignment: false
442
457
  VersionAdded: '0.49'
458
+ VersionChanged: '1.24'
443
459
 
444
460
  Layout/ConditionPosition:
445
461
  Description: >-
@@ -511,13 +527,13 @@ Layout/EmptyLineBetweenDefs:
511
527
  StyleGuide: '#empty-lines-between-methods'
512
528
  Enabled: true
513
529
  VersionAdded: '0.49'
514
- VersionChanged: '1.7'
530
+ VersionChanged: '1.23'
515
531
  EmptyLineBetweenMethodDefs: true
516
532
  EmptyLineBetweenClassDefs: true
517
533
  EmptyLineBetweenModuleDefs: true
518
- # If `true`, this parameter means that single line method definitions don't
519
- # need an empty line between them.
520
- AllowAdjacentOneLineDefs: false
534
+ # `AllowAdjacentOneLineDefs` means that single line method definitions don't
535
+ # need an empty line between them. `true` by default.
536
+ AllowAdjacentOneLineDefs: true
521
537
  # Can be array to specify minimum and maximum number of empty lines, e.g. [1, 2]
522
538
  NumberOfEmptyLines: 1
523
539
 
@@ -1786,7 +1802,9 @@ Lint/ImplicitStringConcatenation:
1786
1802
  Lint/IncompatibleIoSelectWithFiberScheduler:
1787
1803
  Description: 'Checks for `IO.select` that is incompatible with Fiber Scheduler.'
1788
1804
  Enabled: pending
1805
+ SafeAutoCorrect: false
1789
1806
  VersionAdded: '1.21'
1807
+ VersionChanged: '1.24'
1790
1808
 
1791
1809
  Lint/IneffectiveAccessModifier:
1792
1810
  Description: >-
@@ -1798,12 +1816,14 @@ Lint/IneffectiveAccessModifier:
1798
1816
  Lint/InheritException:
1799
1817
  Description: 'Avoid inheriting from the `Exception` class.'
1800
1818
  Enabled: true
1819
+ SafeAutoCorrect: false
1801
1820
  VersionAdded: '0.41'
1821
+ VersionChanged: '1.26'
1802
1822
  # The default base class in favour of `Exception`.
1803
- EnforcedStyle: runtime_error
1823
+ EnforcedStyle: standard_error
1804
1824
  SupportedStyles:
1805
- - runtime_error
1806
1825
  - standard_error
1826
+ - runtime_error
1807
1827
 
1808
1828
  Lint/InterpolationCheck:
1809
1829
  Description: 'Raise warning for interpolation in single q strs.'
@@ -1882,7 +1902,7 @@ Lint/NestedPercentLiteral:
1882
1902
  VersionAdded: '0.52'
1883
1903
 
1884
1904
  Lint/NextWithoutAccumulator:
1885
- Description: >-
1905
+ Description: >-
1886
1906
  Do not omit the accumulator when calling `next`
1887
1907
  in a `reduce`/`inject` block.
1888
1908
  Enabled: true
@@ -1993,6 +2013,8 @@ Lint/RedundantDirGlobSort:
1993
2013
  Description: 'Checks for redundant `sort` method to `Dir.glob` and `Dir[]`.'
1994
2014
  Enabled: pending
1995
2015
  VersionAdded: '1.8'
2016
+ VersionChanged: '1.26'
2017
+ SafeAutoCorrect: false
1996
2018
 
1997
2019
  Lint/RedundantRequireStatement:
1998
2020
  Description: 'Checks for unnecessary `require` statement.'
@@ -2308,6 +2330,11 @@ Lint/UselessMethodDefinition:
2308
2330
  Safe: false
2309
2331
  AllowComments: true
2310
2332
 
2333
+ Lint/UselessRuby2Keywords:
2334
+ Description: 'Finds unnecessary uses of `ruby2_keywords`.'
2335
+ Enabled: pending
2336
+ VersionAdded: '1.23'
2337
+
2311
2338
  Lint/UselessSetterCall:
2312
2339
  Description: 'Checks for useless setter call to a local variable.'
2313
2340
  Enabled: true
@@ -2464,6 +2491,17 @@ Naming/BinaryOperatorParameterName:
2464
2491
  VersionAdded: '0.50'
2465
2492
  VersionChanged: '1.2'
2466
2493
 
2494
+ Naming/BlockForwarding:
2495
+ Description: 'Use anonymous block forwarding.'
2496
+ StyleGuide: '#block-forwarding'
2497
+ Enabled: pending
2498
+ VersionAdded: '1.24'
2499
+ EnforcedStyle: anonymous
2500
+ SupportedStyles:
2501
+ - anonymous
2502
+ - explicit
2503
+ BlockForwardingName: block
2504
+
2467
2505
  Naming/BlockParameterName:
2468
2506
  Description: >-
2469
2507
  Checks for block parameter names that contain capital letters,
@@ -2501,6 +2539,7 @@ Naming/FileName:
2501
2539
  StyleGuide: '#snake-case-files'
2502
2540
  Enabled: true
2503
2541
  VersionAdded: '0.50'
2542
+ VersionChanged: '1.23'
2504
2543
  # Camel case file names listed in `AllCops:Include` and all file names listed
2505
2544
  # in `AllCops:Exclude` are excluded by default. Add extra excludes here.
2506
2545
  Exclude: []
@@ -2513,6 +2552,13 @@ Naming/FileName:
2513
2552
  # whether each source file's class or module name matches the file name --
2514
2553
  # not whether the nested module hierarchy matches the subdirectory path.
2515
2554
  CheckDefinitionPathHierarchy: true
2555
+ # paths that are considered root directories, for example "lib" in most ruby projects
2556
+ # or "app/models" in rails projects
2557
+ CheckDefinitionPathHierarchyRoots:
2558
+ - lib
2559
+ - spec
2560
+ - test
2561
+ - src
2516
2562
  # If non-`nil`, expect all source file names to match the following regex.
2517
2563
  # Only the file name itself is matched, not the entire file path.
2518
2564
  # Use anchors as necessary if you want to match the entire name rather than
@@ -3111,7 +3157,7 @@ Style/ClassMethodsDefinitions:
3111
3157
  StyleGuide: '#def-self-class-methods'
3112
3158
  Enabled: false
3113
3159
  VersionAdded: '0.89'
3114
- EnforcedStyle: def_self
3160
+ EnforcedStyle: def_self
3115
3161
  SupportedStyles:
3116
3162
  - def_self
3117
3163
  - self_class
@@ -3469,6 +3515,18 @@ Style/ExponentialNotation:
3469
3515
  - engineering
3470
3516
  - integral
3471
3517
 
3518
+ Style/FileRead:
3519
+ Description: 'Favor `File.(bin)read` convenience methods.'
3520
+ StyleGuide: '#file-read'
3521
+ Enabled: pending
3522
+ VersionAdded: '1.24'
3523
+
3524
+ Style/FileWrite:
3525
+ Description: 'Favor `File.(bin)write` convenience methods.'
3526
+ StyleGuide: '#file-write'
3527
+ Enabled: pending
3528
+ VersionAdded: '1.24'
3529
+
3472
3530
  Style/FloatDivision:
3473
3531
  Description: 'For performing float division, coerce one side only.'
3474
3532
  StyleGuide: '#float-division'
@@ -3488,8 +3546,9 @@ Style/For:
3488
3546
  Description: 'Checks use of for or each in multiline loops.'
3489
3547
  StyleGuide: '#no-for-loops'
3490
3548
  Enabled: true
3549
+ SafeAutoCorrect: false
3491
3550
  VersionAdded: '0.13'
3492
- VersionChanged: '0.59'
3551
+ VersionChanged: '1.26'
3493
3552
  EnforcedStyle: each
3494
3553
  SupportedStyles:
3495
3554
  - each
@@ -3627,7 +3686,7 @@ Style/HashSyntax:
3627
3686
  StyleGuide: '#hash-literals'
3628
3687
  Enabled: true
3629
3688
  VersionAdded: '0.9'
3630
- VersionChanged: '0.43'
3689
+ VersionChanged: '1.24'
3631
3690
  EnforcedStyle: ruby19
3632
3691
  SupportedStyles:
3633
3692
  # checks for 1.9 syntax (e.g. {a: 1}) for all symbol keys
@@ -3638,6 +3697,15 @@ Style/HashSyntax:
3638
3697
  - no_mixed_keys
3639
3698
  # enforces both ruby19 and no_mixed_keys styles
3640
3699
  - ruby19_no_mixed_keys
3700
+ # Force hashes that have a hash value omission
3701
+ EnforcedShorthandSyntax: always
3702
+ SupportedShorthandSyntax:
3703
+ # forces use of the 3.1 syntax (e.g. {foo:}) when the hash key and value are the same.
3704
+ - always
3705
+ # forces use of explicit hash literal value.
3706
+ - never
3707
+ # accepts both shorthand and explicit use of hash literal value.
3708
+ - either
3641
3709
  # Force hashes that have a symbol value to use hash rockets
3642
3710
  UseHashRocketsWithSymbolValues: false
3643
3711
  # Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style
@@ -3752,8 +3820,8 @@ Style/InverseMethods:
3752
3820
  :>: :<=
3753
3821
  # `ActiveSupport` defines some common inverse methods. They are listed below,
3754
3822
  # and not enabled by default.
3755
- #:present?: :blank?,
3756
- #:include?: :exclude?
3823
+ # :present?: :blank?,
3824
+ # :include?: :exclude?
3757
3825
  # `InverseBlocks` are methods that are inverted by inverting the return
3758
3826
  # of the block that is passed to the method
3759
3827
  InverseBlocks:
@@ -3814,6 +3882,12 @@ Style/LineEndConcatenation:
3814
3882
  VersionAdded: '0.18'
3815
3883
  VersionChanged: '0.64'
3816
3884
 
3885
+ Style/MapToHash:
3886
+ Description: 'Prefer `to_h` with a block over `map.to_h`.'
3887
+ Enabled: pending
3888
+ VersionAdded: '1.24'
3889
+ Safe: false
3890
+
3817
3891
  Style/MethodCallWithArgsParentheses:
3818
3892
  Description: 'Use parentheses for method calls with arguments.'
3819
3893
  StyleGuide: '#method-invocation-parens'
@@ -4053,6 +4127,11 @@ Style/NegatedWhile:
4053
4127
  Enabled: true
4054
4128
  VersionAdded: '0.20'
4055
4129
 
4130
+ Style/NestedFileDirname:
4131
+ Description: 'Checks for nested `File.dirname`.'
4132
+ Enabled: pending
4133
+ VersionAdded: '1.26'
4134
+
4056
4135
  Style/NestedModifier:
4057
4136
  Description: 'Avoid using nested modifiers.'
4058
4137
  StyleGuide: '#no-nested-modifiers'
@@ -4182,6 +4261,8 @@ Style/NumericLiterals:
4182
4261
  VersionChanged: '0.48'
4183
4262
  MinDigits: 5
4184
4263
  Strict: false
4264
+ # You can specify allowed numbers. (e.g. port number 3000, 8080, and etc)
4265
+ AllowedNumbers: []
4185
4266
 
4186
4267
  Style/NumericPredicate:
4187
4268
  Description: >-
@@ -4216,6 +4297,16 @@ Style/OneLineConditional:
4216
4297
  VersionAdded: '0.9'
4217
4298
  VersionChanged: '0.90'
4218
4299
 
4300
+ Style/OpenStructUse:
4301
+ Description: >-
4302
+ Avoid using OpenStruct. As of Ruby 3.0, use is officially discouraged due to performance,
4303
+ version compatibility, and potential security issues.
4304
+ Reference:
4305
+ - https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats
4306
+
4307
+ Enabled: pending
4308
+ VersionAdded: '1.23'
4309
+
4219
4310
  Style/OptionHash:
4220
4311
  Description: "Don't use option hashes when you can use keyword arguments."
4221
4312
  Enabled: false
@@ -124,7 +124,7 @@ module RuboCop
124
124
  lines = /\S/.match?(rubocop_yml_contents) ? rubocop_yml_contents.split("\n", -1) : []
125
125
  doc_start_index = lines.index { |line| YAML_OPTIONAL_DOC_START.match?(line) } || -1
126
126
  lines.insert(doc_start_index + 1, "inherit_from:#{file_string}\n")
127
- File.open(file_name, 'w') { |f| f.write lines.join("\n") }
127
+ File.write(file_name, lines.join("\n"))
128
128
  end
129
129
  end
130
130
  end
@@ -31,7 +31,7 @@ module RuboCop
31
31
  # See https://docs.rubocop.org/rubocop/configuration
32
32
  DESC
33
33
 
34
- File.open(DOTFILE, 'w') { |f| f.write(description) }
34
+ File.write(DOTFILE, description)
35
35
 
36
36
  puts "Writing new #{DOTFILE} to #{path}"
37
37
 
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ class CLI
5
+ module Command
6
+ # Prints out url to documentation of provided cops
7
+ # or documentation base url by default.
8
+ # @api private
9
+ class ShowDocsUrl < Base
10
+ self.command_name = :show_docs_url
11
+
12
+ def initialize(env)
13
+ super
14
+
15
+ @config = @config_store.for(Dir.pwd)
16
+ end
17
+
18
+ def run
19
+ print_documentation_url
20
+ end
21
+
22
+ private
23
+
24
+ def print_documentation_url
25
+ puts Cop::Documentation.default_base_url if cops_array.empty?
26
+
27
+ cops_array.each do |cop_name|
28
+ cop = registry_hash[cop_name]
29
+
30
+ next if cop.empty?
31
+
32
+ puts Cop::Documentation.url_for(cop.first, @config)
33
+ end
34
+
35
+ puts
36
+ end
37
+
38
+ def cops_array
39
+ @cops_array ||= @options[:show_docs_url]
40
+ end
41
+
42
+ def registry_hash
43
+ @registry_hash ||= Cop::Registry.global.to_h
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -22,7 +22,7 @@ module RuboCop
22
22
  'RuboCop extension libraries might be helpful:'
23
23
 
24
24
  extensions.sort.each do |extension|
25
- puts " * #{extension} (https://github.com/rubocop/#{extension})"
25
+ puts " * #{extension} (https://rubygems.org/gems/#{extension})"
26
26
  end
27
27
 
28
28
  puts
data/lib/rubocop/cli.rb CHANGED
@@ -14,7 +14,7 @@ module RuboCop
14
14
  ignore_disable_comments lint only only_guide_cops require safe
15
15
  ].freeze
16
16
 
17
- class Finished < RuntimeError; end
17
+ class Finished < StandardError; end
18
18
 
19
19
  attr_reader :options, :config_store
20
20
 
@@ -131,6 +131,7 @@ module RuboCop
131
131
 
132
132
  run_command(:version) if @options[:version] || @options[:verbose_version]
133
133
  run_command(:show_cops) if @options[:show_cops]
134
+ run_command(:show_docs_url) if @options[:show_docs_url]
134
135
  raise Finished
135
136
  end
136
137
 
@@ -74,7 +74,7 @@ module RuboCop
74
74
  # Merges the given configuration with the default one. If
75
75
  # AllCops:DisabledByDefault is true, it changes the Enabled params so that
76
76
  # only cops from user configuration are enabled. If
77
- # AllCops::EnabledByDefault is true, it changes the Enabled params so that
77
+ # AllCops:EnabledByDefault is true, it changes the Enabled params so that
78
78
  # only cops explicitly disabled in user configuration are disabled.
79
79
  def merge_with_default(config, config_file, unset_nil:)
80
80
  default_configuration = ConfigLoader.default_configuration
@@ -19,7 +19,13 @@ module RuboCop
19
19
  end
20
20
 
21
21
  def self.parse(identifier)
22
- new(identifier.split('/'))
22
+ new(identifier.split('/').map { |i| camel_case(i) })
23
+ end
24
+
25
+ def self.camel_case(name_part)
26
+ return 'RSpec' if name_part == 'rspec'
27
+
28
+ name_part.gsub(/^\w|_\w/) { |match| match[-1, 1].upcase }
23
29
  end
24
30
 
25
31
  def initialize(class_name_parts)
@@ -68,7 +68,7 @@ module RuboCop
68
68
  end
69
69
 
70
70
  def conditional_declaration?(nodes)
71
- parent = nodes[0].parent
71
+ parent = nodes[0].each_ancestor.find { |ancestor| !ancestor.begin_type? }
72
72
  return false unless parent&.if_type? || parent&.when_type?
73
73
 
74
74
  root_conditional_node = parent.if_type? ? parent : parent.parent
@@ -11,7 +11,7 @@ module RuboCop
11
11
 
12
12
  def initialize(block_node)
13
13
  @block_node = block_node
14
- @collection_node = block_node.send_node.receiver
14
+ @collection_node = block_node.receiver
15
15
  @argument_node = block_node.arguments
16
16
  end
17
17
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ # This class auto-corrects `if...then` structures to a multiline `if` statement
6
+ class IfThenCorrector
7
+ DEFAULT_INDENTATION_WIDTH = 2
8
+
9
+ def initialize(if_node, indentation: nil)
10
+ @if_node = if_node
11
+ @indentation = indentation || DEFAULT_INDENTATION_WIDTH
12
+ end
13
+
14
+ def call(corrector)
15
+ corrector.replace(if_node, replacement)
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :if_node, :indentation
21
+
22
+ def replacement(node = if_node, indentation = nil)
23
+ indentation = ' ' * node.source_range.column if indentation.nil?
24
+ if_branch_source = node.if_branch&.source || 'nil'
25
+ elsif_indentation = indentation if node.respond_to?(:elsif?) && node.elsif?
26
+
27
+ if_branch = <<~RUBY
28
+ #{elsif_indentation}#{node.keyword} #{node.condition.source}
29
+ #{indentation}#{branch_body_indentation}#{if_branch_source}
30
+ RUBY
31
+
32
+ else_branch = rewrite_else_branch(node.else_branch, indentation)
33
+ if_branch + else_branch
34
+ end
35
+
36
+ def rewrite_else_branch(else_branch, indentation)
37
+ if else_branch.nil?
38
+ 'end'
39
+ elsif else_branch.if_type? && else_branch.elsif?
40
+ replacement(else_branch, indentation)
41
+ else
42
+ <<~RUBY.chomp
43
+ #{indentation}else
44
+ #{indentation}#{branch_body_indentation}#{else_branch.source}
45
+ #{indentation}end
46
+ RUBY
47
+ end
48
+ end
49
+
50
+ def branch_body_indentation
51
+ @branch_body_indentation ||= (' ' * indentation).freeze
52
+ end
53
+ end
54
+ end
55
+ end
@@ -12,10 +12,27 @@ module RuboCop
12
12
  end
13
13
 
14
14
  # @api private
15
- def url_for(cop_class)
15
+ def url_for(cop_class, config = nil)
16
16
  base = department_to_basename(cop_class.department)
17
17
  fragment = cop_class.cop_name.downcase.gsub(/[^a-z]/, '')
18
- "https://docs.rubocop.org/rubocop/#{base}.html##{fragment}"
18
+ base_url = base_url_for(cop_class, config)
19
+
20
+ "#{base_url}/#{base}.html##{fragment}"
21
+ end
22
+
23
+ # @api private
24
+ def base_url_for(cop_class, config)
25
+ return default_base_url unless config
26
+
27
+ department_name = cop_class.department.to_s
28
+
29
+ config.for_department(department_name)['DocumentationBaseURL'] ||
30
+ config.for_all_cops['DocumentationBaseURL']
31
+ end
32
+
33
+ # @api private
34
+ def default_base_url
35
+ 'https://docs.rubocop.org/rubocop'
19
36
  end
20
37
  end
21
38
  end
@@ -21,21 +21,13 @@ module RuboCop
21
21
  #
22
22
  class DateAssignment < Base
23
23
  include RangeHelp
24
+ include GemspecHelp
24
25
  extend AutoCorrector
25
26
 
26
27
  MSG = 'Do not use `date =` in gemspec, it is set automatically when the gem is packaged.'
27
28
 
28
- # @!method gem_specification(node)
29
- def_node_matcher :gem_specification, <<~PATTERN
30
- (block
31
- (send
32
- (const
33
- (const {cbase nil?} :Gem) :Specification) :new)
34
- ...)
35
- PATTERN
36
-
37
29
  def on_block(block_node)
38
- return unless gem_specification(block_node)
30
+ return unless gem_specification?(block_node)
39
31
 
40
32
  block_parameter = block_node.arguments.first.source
41
33
 
@@ -36,20 +36,11 @@ module RuboCop
36
36
  # end
37
37
  class DuplicatedAssignment < Base
38
38
  include RangeHelp
39
+ include GemspecHelp
39
40
 
40
41
  MSG = '`%<assignment>s` method calls already given on line '\
41
42
  '%<line_of_first_occurrence>d of the gemspec.'
42
43
 
43
- # @!method gem_specification(node)
44
- def_node_search :gem_specification, <<~PATTERN
45
- (block
46
- (send
47
- (const
48
- (const {cbase nil?} :Gem) :Specification) :new)
49
- (args
50
- (arg $_)) ...)
51
- PATTERN
52
-
53
44
  # @!method assignment_method_declarations(node)
54
45
  def_node_search :assignment_method_declarations, <<~PATTERN
55
46
  (send