rubocop 1.64.1 → 1.65.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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/config/default.yml +11 -1
  4. data/lib/rubocop/config_loader.rb +1 -1
  5. data/lib/rubocop/config_loader_resolver.rb +9 -3
  6. data/lib/rubocop/cop/cop.rb +22 -4
  7. data/lib/rubocop/cop/gemspec/add_runtime_dependency.rb +38 -0
  8. data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
  9. data/lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb +3 -3
  10. data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
  11. data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
  12. data/lib/rubocop/cop/layout/condition_position.rb +0 -4
  13. data/lib/rubocop/cop/layout/empty_line_after_multiline_condition.rb +1 -1
  14. data/lib/rubocop/cop/layout/first_argument_indentation.rb +2 -2
  15. data/lib/rubocop/cop/layout/heredoc_indentation.rb +1 -1
  16. data/lib/rubocop/cop/layout/indentation_width.rb +1 -1
  17. data/lib/rubocop/cop/layout/line_length.rb +20 -20
  18. data/lib/rubocop/cop/layout/space_around_operators.rb +3 -0
  19. data/lib/rubocop/cop/legacy/corrector.rb +12 -2
  20. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +0 -2
  21. data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
  22. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
  23. data/lib/rubocop/cop/lint/boolean_symbol.rb +0 -2
  24. data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -13
  25. data/lib/rubocop/cop/lint/debugger.rb +0 -4
  26. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +0 -10
  27. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +1 -5
  28. data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
  29. data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -10
  30. data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
  31. data/lib/rubocop/cop/lint/else_layout.rb +0 -2
  32. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -11
  33. data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -4
  34. data/lib/rubocop/cop/lint/empty_when.rb +1 -3
  35. data/lib/rubocop/cop/lint/ensure_return.rb +1 -6
  36. data/lib/rubocop/cop/lint/float_comparison.rb +3 -1
  37. data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -4
  38. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -10
  39. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +15 -12
  40. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
  41. data/lib/rubocop/cop/lint/interpolation_check.rb +0 -4
  42. data/lib/rubocop/cop/lint/literal_as_condition.rb +1 -1
  43. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
  44. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +0 -4
  45. data/lib/rubocop/cop/lint/loop.rb +6 -12
  46. data/lib/rubocop/cop/lint/nested_method_definition.rb +1 -7
  47. data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -4
  48. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +0 -5
  49. data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
  50. data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
  51. data/lib/rubocop/cop/lint/rand_one.rb +0 -4
  52. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +3 -1
  53. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  54. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +0 -4
  55. data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
  56. data/lib/rubocop/cop/lint/rescue_exception.rb +0 -4
  57. data/lib/rubocop/cop/lint/return_in_void_context.rb +0 -2
  58. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +0 -4
  59. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +6 -10
  60. data/lib/rubocop/cop/lint/to_enum_arguments.rb +2 -9
  61. data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
  62. data/lib/rubocop/cop/lint/unmodified_reduce_accumulator.rb +1 -0
  63. data/lib/rubocop/cop/lint/unreachable_code.rb +0 -5
  64. data/lib/rubocop/cop/lint/useless_assignment.rb +1 -5
  65. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -4
  66. data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -4
  67. data/lib/rubocop/cop/lint/void.rb +5 -0
  68. data/lib/rubocop/cop/metrics/block_nesting.rb +19 -7
  69. data/lib/rubocop/cop/mixin/alignment.rb +5 -1
  70. data/lib/rubocop/cop/mixin/allowed_methods.rb +7 -1
  71. data/lib/rubocop/cop/mixin/allowed_pattern.rb +15 -3
  72. data/lib/rubocop/cop/mixin/configurable_max.rb +5 -1
  73. data/lib/rubocop/cop/mixin/rescue_node.rb +4 -0
  74. data/lib/rubocop/cop/naming/predicate_name.rb +52 -26
  75. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -1
  76. data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -1
  77. data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -2
  78. data/lib/rubocop/cop/style/each_for_simple_loop.rb +0 -1
  79. data/lib/rubocop/cop/style/eval_with_location.rb +12 -11
  80. data/lib/rubocop/cop/style/file_read.rb +2 -5
  81. data/lib/rubocop/cop/style/file_write.rb +2 -5
  82. data/lib/rubocop/cop/style/global_std_stream.rb +7 -1
  83. data/lib/rubocop/cop/style/hash_except.rb +8 -5
  84. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +0 -1
  85. data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
  86. data/lib/rubocop/cop/style/map_compact_with_conditional_block.rb +77 -43
  87. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +5 -0
  88. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
  89. data/lib/rubocop/cop/style/missing_else.rb +0 -4
  90. data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
  91. data/lib/rubocop/cop/style/quoted_symbols.rb +1 -1
  92. data/lib/rubocop/cop/style/redundant_begin.rb +1 -1
  93. data/lib/rubocop/cop/style/redundant_condition.rb +0 -1
  94. data/lib/rubocop/cop/style/redundant_file_extension_in_require.rb +1 -1
  95. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -24
  96. data/lib/rubocop/cop/style/send_with_literal_method_name.rb +15 -1
  97. data/lib/rubocop/cop/style/sole_nested_conditional.rb +21 -2
  98. data/lib/rubocop/cop/style/super_arguments.rb +28 -10
  99. data/lib/rubocop/cop/style/symbol_proc.rb +8 -1
  100. data/lib/rubocop/cop/style/while_until_do.rb +0 -2
  101. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  102. data/lib/rubocop/cop/style/zero_length_predicate.rb +32 -24
  103. data/lib/rubocop/cop/team.rb +8 -0
  104. data/lib/rubocop/cop/util.rb +7 -1
  105. data/lib/rubocop/cop/variable_force.rb +13 -1
  106. data/lib/rubocop/cops_documentation_generator.rb +1 -1
  107. data/lib/rubocop/core_ext/string.rb +2 -6
  108. data/lib/rubocop/ext/regexp_node.rb +9 -31
  109. data/lib/rubocop/ext/regexp_parser.rb +4 -21
  110. data/lib/rubocop/formatter/html_formatter.rb +3 -1
  111. data/lib/rubocop/options.rb +3 -1
  112. data/lib/rubocop/rspec/shared_contexts.rb +20 -0
  113. data/lib/rubocop/rspec/support.rb +1 -0
  114. data/lib/rubocop/server/cache.rb +10 -0
  115. data/lib/rubocop/server/client_command/exec.rb +2 -2
  116. data/lib/rubocop/server/client_command/start.rb +1 -1
  117. data/lib/rubocop/server/core.rb +4 -0
  118. data/lib/rubocop/version.rb +1 -1
  119. data/lib/rubocop.rb +6 -0
  120. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc79c69246529843a3d6179458d5563867515189cca9f68d34e6cba9f103a032
