rubocop 1.6.1 → 1.9.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/LICENSE.txt +1 -1
  3. data/README.md +4 -3
  4. data/config/default.yml +145 -19
  5. data/lib/rubocop.rb +16 -1
  6. data/lib/rubocop/cli/command/auto_genenerate_config.rb +5 -4
  7. data/lib/rubocop/comment_config.rb +6 -6
  8. data/lib/rubocop/config.rb +13 -7
  9. data/lib/rubocop/config_loader.rb +11 -14
  10. data/lib/rubocop/config_loader_resolver.rb +21 -4
  11. data/lib/rubocop/config_obsoletion.rb +5 -3
  12. data/lib/rubocop/config_store.rb +12 -1
  13. data/lib/rubocop/cop/base.rb +2 -1
  14. data/lib/rubocop/cop/exclude_limit.rb +26 -0
  15. data/lib/rubocop/cop/gemspec/required_ruby_version.rb +3 -2
  16. data/lib/rubocop/cop/generator.rb +1 -3
  17. data/lib/rubocop/cop/internal_affairs.rb +6 -1
  18. data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +68 -0
  19. data/lib/rubocop/cop/internal_affairs/example_description.rb +89 -0
  20. data/lib/rubocop/cop/internal_affairs/redundant_described_class_as_subject.rb +61 -0
  21. data/lib/rubocop/cop/internal_affairs/redundant_let_rubocop_config_new.rb +64 -0
  22. data/lib/rubocop/cop/internal_affairs/style_detected_api_use.rb +145 -0
  23. data/lib/rubocop/cop/layout/class_structure.rb +7 -2
  24. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +56 -20
  25. data/lib/rubocop/cop/layout/first_argument_indentation.rb +16 -2
  26. data/lib/rubocop/cop/layout/heredoc_argument_closing_parenthesis.rb +14 -0
  27. data/lib/rubocop/cop/layout/line_length.rb +2 -1
  28. data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -2
  29. data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -10
  30. data/lib/rubocop/cop/layout/space_around_equals_in_parameter_default.rb +1 -0
  31. data/lib/rubocop/cop/layout/space_before_block_braces.rb +2 -0
  32. data/lib/rubocop/cop/layout/space_before_brackets.rb +67 -0
  33. data/lib/rubocop/cop/layout/space_inside_block_braces.rb +13 -10
  34. data/lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb +2 -2
  35. data/lib/rubocop/cop/lint/ambiguous_assignment.rb +59 -0
  36. data/lib/rubocop/cop/lint/binary_operator_with_identical_operands.rb +7 -2
  37. data/lib/rubocop/cop/lint/deprecated_constants.rb +80 -0
  38. data/lib/rubocop/cop/lint/duplicate_branch.rb +64 -2
  39. data/lib/rubocop/cop/lint/lambda_without_literal_block.rb +44 -0
  40. data/lib/rubocop/cop/lint/non_deterministic_require_order.rb +10 -6
  41. data/lib/rubocop/cop/lint/number_conversion.rb +41 -6
  42. data/lib/rubocop/cop/lint/numbered_parameter_assignment.rb +47 -0
  43. data/lib/rubocop/cop/lint/or_assignment_to_constant.rb +39 -0
  44. data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +2 -1
  45. data/lib/rubocop/cop/lint/redundant_dir_glob_sort.rb +50 -0
  46. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +50 -17
  47. data/lib/rubocop/cop/lint/shadowed_exception.rb +1 -11
  48. data/lib/rubocop/cop/lint/symbol_conversion.rb +103 -0
  49. data/lib/rubocop/cop/lint/triple_quotes.rb +71 -0
  50. data/lib/rubocop/cop/lint/unreachable_loop.rb +17 -0
  51. data/lib/rubocop/cop/message_annotator.rb +4 -1
  52. data/lib/rubocop/cop/metrics/block_nesting.rb +2 -2
  53. data/lib/rubocop/cop/metrics/parameter_lists.rb +5 -2
  54. data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
  55. data/lib/rubocop/cop/mixin/allowed_identifiers.rb +18 -0
  56. data/lib/rubocop/cop/mixin/check_line_breakable.rb +5 -0
  57. data/lib/rubocop/cop/mixin/code_length.rb +3 -1
  58. data/lib/rubocop/cop/mixin/comments_help.rb +1 -11
  59. data/lib/rubocop/cop/mixin/configurable_max.rb +1 -0
  60. data/lib/rubocop/cop/mixin/first_element_line_break.rb +1 -1
  61. data/lib/rubocop/cop/mixin/method_complexity.rb +3 -1
  62. data/lib/rubocop/cop/mixin/uncommunicative_name.rb +5 -1
  63. data/lib/rubocop/cop/naming/memoized_instance_variable_name.rb +59 -5
  64. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +38 -5
  65. data/lib/rubocop/cop/naming/variable_name.rb +2 -0
  66. data/lib/rubocop/cop/naming/variable_number.rb +2 -9
  67. data/lib/rubocop/cop/registry.rb +10 -0
  68. data/lib/rubocop/cop/severity.rb +3 -3
  69. data/lib/rubocop/cop/style/access_modifier_declarations.rb +3 -1
  70. data/lib/rubocop/cop/style/ascii_comments.rb +1 -1
  71. data/lib/rubocop/cop/style/collection_methods.rb +14 -1
  72. data/lib/rubocop/cop/style/commented_keyword.rb +22 -5
  73. data/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb +49 -9
  74. data/lib/rubocop/cop/style/empty_literal.rb +6 -2
  75. data/lib/rubocop/cop/style/endless_method.rb +102 -0
  76. data/lib/rubocop/cop/style/eval_with_location.rb +63 -34
  77. data/lib/rubocop/cop/style/explicit_block_argument.rb +10 -0
  78. data/lib/rubocop/cop/style/float_division.rb +3 -0
  79. data/lib/rubocop/cop/style/for.rb +2 -0
  80. data/lib/rubocop/cop/style/format_string_token.rb +18 -2
  81. data/lib/rubocop/cop/style/hash_except.rb +95 -0
  82. data/lib/rubocop/cop/style/hash_like_case.rb +2 -1
  83. data/lib/rubocop/cop/style/if_inside_else.rb +22 -10
  84. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +120 -0
  85. data/lib/rubocop/cop/style/keyword_parameters_order.rb +12 -2
  86. data/lib/rubocop/cop/style/lambda_call.rb +2 -1
  87. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +7 -0
  88. data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +16 -6
  89. data/lib/rubocop/cop/style/method_def_parentheses.rb +7 -0
  90. data/lib/rubocop/cop/style/multiline_method_signature.rb +26 -1
  91. data/lib/rubocop/cop/style/multiline_when_then.rb +3 -1
  92. data/lib/rubocop/cop/style/mutable_constant.rb +13 -3
  93. data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +4 -0
  94. data/lib/rubocop/cop/style/nil_comparison.rb +3 -0
  95. data/lib/rubocop/cop/style/non_nil_check.rb +23 -13
  96. data/lib/rubocop/cop/style/numeric_literals.rb +6 -9
  97. data/lib/rubocop/cop/style/numeric_predicate.rb +1 -1
  98. data/lib/rubocop/cop/style/raise_args.rb +5 -2
  99. data/lib/rubocop/cop/style/redundant_argument.rb +7 -1
  100. data/lib/rubocop/cop/style/redundant_freeze.rb +8 -4
  101. data/lib/rubocop/cop/style/redundant_return.rb +1 -1
  102. data/lib/rubocop/cop/style/single_line_methods.rb +36 -2
  103. data/lib/rubocop/cop/style/sole_nested_conditional.rb +29 -5
  104. data/lib/rubocop/cop/style/string_concatenation.rb +1 -1
  105. data/lib/rubocop/cop/style/symbol_proc.rb +5 -4
  106. data/lib/rubocop/cop/style/ternary_parentheses.rb +1 -1
  107. data/lib/rubocop/cop/style/while_until_modifier.rb +2 -4
  108. data/lib/rubocop/cop/util.rb +3 -1
  109. data/lib/rubocop/formatter/git_hub_actions_formatter.rb +1 -0
  110. data/lib/rubocop/formatter/simple_text_formatter.rb +2 -1
  111. data/lib/rubocop/magic_comment.rb +30 -1
  112. data/lib/rubocop/options.rb +10 -10
  113. data/lib/rubocop/rspec/cop_helper.rb +0 -4
  114. data/lib/rubocop/rspec/expect_offense.rb +37 -22
  115. data/lib/rubocop/runner.rb +17 -1
  116. data/lib/rubocop/target_finder.rb +4 -2
  117. data/lib/rubocop/target_ruby.rb +47 -11
  118. data/lib/rubocop/util.rb +16 -0
  119. data/lib/rubocop/version.rb +8 -2
  120. metadata +27 -7
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module InternalAffairs
6
+ # This cop checks for redundant `subject(:cop) { described_class.new }`.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # RSpec.describe RuboCop::Cop::Department::Foo do
11
+ # subject(:cop) { described_class.new(config) }
12
+ # end
13
+ #
14
+ # # good
15
+ # RSpec.describe RuboCop::Cop::Department::Foo, :config do
16
+ # end
17
+ #
18
+ class RedundantDescribedClassAsSubject < Base
19
+ include RangeHelp
20
+ extend AutoCorrector
21
+
22
+ MSG = 'Remove the redundant `subject`%<additional_message>s.'
23
+
24
+ def_node_matcher :described_class_subject?, <<~PATTERN
25
+ (block
26
+ (send nil? :subject
27
+ (sym :cop))
28
+ (args)
29
+ (send
30
+ (send nil? :described_class) :new
31
+ $...))
32
+ PATTERN
33
+
34
+ def on_block(node)
35
+ return unless (described_class_arguments = described_class_subject?(node))
36
+ return if described_class_arguments.count >= 2
37
+
38
+ describe = find_describe_method_node(node)
39
+
40
+ unless (exist_config = describe.last_argument.source == ':config')
41
+ additional_message = ' and specify `:config` in `describe`'
42
+ end
43
+
44
+ message = format(MSG, additional_message: additional_message)
45
+
46
+ add_offense(node, message: message) do |corrector|
47
+ corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
48
+
49
+ corrector.insert_after(describe.last_argument, ', :config') unless exist_config
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def find_describe_method_node(block_node)
56
+ block_node.ancestors.find { |node| node.block_type? && node.method?(:describe) }.send_node
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module InternalAffairs
6
+ # This cop checks that `let` is `RuboCop::Config.new` with no arguments.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # RSpec.describe RuboCop::Cop::Department::Foo, :config do
11
+ # let(:config) { RuboCop::Config.new }
12
+ # end
13
+ #
14
+ # # good
15
+ # RSpec.describe RuboCop::Cop::Department::Foo, :config do
16
+ # end
17
+ #
18
+ # RSpec.describe RuboCop::Cop::Department::Foo, :config do
19
+ # let(:config) { RuboCop::Config.new(argument) }
20
+ # end
21
+ #
22
+ class RedundantLetRuboCopConfigNew < Base
23
+ include RangeHelp
24
+ extend AutoCorrector
25
+
26
+ MSG = 'Remove `let` that is `RuboCop::Config.new` with no arguments%<additional_message>s.'
27
+
28
+ def_node_matcher :let_rubocop_config_new?, <<~PATTERN
29
+ (block
30
+ (send nil? :let
31
+ (sym :config))
32
+ (args)
33
+ (send
34
+ (const
35
+ (const nil? :RuboCop) :Config) :new))
36
+ PATTERN
37
+
38
+ def on_block(node)
39
+ return unless let_rubocop_config_new?(node)
40
+
41
+ describe = find_describe_method_node(node)
42
+
43
+ unless (exist_config = describe.last_argument.source == ':config')
44
+ additional_message = ' and specify `:config` in `describe`'
45
+ end
46
+
47
+ message = format(MSG, additional_message: additional_message)
48
+
49
+ add_offense(node, message: message) do |corrector|
50
+ corrector.remove(range_by_whole_lines(node.source_range, include_final_newline: true))
51
+
52
+ corrector.insert_after(describe.last_argument, ', :config') unless exist_config
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def find_describe_method_node(block_node)
59
+ block_node.ancestors.find { |node| node.block_type? && node.method?(:describe) }.send_node
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,145 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module InternalAffairs
6
+ # Checks for correct use of the style_detected API provided by
7
+ # `ConfigurableEnforcedStyle`. If `correct_style_detected` is used
8
+ # then `opposite_style_detected`, `unexpected_style_detected`,
9
+ # `ambiguous_style_detected`, `conflicting_styles_detected`,
10
+ # `unrecognized_style_detected` or `no_acceptable_style!` should be
11
+ # used too, and vice versa. The `xxx_style_detected` methods
12
+ # should not be used as predicates either.
13
+ #
14
+ # @example
15
+ #
16
+ # # bad
17
+ # def on_send(node)
18
+ # return add_offense(node) if opposite_style_detected
19
+ #
20
+ # correct_style_detected
21
+ # end
22
+ #
23
+ # def on_send(node)
24
+ # if offense?
25
+ # add_offense(node)
26
+ # else
27
+ # correct_style_detected
28
+ # end
29
+ # end
30
+ #
31
+ # def on_send(node)
32
+ # return unless offense?
33
+ #
34
+ # add_offense(node)
35
+ # opposite_style_detected
36
+ # end
37
+ #
38
+ # # good
39
+ # def on_send(node)
40
+ # if offense?
41
+ # add_offense(node)
42
+ # opposite_style_detected
43
+ # else
44
+ # correct_style_detected
45
+ # end
46
+ # end
47
+ #
48
+ # def on_send(node)
49
+ # add_offense(node) if offense?
50
+ # end
51
+ #
52
+ class StyleDetectedApiUse < Base
53
+ include RangeHelp
54
+
55
+ MSG_FOR_POSITIVE_WITHOUT_NEGATIVE =
56
+ '`correct_style_detected` method called without ' \
57
+ 'calling a negative `*_style_detected` method.'
58
+ MSG_FOR_NEGATIVE_WITHOUT_POSITIVE =
59
+ 'negative `*_style_detected` methods called without ' \
60
+ 'calling `correct_style_detected` method.'
61
+ MSG_FOR_CONDITIONAL_USE =
62
+ '`*_style_detected` method called in conditional.'
63
+ RESTRICT_ON_SEND = %i[
64
+ correct_style_detected opposite_style_detected
65
+ unexpected_style_detected ambiguous_style_detected
66
+ conflicting_styles_detected unrecognized_style_detected
67
+ no_acceptable_style! style_detected
68
+ ].freeze
69
+
70
+ def_node_matcher :correct_style_detected_check, <<~PATTERN
71
+ (send nil? :correct_style_detected)
72
+ PATTERN
73
+
74
+ def_node_matcher :negative_style_detected_method_check, <<~PATTERN
75
+ (send nil? /(?:opposite|unexpected|ambiguous|unrecognized)_style_detected|conflicting_styles_detected/ ...)
76
+ PATTERN
77
+
78
+ def_node_matcher :no_acceptable_style_check, <<~PATTERN
79
+ (send nil? :no_acceptable_style!)
80
+ PATTERN
81
+
82
+ def_node_matcher :style_detected_check, <<~PATTERN
83
+ (send nil? :style_detected ...)
84
+ PATTERN
85
+
86
+ def on_new_investigation
87
+ @correct_style_detected_called = false
88
+ @negative_style_detected_methods_called = false
89
+ @style_detected_called = false
90
+ end
91
+
92
+ def on_investigation_end
93
+ return if style_detected_called
94
+ return unless correct_style_detected_called ^ negative_style_detected_methods_called
95
+
96
+ add_global_offense(MSG_FOR_POSITIVE_WITHOUT_NEGATIVE) if positive_without_negative?
97
+ add_global_offense(MSG_FOR_NEGATIVE_WITHOUT_POSITIVE) if negative_without_positive?
98
+ end
99
+
100
+ def on_send(node)
101
+ if correct_style_detected_check(node)
102
+ @correct_style_detected_called = true
103
+ elsif negative_style_detected_method_check(node) || no_acceptable_style_check(node)
104
+ @negative_style_detected_methods_called = true
105
+ elsif style_detected_check(node)
106
+ @style_detected_called = true
107
+ end
108
+ end
109
+
110
+ def on_if(node)
111
+ traverse_condition(node.condition) do |cond|
112
+ add_offense(cond, message: MSG_FOR_CONDITIONAL_USE) if style_detected_api_used?(cond)
113
+ end
114
+ end
115
+
116
+ private
117
+
118
+ attr_reader :correct_style_detected_called,
119
+ :negative_style_detected_methods_called,
120
+ :style_detected_called
121
+
122
+ def positive_without_negative?
123
+ correct_style_detected_called && !negative_style_detected_methods_called
124
+ end
125
+
126
+ def negative_without_positive?
127
+ negative_style_detected_methods_called && !correct_style_detected_called
128
+ end
129
+
130
+ def style_detected_api_used?(node)
131
+ correct_style_detected_check(node) ||
132
+ negative_style_detected_method_check(node) ||
133
+ no_acceptable_style_check(node) ||
134
+ style_detected_check(node)
135
+ end
136
+
137
+ def traverse_condition(condition, &block)
138
+ yield condition if condition.send_type?
139
+
140
+ condition.each_child_node { |child| traverse_condition(child, &block) }
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
@@ -213,7 +213,12 @@ module RuboCop
213
213
  name = node.method_name.to_s
