rubocop 0.52.0 → 0.52.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.
- checksums.yaml +4 -4
- data/README.md +6 -5
- data/config/default.yml +1 -11
- data/config/disabled.yml +5 -0
- data/config/enabled.yml +6 -8
- data/lib/rubocop.rb +13 -2
- data/lib/rubocop/ast/node.rb +23 -15
- data/lib/rubocop/cli.rb +25 -2
- data/lib/rubocop/config.rb +23 -8
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +2 -2
- data/lib/rubocop/cop/bundler/ordered_gems.rb +9 -0
- data/lib/rubocop/cop/commissioner.rb +1 -1
- data/lib/rubocop/cop/correctors/alignment_corrector.rb +121 -0
- data/lib/rubocop/cop/correctors/condition_corrector.rb +28 -0
- data/lib/rubocop/cop/correctors/empty_line_corrector.rb +26 -0
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +62 -0
- data/lib/rubocop/cop/correctors/ordered_gem_corrector.rb +44 -0
- data/lib/rubocop/cop/correctors/parentheses_corrector.rb +31 -0
- data/lib/rubocop/cop/correctors/punctuation_corrector.rb +29 -0
- data/lib/rubocop/cop/correctors/space_corrector.rb +34 -0
- data/lib/rubocop/cop/correctors/string_literal_corrector.rb +25 -0
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +31 -0
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +2 -2
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +9 -0
- data/lib/rubocop/cop/generator.rb +18 -87
- data/lib/rubocop/cop/generator/require_file_injector.rb +78 -0
- data/lib/rubocop/cop/layout/access_modifier_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/align_array.rb +5 -1
- data/lib/rubocop/cop/layout/align_hash.rb +1 -1
- data/lib/rubocop/cop/layout/align_parameters.rb +5 -1
- data/lib/rubocop/cop/layout/case_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/class_structure.rb +2 -2
- data/lib/rubocop/cop/layout/closing_parenthesis_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/comment_indentation.rb +5 -1
- data/lib/rubocop/cop/layout/else_alignment.rb +5 -1
- data/lib/rubocop/cop/layout/empty_lines_around_access_modifier.rb +3 -3
- data/lib/rubocop/cop/layout/empty_lines_around_arguments.rb +17 -19
- data/lib/rubocop/cop/layout/empty_lines_around_begin_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_block_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_class_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_method_body.rb +4 -0
- data/lib/rubocop/cop/layout/empty_lines_around_module_body.rb +4 -0
- data/lib/rubocop/cop/layout/first_array_element_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_hash_element_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_method_argument_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_method_parameter_line_break.rb +4 -0
- data/lib/rubocop/cop/layout/first_parameter_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/indent_array.rb +6 -2
- data/lib/rubocop/cop/layout/indent_assignment.rb +6 -2
- data/lib/rubocop/cop/layout/indent_hash.rb +5 -1
- data/lib/rubocop/cop/layout/indentation_consistency.rb +5 -1
- data/lib/rubocop/cop/layout/indentation_width.rb +5 -1
- data/lib/rubocop/cop/layout/multiline_array_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_assignment_layout.rb +3 -3
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_hash_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_method_call_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/multiline_method_definition_brace_layout.rb +4 -0
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +6 -2
- data/lib/rubocop/cop/layout/rescue_ensure_alignment.rb +3 -1
- data/lib/rubocop/cop/layout/space_after_comma.rb +4 -0
- data/lib/rubocop/cop/layout/space_after_semicolon.rb +4 -0
- data/lib/rubocop/cop/layout/space_before_comma.rb +4 -0
- data/lib/rubocop/cop/layout/space_before_semicolon.rb +4 -0
- data/lib/rubocop/cop/layout/space_inside_array_literal_brackets.rb +3 -2
- data/lib/rubocop/cop/layout/space_inside_reference_brackets.rb +16 -7
- data/lib/rubocop/cop/layout/tab.rb +1 -1
- data/lib/rubocop/cop/lint/block_alignment.rb +1 -1
- data/lib/rubocop/cop/lint/def_end_alignment.rb +2 -2
- data/lib/rubocop/cop/lint/end_alignment.rb +3 -1
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +1 -1
- data/lib/rubocop/cop/lint/unused_block_argument.rb +4 -0
- data/lib/rubocop/cop/lint/unused_method_argument.rb +6 -0
- data/lib/rubocop/cop/lint/uri_escape_unescape.rb +2 -1
- data/lib/rubocop/cop/mixin/alignment.rb +70 -0
- data/lib/rubocop/cop/mixin/array_hash_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/array_syntax.rb +2 -0
- data/lib/rubocop/cop/mixin/code_length.rb +2 -0
- data/lib/rubocop/cop/mixin/configurable_max.rb +2 -0
- data/lib/rubocop/cop/mixin/def_node.rb +3 -1
- data/lib/rubocop/cop/mixin/documentation_comment.rb +2 -2
- data/lib/rubocop/cop/mixin/empty_lines_around_body.rb +3 -15
- data/lib/rubocop/cop/mixin/end_keyword_alignment.rb +1 -25
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +0 -6
- data/lib/rubocop/cop/mixin/first_element_line_break.rb +5 -9
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +2 -2
- data/lib/rubocop/cop/mixin/ignored_pattern.rb +2 -0
- data/lib/rubocop/cop/mixin/integer_node.rb +2 -0
- data/lib/rubocop/cop/mixin/match_range.rb +2 -0
- data/lib/rubocop/cop/mixin/min_body_length.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_expression_indentation.rb +2 -0
- data/lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb +9 -48
- data/lib/rubocop/cop/mixin/negative_conditional.rb +2 -16
- data/lib/rubocop/cop/mixin/ordered_gem_node.rb +12 -31
- data/lib/rubocop/cop/mixin/parentheses.rb +2 -19
- data/lib/rubocop/cop/mixin/percent_literal.rb +3 -3
- data/lib/rubocop/cop/mixin/preceding_following_alignment.rb +2 -0
- data/lib/rubocop/cop/mixin/rescue_node.rb +2 -0
- data/lib/rubocop/cop/mixin/safe_assignment.rb +2 -0
- data/lib/rubocop/cop/mixin/space_after_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/space_before_punctuation.rb +1 -3
- data/lib/rubocop/cop/mixin/statement_modifier.rb +4 -2
- data/lib/rubocop/cop/mixin/string_help.rb +2 -0
- data/lib/rubocop/cop/mixin/string_literals_help.rb +2 -13
- data/lib/rubocop/cop/mixin/surrounding_space.rb +4 -21
- data/lib/rubocop/cop/mixin/trailing_comma.rb +1 -10
- data/lib/rubocop/cop/mixin/unused_argument.rb +2 -15
- data/lib/rubocop/cop/performance/case_when_splat.rb +1 -1
- data/lib/rubocop/cop/rails/action_filter.rb +3 -2
- data/lib/rubocop/cop/rails/active_support_aliases.rb +3 -2
- data/lib/rubocop/cop/rails/application_job.rb +6 -0
- data/lib/rubocop/cop/rails/application_record.rb +6 -0
- data/lib/rubocop/cop/rails/blank.rb +10 -9
- data/lib/rubocop/cop/rails/date.rb +22 -14
- data/lib/rubocop/cop/rails/delegate.rb +1 -1
- data/lib/rubocop/cop/rails/dynamic_find_by.rb +3 -2
- data/lib/rubocop/cop/rails/enum_uniqueness.rb +4 -2
- data/lib/rubocop/cop/rails/environment_comparison.rb +2 -2
- data/lib/rubocop/cop/rails/file_path.rb +1 -1
- data/lib/rubocop/cop/rails/find_by.rb +2 -2
- data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +15 -7
- data/lib/rubocop/cop/rails/http_positional_arguments.rb +2 -2
- data/lib/rubocop/cop/rails/inverse_of.rb +130 -8
- data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +3 -3
- data/lib/rubocop/cop/rails/pluralization_grammar.rb +3 -2
- data/lib/rubocop/cop/rails/presence.rb +31 -18
- data/lib/rubocop/cop/rails/present.rb +11 -8
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +52 -10
- data/lib/rubocop/cop/rails/request_referer.rb +2 -3
- data/lib/rubocop/cop/style/auto_resource_cleanup.rb +9 -2
- data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +38 -10
- data/lib/rubocop/cop/style/class_and_module_children.rb +76 -0
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/eval_with_location.rb +1 -1
- data/lib/rubocop/cop/style/format_string_token.rb +24 -4
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +46 -0
- data/lib/rubocop/cop/style/hash_syntax.rb +4 -3
- data/lib/rubocop/cop/style/if_unless_modifier.rb +14 -0
- data/lib/rubocop/cop/style/method_def_parentheses.rb +79 -0
- data/lib/rubocop/cop/style/mixin_usage.rb +13 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +19 -0
- data/lib/rubocop/cop/style/negated_if.rb +1 -1
- data/lib/rubocop/cop/style/negated_while.rb +6 -4
- data/lib/rubocop/cop/style/parallel_assignment.rb +1 -1
- data/lib/rubocop/cop/style/parentheses_around_condition.rb +4 -0
- data/lib/rubocop/cop/style/redundant_conditional.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +4 -0
- data/lib/rubocop/cop/style/rescue_modifier.rb +1 -1
- data/lib/rubocop/cop/style/single_line_methods.rb +1 -1
- data/lib/rubocop/cop/style/string_literals.rb +4 -0
- data/lib/rubocop/cop/style/string_literals_in_interpolation.rb +4 -0
- data/lib/rubocop/cop/style/trailing_body_on_method_definition.rb +1 -1
- data/lib/rubocop/cop/style/trailing_comma_in_arguments.rb +4 -0
- data/lib/rubocop/cop/style/trailing_comma_in_literal.rb +4 -0
- data/lib/rubocop/cop/style/trailing_method_end_statement.rb +1 -1
- data/lib/rubocop/formatter/disabled_config_formatter.rb +33 -24
- data/lib/rubocop/options.rb +33 -10
- data/lib/rubocop/path_util.rb +7 -0
- data/lib/rubocop/token.rb +4 -0
- data/lib/rubocop/version.rb +1 -1
- metadata +14 -4
- data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +0 -149
- data/lib/rubocop/cop/style/extend_self.rb +0 -92
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
class Generator
|
6
|
+
# A class that injects a require directive into the root RuboCop file.
|
7
|
+
# It looks for other directives that require files in the same (cop)
|
8
|
+
# namespace and injects the provided one in alpha
|
9
|
+
class RequireFileInjector
|
10
|
+
REQUIRE_PATH = /require_relative ['"](.+)['"]/
|
11
|
+
|
12
|
+
def initialize(source_path:, root_file_path:, output: $stdout)
|
13
|
+
@source_path = Pathname(source_path)
|
14
|
+
@root_file_path = Pathname(root_file_path)
|
15
|
+
@require_entries = File.readlines(root_file_path)
|
16
|
+
@output = output
|
17
|
+
end
|
18
|
+
|
19
|
+
def inject
|
20
|
+
return if require_exists? || !target_line
|
21
|
+
|
22
|
+
File.write(root_file_path, updated_directives)
|
23
|
+
require = injectable_require_directive.chomp
|
24
|
+
output.puts "[modify] #{root_file_path} - `#{require}` was injected."
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :require_entries, :root_file_path, :source_path, :output
|
30
|
+
|
31
|
+
def require_exists?
|
32
|
+
require_entries.any? do |entry|
|
33
|
+
entry == injectable_require_directive
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def updated_directives
|
38
|
+
require_entries.insert(target_line,
|
39
|
+
injectable_require_directive).join
|
40
|
+
end
|
41
|
+
|
42
|
+
def target_line
|
43
|
+
@target_line ||= begin
|
44
|
+
in_the_same_department = false
|
45
|
+
inject_parts = require_path_fragments(injectable_require_directive)
|
46
|
+
|
47
|
+
require_entries.find.with_index do |entry, index|
|
48
|
+
current_entry_parts = require_path_fragments(entry)
|
49
|
+
|
50
|
+
if inject_parts[0..-2] == current_entry_parts[0..-2]
|
51
|
+
in_the_same_department = true
|
52
|
+
|
53
|
+
break index if inject_parts.last < current_entry_parts.last
|
54
|
+
elsif in_the_same_department
|
55
|
+
break index
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def require_path_fragments(require_directove)
|
62
|
+
path = require_directove.match(REQUIRE_PATH)
|
63
|
+
|
64
|
+
path ? path.captures.first.split('/') : []
|
65
|
+
end
|
66
|
+
|
67
|
+
def injectable_require_directive
|
68
|
+
"require_relative '#{require_path}'\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
def require_path
|
72
|
+
path = source_path.relative_path_from(root_file_path.dirname)
|
73
|
+
path.to_s.sub('.rb', '')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -32,7 +32,7 @@ module RuboCop
|
|
32
32
|
# def smooth; end
|
33
33
|
# end
|
34
34
|
class AccessModifierIndentation < Cop
|
35
|
-
include
|
35
|
+
include Alignment
|
36
36
|
include ConfigurableEnforcedStyle
|
37
37
|
|
38
38
|
MSG = '%<style>s access modifiers like `%<node>s`.'.freeze
|
@@ -58,6 +58,10 @@ module RuboCop
|
|
58
58
|
check_body(node.body, node)
|
59
59
|
end
|
60
60
|
|
61
|
+
def autocorrect(node)
|
62
|
+
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
63
|
+
end
|
64
|
+
|
61
65
|
private
|
62
66
|
|
63
67
|
def check_body(body, node)
|
@@ -21,7 +21,7 @@ module RuboCop
|
|
21
21
|
# 'forrest',
|
22
22
|
# 'run']
|
23
23
|
class AlignArray < Cop
|
24
|
-
include
|
24
|
+
include Alignment
|
25
25
|
|
26
26
|
MSG = 'Align the elements of an array literal if they span more ' \
|
27
27
|
'than one line.'.freeze
|
@@ -29,6 +29,10 @@ module RuboCop
|
|
29
29
|
def on_array(node)
|
30
30
|
check_alignment(node.children)
|
31
31
|
end
|
32
|
+
|
33
|
+
def autocorrect(node)
|
34
|
+
AlignmentCorrector.correct(processed_source, node, column_delta)
|
35
|
+
end
|
32
36
|
end
|
33
37
|
end
|
34
38
|
end
|
@@ -116,7 +116,7 @@ module RuboCop
|
|
116
116
|
|
117
117
|
def on_hash(node)
|
118
118
|
return if ignored_node?(node)
|
119
|
-
return if node.empty? || node.single_line?
|
119
|
+
return if node.pairs.empty? || node.single_line?
|
120
120
|
|
121
121
|
return unless alignment_for_hash_rockets.checkable_layout?(node) &&
|
122
122
|
alignment_for_colons.checkable_layout?(node)
|
@@ -28,7 +28,7 @@ module RuboCop
|
|
28
28
|
# foo :bar,
|
29
29
|
# :baz
|
30
30
|
class AlignParameters < Cop
|
31
|
-
include
|
31
|
+
include Alignment
|
32
32
|
|
33
33
|
ALIGN_PARAMS_MSG = 'Align the parameters of a method %<type>s if ' \
|
34
34
|
'they span more than one line.'.freeze
|
@@ -45,6 +45,10 @@ module RuboCop
|
|
45
45
|
alias on_def on_send
|
46
46
|
alias on_defs on_send
|
47
47
|
|
48
|
+
def autocorrect(node)
|
49
|
+
AlignmentCorrector.correct(processed_source, node, column_delta)
|
50
|
+
end
|
51
|
+
|
48
52
|
private
|
49
53
|
|
50
54
|
def message(node)
|
@@ -264,7 +264,7 @@ module RuboCop
|
|
264
264
|
end
|
265
265
|
|
266
266
|
def begin_pos_with_comment(node)
|
267
|
-
annotation_line = node.
|
267
|
+
annotation_line = node.first_line - 1
|
268
268
|
first_comment = nil
|
269
269
|
|
270
270
|
comments_before_line(annotation_line).reverse_each do |comment|
|
@@ -278,7 +278,7 @@ module RuboCop
|
|
278
278
|
end
|
279
279
|
|
280
280
|
def start_line_position(node)
|
281
|
-
buffer.line_range(node.
|
281
|
+
buffer.line_range(node.first_line).begin_pos - 1
|
282
282
|
end
|
283
283
|
|
284
284
|
def comments_before_line(line)
|
@@ -27,7 +27,7 @@ module RuboCop
|
|
27
27
|
# )
|
28
28
|
# end
|
29
29
|
class ClosingParenthesisIndentation < Cop
|
30
|
-
include
|
30
|
+
include Alignment
|
31
31
|
|
32
32
|
MSG_INDENT =
|
33
33
|
'Indent `)` the same as the start of the line where `(` is.'.freeze
|
@@ -46,6 +46,10 @@ module RuboCop
|
|
46
46
|
end
|
47
47
|
alias on_defs on_def
|
48
48
|
|
49
|
+
def autocorrect(node)
|
50
|
+
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
51
|
+
end
|
52
|
+
|
49
53
|
private
|
50
54
|
|
51
55
|
def check(node, elements)
|
@@ -33,7 +33,7 @@ module RuboCop
|
|
33
33
|
# end
|
34
34
|
#
|
35
35
|
class CommentIndentation < Cop
|
36
|
-
include
|
36
|
+
include Alignment
|
37
37
|
|
38
38
|
MSG = 'Incorrect indentation detected (column %<column>d ' \
|
39
39
|
'instead of %<correct_comment_indentation>d).'.freeze
|
@@ -42,6 +42,10 @@ module RuboCop
|
|
42
42
|
processed_source.comments.each { |comment| check(comment) }
|
43
43
|
end
|
44
44
|
|
45
|
+
def autocorrect(node)
|
46
|
+
AlignmentCorrector.correct(processed_source, node, @column_delta)
|
47
|
+
end
|
48
|
+
|
45
49
|
private
|
46
50
|
|
47
51
|
def check(comment)
|
@@ -31,7 +31,7 @@ module RuboCop
|
|
31
31
|
# end
|
32
32
|
class ElseAlignment < Cop
|
33
33
|
include EndKeywordAlignment
|
34
|
-
include
|
34
|
+
include Alignment
|
35
35
|
include CheckAssignment
|
36
36
|
|
37
37
|
MSG = 'Align `%<else_range>s` with `%<base_range>s`.'.freeze
|
@@ -66,6 +66,10 @@ module RuboCop
|
|
66
66
|
check_alignment(node.when_branches.last.loc.keyword, node.loc.else)
|
67
67
|
end
|
68
68
|
|
69
|
+
def autocorrect(node)
|
70
|
+
AlignmentCorrector.correct(processed_source, node, column_delta)
|
71
|
+
end
|
72
|
+
|
69
73
|
private
|
70
74
|
|
71
75
|
def check_nested(node, base)
|
@@ -37,7 +37,7 @@ module RuboCop
|
|
37
37
|
|
38
38
|
def autocorrect(node)
|
39
39
|
lambda do |corrector|
|
40
|
-
send_line = node.
|
40
|
+
send_line = node.first_line
|
41
41
|
previous_line = processed_source[send_line - 2]
|
42
42
|
next_line = processed_source[send_line]
|
43
43
|
line = range_by_whole_lines(node.source_range)
|
@@ -71,7 +71,7 @@ module RuboCop
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def empty_lines_around?(node)
|
74
|
-
send_line = node.
|
74
|
+
send_line = node.first_line
|
75
75
|
previous_line = previous_line_ignoring_comments(processed_source,
|
76
76
|
send_line)
|
77
77
|
next_line = processed_source[send_line]
|
@@ -92,7 +92,7 @@ module RuboCop
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def message(node)
|
95
|
-
previous_line = processed_source[node.
|
95
|
+
previous_line = processed_source[node.first_line - 2]
|
96
96
|
|
97
97
|
if block_start?(previous_line) ||
|
98
98
|
class_def?(previous_line)
|
@@ -42,8 +42,7 @@ module RuboCop
|
|
42
42
|
MSG = 'Empty line detected around arguments.'.freeze
|
43
43
|
|
44
44
|
def on_send(node)
|
45
|
-
return if node.single_line?
|
46
|
-
return if empty_lines(node).empty?
|
45
|
+
return if node.single_line? || node.arguments.empty?
|
47
46
|
extra_lines(node) { |range| add_offense(node, location: range) }
|
48
47
|
end
|
49
48
|
|
@@ -56,21 +55,9 @@ module RuboCop
|
|
56
55
|
private
|
57
56
|
|
58
57
|
def empty_lines(node)
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
lines.map { |_, line| line }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def source_lines(node)
|
67
|
-
source =
|
68
|
-
if node.arguments.last && node.arguments.last.block_type?
|
69
|
-
source_without_block(node, node.arguments.last)
|
70
|
-
else
|
71
|
-
node.source
|
72
|
-
end
|
73
|
-
source.lines.map { |line| line.delete("\n") }
|
58
|
+
lines = processed_lines(node).map.with_index(first_line(node)).to_a
|
59
|
+
lines.select! { |code, _| code.empty? }
|
60
|
+
lines.map { |_, line| line }
|
74
61
|
end
|
75
62
|
|
76
63
|
def extra_lines(node)
|
@@ -80,8 +67,19 @@ module RuboCop
|
|
80
67
|
end
|
81
68
|
end
|
82
69
|
|
83
|
-
def
|
84
|
-
node.
|
70
|
+
def first_line(node)
|
71
|
+
node.receiver ? node.receiver.last_line : node.first_line
|
72
|
+
end
|
73
|
+
|
74
|
+
def last_line(node)
|
75
|
+
last_arg = node.arguments.last
|
76
|
+
last_arg.block_type? ? last_arg.first_line : node.last_line
|
77
|
+
end
|
78
|
+
|
79
|
+
def processed_lines(node)
|
80
|
+
start = first_line(node) - 1
|
81
|
+
stop = last_line(node) - 1
|
82
|
+
processed_source.lines[start..stop]
|
85
83
|
end
|
86
84
|
end
|
87
85
|
end
|
@@ -27,6 +27,10 @@ module RuboCop
|
|
27
27
|
# If it doesn't, Style/FirstMethodArgumentLineBreak will handle it
|
28
28
|
check_children_line_break(node, node.children) if node.loc.begin
|
29
29
|
end
|
30
|
+
|
31
|
+
def autocorrect(node)
|
32
|
+
EmptyLineCorrector.insert_before(node)
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
19
19
|
# first_param,
|
20
20
|
# second_param)
|
21
21
|
class FirstParameterIndentation < Cop
|
22
|
-
include
|
22
|
+
include Alignment
|
23
23
|
include ConfigurableEnforcedStyle
|
24
24
|
|
25
25
|
MSG = 'Indent the first parameter one step more than %<base>s.'.freeze
|
@@ -32,6 +32,10 @@ module RuboCop
|
|
32
32
|
check_alignment([node.first_argument], indent)
|
33
33
|
end
|
34
34
|
|
35
|
+
def autocorrect(node)
|
36
|
+
AlignmentCorrector.correct(processed_source, node, column_delta)
|
37
|
+
end
|
38
|
+
|
35
39
|
private
|
36
40
|
|
37
41
|
def message(arg_node)
|
@@ -54,7 +58,7 @@ module RuboCop
|
|
54
58
|
if special_inner_call_indentation?(node)
|
55
59
|
column_of(base_range(node, node.first_argument))
|
56
60
|
else
|
57
|
-
previous_code_line(node.first_argument.
|
61
|
+
previous_code_line(node.first_argument.first_line) =~ /\S/
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|