4
- data.tar.gz: 2b71ef0f55a63904b93e1315417ab4bd9701c1d91f3f87087fda9046243a4176
3
+ metadata.gz: 5ff6bd1def6f2fc502a83cef45c2031e812de416bf82ee6805ed3c8a4aa4ec08
4
+ data.tar.gz: 3fc581f44db6ecb7a31a16b58799151c941184b3d972d11716215165c071d672
5
5
  SHA512:
6
- metadata.gz: 4ea1aa79a49f5a9c7331286e58563b5b92c5c8b11bc1d81dbddee107595a9588e84c7888a8fe6338b29e856740d35d56df47e8d7b485db5cc4cd6cd0f45a8406
7
- data.tar.gz: f5bc4fb8153c6277534bc4acd22da3bb3e41ef0ca5eef2639817893fa2312b5291ca80b308151c2e315db993ea086f32f618f9ef65146b69e4b99fc50782c165
6
+ metadata.gz: 07e4e645df882074e88da46ca8a69d7b1d12ec0d83bf4dfaaef6d799dcdb49c584b904d9f186e59278e663bbebe3db8e3950a6d4219fa73487978261c72fded6
7
+ data.tar.gz: 2d8d8ad60a022ee9df6cb9d164486044787a3a41da8bee073cabb528299d9f62968b8f90fc18a1cba0dbb581968912a478ddda85c1f02c336eb92dbd83092b14
data/README.md CHANGED
@@ -52,7 +52,7 @@ To prevent an unwanted RuboCop update you might want to use a conservative versi
52
52
  in your `Gemfile`:
53
53
 
54
54
  ```rb
55
- gem 'rubocop', '~> 1.64', require: false
55
+ gem 'rubocop', '~> 1.65', require: false
56
56
  ```
57
57
 