214
214
  category, = categories.find { |_, names| names.include?(name) }
215
215
  key = category || name
216
- visibility_key = "#{node_visibility(node)}_#{key}"
216
+ visibility_key =
217
+ if node.def_modifier?
218
+ "#{name}_methods"
219
+ else
220
+ "#{node_visibility(node)}_#{key}"
221
+ end
217
222
  expected_order.include?(visibility_key) ? visibility_key : key
218
223
  end
219
224
 
@@ -264,7 +269,7 @@ module RuboCop
264
269
 
265
270
  def source_range_with_comment(node)
266
271
  begin_pos, end_pos =
267
- if node.def_type?
272
+ if node.def_type? && !node.method?(:initialize) || node.send_type? && node.def_modifier?
268
273
  start_node = find_visibility_start(node) || node
269
274
  end_node = find_visibility_end(node) || node
270
275
  [begin_pos_with_comment(start_node),
@@ -76,11 +76,19 @@ module RuboCop
76
76
  #
77
77
  # def b
78
78
  # end
79
+ #
80
+ # @example AllowAdjacentOneLineDefs: true
81
+ #
82
+ # # good
83
+ # class ErrorA < BaseError; end
84
+ # class ErrorB < BaseError; end
85
+ # class ErrorC < BaseError; end
86
+ #
79
87
  class EmptyLineBetweenDefs < Base
80
88
  include RangeHelp
81
89
  extend AutoCorrector
82
90
 
83
- MSG = 'Use empty lines between %<type>s definitions.'
91
+ MSG = 'Expected %<expected>s between %<type>s definitions; found %<actual>d.'
84
92
 
85
93
  def self.autocorrect_incompatible_with
86
94
  [Layout::EmptyLines]
@@ -99,29 +107,29 @@ module RuboCop
99
107
  end
100
108
 
101
109
  def check_defs(nodes)
102
- return if blank_lines_between?(*nodes)
110
+ count = blank_lines_count_between(*nodes)
111
+
112
+ return if line_count_allowed?(count)
103
113
  return if multiple_blank_lines_groups?(*nodes)
104
114
  return if nodes.all?(&:single_line?) &&
105
115
  cop_config['AllowAdjacentOneLineDefs']
106
116
 
107
117
  correction_node = nodes.last
108
118
  location = correction_node.loc.keyword.join(correction_node.loc.name)
109
- add_offense(location, message: message(correction_node)) do |corrector|
110
- autocorrect(corrector, *nodes)
119
+ add_offense(location, message: message(correction_node, count: count)) do |corrector|
120
+ autocorrect(corrector, *nodes, count)
111
121
  end
112
122
  end
113
123
 
114
- def autocorrect(corrector, prev_def, node)
124
+ def autocorrect(corrector, prev_def, node, count)
115
125
  # finds position of first newline
116
- end_pos = prev_def.loc.end.end_pos
117
- source_buffer = prev_def.loc.end.source_buffer
126
+ end_pos = end_loc(prev_def).end_pos
127
+ source_buffer = end_loc(prev_def).source_buffer
118
128
  newline_pos = source_buffer.source.index("\n", end_pos)
119
129
 
120
130
  # Handle the case when multiple one-liners are on the same line.
121
131
  newline_pos = end_pos + 1 if newline_pos > node.source_range.begin_pos
122
132
 
123
- count = blank_lines_count_between(prev_def, node)
124
-
125
133
  if count > maximum_empty_lines
126
134
  autocorrect_remove_lines(corrector, newline_pos, count)
127
135
  else
@@ -149,14 +157,22 @@ module RuboCop
149
157
  cop_config['EmptyLineBetweenModuleDefs'] && node.module_type?
150
158
  end
151
159
 
152
- def message(node)
153
- type = case node.type
154
- when :def, :defs
155
- :method
156
- else
157
- node.type
158
- end
159
- format(MSG, type: type)
160
+ def message(node, count: nil)
161
+ type = node_type(node)
162
+
163
+ format(MSG,
164
+ type: type,
165
+ expected: expected_lines,
166
+ actual: count)
167
+ end
168
+
169
+ def expected_lines
170
+ if allowance_range?
171
+ "#{minimum_empty_lines..maximum_empty_lines} empty lines"
172
+ else
173
+ lines = maximum_empty_lines == 1 ? 'line' : 'lines'
174
+ "#{maximum_empty_lines} empty #{lines}"
175
+ end
160
176
  end
161
177
 
162
178
  def multiple_blank_lines_groups?(first_def_node, second_def_node)
@@ -168,8 +184,7 @@ module RuboCop
168
184
  blank_start > non_blank_end
169
185
  end
170
186
 
171
- def blank_lines_between?(first_def_node, second_def_node)
172
- count = blank_lines_count_between(first_def_node, second_def_node)
187
+ def line_count_allowed?(count)
173
188
  (minimum_empty_lines..maximum_empty_lines).cover?(count)
174
189
  end
175
190
 
@@ -198,7 +213,15 @@ module RuboCop
198
213
  end
199
214
 
200
215
  def def_end(node)
201
- node.loc.end.line
216
+ end_loc(node).line
217
+ end
218
+
219
+ def end_loc(node)
220
+ if (node.def_type? || node.defs_type?) && node.endless?
221
+ node.loc.expression.end
222
+ else
223
+ node.loc.end
224
+ end
202
225
  end
203
226
 
204
227
  def autocorrect_remove_lines(corrector, newline_pos, count)
@@ -214,6 +237,19 @@ module RuboCop
214
237
 
215
238
  corrector.insert_after(where_to_insert, "\n" * difference)
216
239
  end
240
+
241
+ def node_type(node)
242
+ case node.type
243
+ when :def, :defs
244
+ :method
245
+ else
246
+ node.type
247
+ end
248
+ end
249
+
250
+ def allowance_range?
251
+ minimum_empty_lines != maximum_empty_lines
252
+ end
217
253
  end
218
254
  end
219
255
  end
@@ -4,11 +4,14 @@ module RuboCop
4
4
  module Cop
5
5
  module Layout
6
6
  # This cop checks the indentation of the first argument in a method call.
7
- # Arguments after the first one are checked by Layout/ArgumentAlignment,
7
+ # Arguments after the first one are checked by `Layout/ArgumentAlignment`,
8
8
  # not by this cop.
9
9
  #
10
10
  # For indenting the first parameter of method _definitions_, check out
11
- # Layout/FirstParameterIndentation.
11
+ # `Layout/FirstParameterIndentation`.
12
+ #
13
+ # This cop will respect `Layout/ArgumentAlignment` and will not work when
14
+ # `EnforcedStyle: with_fixed_indentation` is specified for `Layout/ArgumentAlignment`.
12
15
  #
13
16
  # @example
14
17
  #
@@ -149,6 +152,7 @@ module RuboCop
149
152
  MSG = 'Indent the first argument one step more than %<base>s.'
150
153
 
151
154
  def on_send(node)
155
+ return if enforce_first_argument_with_fixed_indentation?
152
156
  return if !node.arguments? || node.operator_method?
153
157
 
154
158
  indent = base_indentation(node) + configured_indentation_width
@@ -250,6 +254,16 @@ module RuboCop
250
254
  def on_new_investigation
251
255
  @comment_lines = nil
252
256
  end
257
+
258
+ def enforce_first_argument_with_fixed_indentation?
259
+ return false unless argument_alignment_config['Enabled']
260
+
261
+ argument_alignment_config['EnforcedStyle'] == 'with_fixed_indentation'
262
+ end
263
+
264
+ def argument_alignment_config
265
+ config.for_cop('Layout/ArgumentAlignment')
266
+ end
253
267
  end
254
268
  end
255
269
  end