58
58
  See [our versioning policy](https://docs.rubocop.org/rubocop/versioning.html) for further details.
data/config/default.yml CHANGED
@@ -262,6 +262,15 @@ Bundler/OrderedGems:
262
262
 
263
263
  #################### Gemspec ###############################
264
264
 
265
+ Gemspec/AddRuntimeDependency:
266
+ Description: 'Prefer `add_dependency` over `add_runtime_dependency`.'
267
+ StyleGuide: '#add_dependency_vs_add_runtime_dependency'
268
+ Reference: https://github.com/rubygems/rubygems/issues/7799#issuecomment-2192720316
269
+ Enabled: pending
270
+ VersionAdded: '1.65'
271
+ Include:
272
+ - '**/*.gemspec'
273
+
265
274
  Gemspec/DependencyVersion:
266
275
  Description: 'Requires or forbids specifying gem dependency versions.'
267
276
  Enabled: false
@@ -2617,8 +2626,9 @@ Metrics/BlockNesting:
2617
2626
  StyleGuide: '#three-is-the-number-thou-shalt-count'
2618
2627
  Enabled: true
2619
2628
  VersionAdded: '0.25'
2620
- VersionChanged: '0.47'
2629
+ VersionChanged: '1.65'
2621
2630
  CountBlocks: false
2631
+ CountModifierForms: false
2622
2632
  Max: 3
2623
2633
 
2624
2634
  Metrics/ClassLength:
@@ -164,7 +164,7 @@ module RuboCop
164
164
  # searches will go past this directory.
165
165
  # @deprecated Use `RuboCop::ConfigFinder.project_root` instead.
166
166
  def project_root
167
- warn Rainbow(<<~WARNING).yellow
167
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
168
168
  `RuboCop::ConfigLoader.project_root` is deprecated and will be removed in RuboCop 2.0. \
169
169
  Use `RuboCop::ConfigFinder.project_root` instead.
170
170
  WARNING
@@ -6,7 +6,7 @@ require 'yaml'
6
6
  module RuboCop
7
7
  # A help class for ConfigLoader that handles configuration resolution.
8
8
  # @api private
9
- class ConfigLoaderResolver
9
+ class ConfigLoaderResolver # rubocop:disable Metrics/ClassLength
10
10
  def resolve_requires(path, hash)
11
11
  config_dir = File.dirname(path)
12
12
  hash.delete('require').tap do |loaded_features|
@@ -267,8 +267,14 @@ module RuboCop
267
267
 
268
268
  def gem_config_path(gem_name, relative_config_path)
269
269
  if defined?(Bundler)
270
- gem = Bundler.load.specs[gem_name].first
271
- gem_path = gem.full_gem_path if gem
270
+ begin
271
+ gem = Bundler.load.specs[gem_name].first
272
+ gem_path = gem.full_gem_path if gem
273
+ rescue Bundler::GemfileNotFound
274
+ # No Gemfile found. Bundler may be loaded manually
275
+ rescue Bundler::GitError
276
+ # The Gemfile exists but contains an uninstalled git source
277
+ end
272
278
  end
273
279
 
274
280
  gem_path ||= Gem::Specification.find_by_name(gem_name).gem_dir
@@ -37,16 +37,28 @@ module RuboCop
37
37
 
38
38
  # @deprecated Use Registry.global
39
39
  def self.registry
40
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
41
+ `Cop.registry` is deprecated. Use `Registry.global` instead.
42
+ WARNING
43
+
40
44
  Registry.global
41
45
  end
42
46
 
43
47
  # @deprecated Use Registry.all
44
48
  def self.all
49
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
50
+ `Cop.all` is deprecated. Use `Registry.all` instead.
51
+ WARNING
52
+
45
53
  Registry.all
46
54
  end
47
55
 
48
56
  # @deprecated Use Registry.qualified_cop_name
49
57
  def self.qualified_cop_name(name, origin)
58
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
59
+ `Cop.qualified_cop_name` is deprecated. Use `Registry.qualified_cop_name` instead.
60
+ WARNING
61
+
50
62
  Registry.qualified_cop_name(name, origin)
51
63
  end
52
64
 
@@ -58,7 +70,7 @@ module RuboCop
58
70
  # template file, we convert it to location info in the original file.
59
71
  range = range_for_original(range)
60
72
 
61
- if block.nil? && !support_autocorrect?
73
+ if block.nil? && !self.class.support_autocorrect?
62
74
  super(range, message: message, severity: severity)
63
75
  else
64
76
  super(range, message: message, severity: severity) do |corrector|
@@ -74,13 +86,19 @@ module RuboCop
74
86
 
75
87
  # @deprecated Use class method
76
88
  def support_autocorrect?
77
- # warn 'deprecated, use cop.class.support_autocorrect?' TODO
89
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
90
+ `support_autocorrect?` is deprecated. Use `cop.class.support_autocorrect?`.
91
+ WARNING
92
+
78
93
  self.class.support_autocorrect?
79
94
  end
80
95
 
81
96
  # @deprecated
82
97
  def corrections
83
- # warn 'Cop#corrections is deprecated' TODO
98
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
99
+ `Cop#corrections` is deprecated.
100
+ WARNING
101
+
84
102
  return [] unless @last_corrector
85
103
 
86
104
  Legacy::CorrectionsProxy.new(@last_corrector)
@@ -136,7 +154,7 @@ module RuboCop
136
154
  end
137
155
 
138
156
  def correction_lambda
139
- return unless support_autocorrect?
157
+ return unless self.class.support_autocorrect?
140
158
 
141
159
  dedupe_on_node(@v0_argument) { autocorrect(@v0_argument) }
142
160
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Gemspec
6
+ # Prefer `add_dependency` over `add_runtime_dependency` as the latter is
7
+ # considered soft-deprecated.
8
+ #
9
+ # @example
10
+ #
11
+ # # bad
12
+ # Gem::Specification.new do |spec|
13
+ # spec.add_runtime_dependency('rubocop')
14
+ # end
15
+ #
16
+ # # good
17
+ # Gem::Specification.new do |spec|
18
+ # spec.add_dependency('rubocop')
19
+ # end
20
+ #
21
+ class AddRuntimeDependency < Base
22
+ extend AutoCorrector
23
+
24
+ MSG = 'Use `add_dependency` instead of `add_runtime_dependency`.'
25
+
26
+ RESTRICT_ON_SEND = %i[add_runtime_dependency].freeze
27
+
28
+ def on_send(node)
29
+ return if !node.receiver || node.arguments.empty?
30
+
31
+ add_offense(node.loc.selector) do |corrector|
32
+ corrector.replace(node.loc.selector, 'add_dependency')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -31,8 +31,8 @@ module RuboCop
31
31
  #
32
32
  # # good
33
33
  # Gem::Specification.new do |spec|
34
- # spec.add_runtime_dependency('parallel', '~> 1.10')
35
- # spec.add_runtime_dependency('parser', '>= 2.3.3.1', '< 3.0')
34
+ # spec.add_dependency('parallel', '~> 1.10')
35
+ # spec.add_dependency('parser', '>= 2.3.3.1', '< 3.0')
36
36
  # end
37
37
  class DuplicatedAssignment < Base
38
38
  include RangeHelp
@@ -14,15 +14,15 @@ module RuboCop
14
14
  # # bad
15
15
  # Gem::Specification.new do |spec|
16
16
  # if RUBY_VERSION >= '3.0'
17
- # spec.add_runtime_dependency 'gem_a'
17
+ # spec.add_dependency 'gem_a'
18
18
  # else
19
- # spec.add_runtime_dependency 'gem_b'
19
+ # spec.add_dependency 'gem_b'
20
20
  # end
21
21
  # end
22
22
  #
23
23
  # # good
24
24
  # Gem::Specification.new do |spec|
25
- # spec.add_runtime_dependency 'gem_a'
25
+ # spec.add_dependency 'gem_a'
26
26
  # end
27
27
  #
28
28
  class RubyVersionGlobalsUsage < Base
@@ -6,6 +6,9 @@ module RuboCop
6
6
  # Checks the indentation of the first line of the
7
7
  # right-hand-side of a multi-line assignment.
8
8
  #
9
+ # The indentation of the remaining lines can be corrected with
10
+ # other cops such as `Layout/IndentationConsistency` and `Layout/EndAlignment`.
11
+ #
9
12
  # @example
10
13
  # # bad
11
14
  # value =
@@ -19,8 +22,6 @@ module RuboCop
19
22
  # 'bar'
20
23
  # end
21
24
  #
22
- # The indentation of the remaining lines can be corrected with
23
- # other cops such as `IndentationConsistency` and `EndAlignment`.
24
25
  class AssignmentIndentation < Base
25
26
  include CheckAssignment
26
27
  include Alignment
@@ -121,7 +121,7 @@ module RuboCop
121
121
  return if case_node.single_line?
122
122
  return if enforced_style_end? && end_and_last_conditional_same_line?(case_node)
123
123
 
124
- case_node.each_when { |when_node| check_when(when_node, 'when') }
124
+ case_node.when_branches.each { |when_node| check_when(when_node, 'when') }
125
125
  end
126
126
 
127
127
  def on_case_match(case_match_node)
@@ -9,16 +9,12 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # if
14
13
  # some_condition
15
14
  # do_something
16
15
  # end
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # if some_condition
23
19
  # do_something
24
20
  # end
@@ -80,7 +80,7 @@ module RuboCop
80
80
  alias on_until_post on_while_post
81
81
 
82
82
  def on_case(node)
83
- node.each_when do |when_node|
83
+ node.when_branches.each do |when_node|
84
84
  last_condition = when_node.conditions.last
85
85
 
86
86
  next if !multiline_when_condition?(when_node) ||
@@ -118,8 +118,8 @@ module RuboCop
118
118
  #
119
119
  # @example EnforcedStyle: special_for_inner_method_call
120
120
  # # The first argument should normally be indented one step more than
121
- # # the preceding line, but if it's a argument for a method call that
122
- # # is itself a argument in a method call, then the inner argument
121
+ # # the preceding line, but if it's an argument for a method call that
122
+ # # is itself an argument in a method call, then the inner argument
123
123
  # # should be indented relative to the inner method.
124
124
  #
125
125
  # # good
@@ -6,7 +6,7 @@ module RuboCop
6
6
  # Checks the indentation of the here document bodies. The bodies
7
7
  # are indented one step.
8
8
  #
9
- # Note: When ``Layout/LineLength``'s `AllowHeredoc` is false (not default),
9
+ # NOTE: When ``Layout/LineLength``'s `AllowHeredoc` is false (not default),
10
10
  # this cop does not add any offenses for long here documents to
11
11
  # avoid ``Layout/LineLength``'s offenses.
12
12
  #
@@ -136,7 +136,7 @@ module RuboCop
136
136
  alias on_until on_while
137
137
 
138
138
  def on_case(case_node)
139
- case_node.each_when do |when_node|
139
+ case_node.when_branches.each do |when_node|
140
140
  check_indentation(when_node.loc.keyword, when_node.body)
141
141
  end
142
142
 
@@ -17,29 +17,29 @@ module RuboCop
17
17
  # split across lines. These include arrays, hashes, and
18
18
  # method calls with argument lists.
19
19
  #
20
- # If autocorrection is enabled, the following Layout cops
20
+ # If autocorrection is enabled, the following cops
21
21
  # are recommended to further format the broken lines.
22
22
  # (Many of these are enabled by default.)
23
23
  #
24
- # * ArgumentAlignment
25
- # * ArrayAlignment
26
- # * BlockAlignment
27
- # * BlockDelimiters
28
- # * BlockEndNewline
29
- # * ClosingParenthesisIndentation
30
- # * FirstArgumentIndentation
31
- # * FirstArrayElementIndentation
32
- # * FirstHashElementIndentation
33
- # * FirstParameterIndentation
34
- # * HashAlignment
35
- # * IndentationWidth
36
- # * MultilineArrayLineBreaks
37
- # * MultilineBlockLayout
38
- # * MultilineHashBraceLayout
39
- # * MultilineHashKeyLineBreaks
40
- # * MultilineMethodArgumentLineBreaks
41
- # * MultilineMethodParameterLineBreaks
42
- # * ParameterAlignment
24
+ # * `Layout/ArgumentAlignment`
25
+ # * `Layout/ArrayAlignment`
26
+ # * `Layout/BlockAlignment`
27
+ # * `Layout/BlockEndNewline`
28
+ # * `LayoutClosingParenthesisIndentation`
29
+ # * `LayoutFirstArgumentIndentation`
30
+ # * `LayoutFirstArrayElementIndentation`
31
+ # * `LayoutFirstHashElementIndentation`
32
+ # * `LayoutFirstParameterIndentation`
33
+ # * `LayoutHashAlignment`
34
+ # * `LayoutIndentationWidth`
35
+ # * `LayoutMultilineArrayLineBreaks`
36
+ # * `LayoutMultilineBlockLayout`
37
+ # * `LayoutMultilineHashBraceLayout`
38
+ # * `LayoutMultilineHashKeyLineBreaks`
39
+ # * `LayoutMultilineMethodArgumentLineBreaks`
40
+ # * `LayoutMultilineMethodParameterLineBreaks`
41
+ # * `Layout/ParameterAlignment`
42
+ # * `Style/BlockDelimiters`
43
43
  #
44
44
  # Together, these cops will pretty print hashes, arrays,
45
45
  # method calls, etc. For example, let's say the max columns
@@ -180,6 +180,9 @@ module RuboCop
180
180
  with_space = range_with_surrounding_space(operator)
181
181
  return if with_space.source.start_with?("\n")
182
182
 
183
+ comment = processed_source.comment_at_line(operator.line)
184
+ return if comment && with_space.last_column == comment.loc.column
185
+
183
186
  offense(type, operator, with_space, right_operand) do |msg|
184
187
  add_offense(operator, message: msg) do |corrector|
185
188
  autocorrect(corrector, with_space, right_operand)
@@ -12,13 +12,23 @@ module RuboCop
12
12
  if corr.is_a?(CorrectionsProxy)
13
13
  merge!(corr.send(:corrector))
14
14
  else
15
- # warn "Corrector.new with corrections is deprecated." unless corr.empty? TODO
15
+ unless corr.empty?
16
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
17
+ `Corrector.new` with corrections is deprecated.
18
+ See https://docs.rubocop.org/rubocop/v1_upgrade_notes.html
19
+ WARNING
20
+ end
21
+
16
22
  corr.each { |c| corrections << c }
17
23
  end
18
24
  end
19
25
 
20
26
  def corrections
21
- # warn "#corrections is deprecated. Open an issue if you have a valid usecase." TODO
27
+ warn Rainbow(<<~WARNING).yellow, uplevel: 1
28
+ `Corrector#corrections` is deprecated. Open an issue if you have a valid usecase.
29
+ See https://docs.rubocop.org/rubocop/v1_upgrade_notes.html
30
+ WARNING
31
+
22
32
  CorrectionsProxy.new(self)
23
33
  end
24
34
  end
@@ -14,8 +14,6 @@ module RuboCop
14
14
  # # bad
15
15
  # some_method a { |val| puts val }
16
16
  #
17
- # @example
18
- #
19
17
  # # good
20
18
  # # With parentheses, there's no ambiguity.
21
19
  # some_method(a { |val| puts val })
@@ -14,8 +14,6 @@ module RuboCop
14
14
  # # a `*` method invocation (i.e. `do_something.*(some_array)`).
15
15
  # do_something *some_array
16
16
  #
17
- # @example
18
- #
19
17
  # # good
20
18
  #
21
19
  # # With parentheses, there's no ambiguity.
@@ -15,8 +15,6 @@ module RuboCop
15
15
  # # (i.e. `do_something./(pattern)./(i)`)
16
16
  # do_something /pattern/i
17
17
  #
18
- # @example
19
- #
20
18
  # # good
21
19
  #
22
20
  # # With parentheses, there's no ambiguity.
@@ -19,8 +19,6 @@ module RuboCop
19
19
  # # good
20
20
  # true
21
21
  #
22
- # @example
23
- #
24
22
  # # bad
25
23
  # :false
26
24
  #
@@ -11,39 +11,26 @@ module RuboCop
11
11
  # @example
12
12
  #
13
13
  # # bad
14
- #
15
14
  # def bake(pie: pie)
16
15
  # pie.heat_up
17
16
  # end
18
17
  #
19
- # @example
20
- #
21
18
  # # good
22
- #
23
19
  # def bake(pie:)
24
20
  # pie.refrigerate
25
21
  # end
26
22
  #
27
- # @example
28
- #
29
23
  # # good
30
- #
31
24
  # def bake(pie: self.pie)
32
25
  # pie.feed_to(user)
33
26
  # end
34
27
  #
35
- # @example
36
- #
37
28
  # # bad
38
- #
39
29
  # def cook(dry_ingredients = dry_ingredients)
40
30
  # dry_ingredients.reduce(&:+)
41
31
  # end
42
32
  #
43
- # @example
44
- #
45
33
  # # good
46
- #
47
34
  # def cook(dry_ingredients = self.dry_ingredients)
48
35
  # dry_ingredients.combine
49
36
  # end
@@ -44,8 +44,6 @@ module RuboCop
44
44
  # do_something
45
45
  # end
46
46
  #
47
- # @example
48
- #
49
47
  # # bad (ok during development)
50
48
  #
51
49
  # # using byebug
@@ -54,8 +52,6 @@ module RuboCop
54
52
  # do_something
55
53
  # end
56
54
  #
57
- # @example
58
- #
59
55
  # # good
60
56
  #
61
57
  # def some_method
@@ -9,28 +9,18 @@ module RuboCop
9
9
  #
10
10
  # @example
11
11
  #
12
- # # Example for OpenSSL::Cipher instantiation.
13
- #
14
12
  # # bad
15
13
  # OpenSSL::Cipher::AES.new(128, :GCM)
16
14
  #
17
15
  # # good
18
16
  # OpenSSL::Cipher.new('aes-128-gcm')
19
17
  #
20
- # @example
21
- #
22
- # # Example for OpenSSL::Digest instantiation.
23
- #
24
18
  # # bad
25
19
  # OpenSSL::Digest::SHA256.new
26
20
  #
27
21
  # # good
28
22
  # OpenSSL::Digest.new('SHA256')
29
23
  #
30
- # @example
31
- #
32
- # # Example for ::Digest inherited class methods.
33
- #
34
24
  # # bad
35
25
  # OpenSSL::Digest::SHA256.digest('foo')
36
26
  #
@@ -9,7 +9,6 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # case x
14
13
  # when 'first'
15
14
  # do_something
@@ -17,10 +16,7 @@ module RuboCop
17
16
  # do_something_else
18
17
  # end
19
18
  #
20
- # @example
21
- #
22
19
  # # good
23
- #
24
20
  # case x
25
21
  # when 'first'
26
22
  # do_something
@@ -32,7 +28,7 @@ module RuboCop
32
28
 
33
29
  def on_case(case_node)
34
30
  case_node.when_branches.each_with_object(Set.new) do |when_node, previous|
35
- when_node.each_condition do |condition|
31
+ when_node.conditions.each do |condition|
36
32
  add_offense(condition) unless previous.add?(condition)
37
33
  end
38
34
  end
@@ -11,13 +11,9 @@ module RuboCop
11
11
  # @example
12
12
  #
13
13
  # # bad
14
- #
15
14
  # hash = { food: 'apple', food: 'orange' }
16
15
  #
17
- # @example
18
- #
19
16
  # # good
20
- #
21
17
  # hash = { food: 'apple', other_food: 'orange' }
22
18
  class DuplicateHashKey < Base
23
19
  include Duplication
@@ -9,7 +9,6 @@ module RuboCop
9
9
  # @example
10
10
  #
11
11
  # # bad
12
- #
13
12
  # def foo
14
13
  # 1
15
14
  # end
@@ -18,20 +17,14 @@ module RuboCop
18
17
  # 2
19
18
  # end
20
19
  #
21
- # @example
22
- #
23
20
  # # bad
24
- #
25
21
  # def foo
26
22
  # 1
27
23
  # end
28
24
  #
29
25
  # alias foo bar
30
26
  #
31
- # @example
32
- #
33
27
  # # good
34
- #
35
28
  # def foo
36
29
  # 1
37
30
  # end
@@ -40,10 +33,7 @@ module RuboCop
40
33
  # 2
41
34
  # end
42
35
  #
43
- # @example
44
- #
45
36
  # # good
46
- #
47
37
  # def foo
48
38
  # 1
49
39
  # end
@@ -12,13 +12,9 @@ module RuboCop
12
12
  # @example
13
13
  #
14
14
  # # bad
15
- #
16
15
  # sum = numbers.each_with_object(0) { |e, a| a += e }
17
16
  #
18
- # @example
19
- #
20
17
  # # good
21
- #
22
18
  # num = 0
23
19
  # sum = numbers.each_with_object(num) { |e, a| a += e }
24
20
  class EachWithObjectArgument < Base
@@ -21,8 +21,6 @@ module RuboCop
21
21
  # do_that
22
22
  # end
23
23
  #
24
- # @example
25
- #
26
24
  # # good
27
25
  #
28
26
  # # This code is compatible with the bad case. It will be autocorrected like this.