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
@@ -10,6 +10,8 @@ module RuboCop
|
|
10
10
|
MSG = 'Favor `%<inverse>s` over `%<current>s` for ' \
|
11
11
|
'negative conditions.'.freeze
|
12
12
|
|
13
|
+
private
|
14
|
+
|
13
15
|
def_node_matcher :single_negative?, '(send !(send _ :!) :!)'
|
14
16
|
def_node_matcher :empty_condition?, '(begin)'
|
15
17
|
|
@@ -25,22 +27,6 @@ module RuboCop
|
|
25
27
|
|
26
28
|
add_offense(node)
|
27
29
|
end
|
28
|
-
|
29
|
-
def negative_conditional_corrector(node)
|
30
|
-
condition = negated_condition(node)
|
31
|
-
|
32
|
-
lambda do |corrector|
|
33
|
-
corrector.replace(node.loc.keyword, node.inverse_keyword)
|
34
|
-
corrector.replace(condition.source_range,
|
35
|
-
condition.children.first.source)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def negated_condition(node)
|
40
|
-
condition = node.condition
|
41
|
-
condition = condition.children.first while condition.begin_type?
|
42
|
-
condition
|
43
|
-
end
|
44
30
|
end
|
45
31
|
end
|
46
32
|
end
|
@@ -5,25 +5,25 @@ module RuboCop
|
|
5
5
|
# Common functionality for Bundler/OrderedGems and
|
6
6
|
# Gemspec/OrderedDependencies.
|
7
7
|
module OrderedGemNode
|
8
|
-
|
9
|
-
previous = previous_declaration(node)
|
10
|
-
|
11
|
-
current_range = declaration_with_comment(node)
|
12
|
-
previous_range = declaration_with_comment(previous)
|
8
|
+
private
|
13
9
|
|
14
|
-
|
15
|
-
|
10
|
+
def get_source_range(node, comments_as_separators)
|
11
|
+
unless comments_as_separators
|
12
|
+
first_comment = processed_source.ast_with_comments[node].first
|
13
|
+
return first_comment.loc.expression unless first_comment.nil?
|
16
14
|
end
|
15
|
+
node.source_range
|
17
16
|
end
|
18
17
|
|
19
|
-
private
|
20
|
-
|
21
18
|
def case_insensitive_out_of_order?(string_a, string_b)
|
22
19
|
string_a.downcase < string_b.downcase
|
23
20
|
end
|
24
21
|
|
25
22
|
def consecutive_lines(previous, current)
|
26
|
-
first_line = get_source_range(
|
23
|
+
first_line = get_source_range(
|
24
|
+
current,
|
25
|
+
treat_comments_as_separators
|
26
|
+
).first_line
|
27
27
|
previous.source_range.last_line == first_line - 1
|
28
28
|
end
|
29
29
|
|
@@ -40,27 +40,8 @@ module RuboCop
|
|
40
40
|
declaration_node.first_argument.str_content
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
45
|
-
begin_pos = get_source_range(node).begin_pos
|
46
|
-
end_line = buffer.line_for_position(node.loc.expression.end_pos)
|
47
|
-
end_pos = buffer.line_range(end_line).end_pos
|
48
|
-
Parser::Source::Range.new(buffer, begin_pos, end_pos)
|
49
|
-
end
|
50
|
-
|
51
|
-
def swap_range(corrector, range1, range2)
|
52
|
-
src1 = range1.source
|
53
|
-
src2 = range2.source
|
54
|
-
corrector.replace(range1, src2)
|
55
|
-
corrector.replace(range2, src1)
|
56
|
-
end
|
57
|
-
|
58
|
-
def get_source_range(node)
|
59
|
-
unless cop_config['TreatCommentsAsGroupSeparators']
|
60
|
-
first_comment = processed_source.ast_with_comments[node].first
|
61
|
-
return first_comment.loc.expression unless first_comment.nil?
|
62
|
-
end
|
63
|
-
node.source_range
|
43
|
+
def treat_comments_as_separators
|
44
|
+
cop_config['TreatCommentsAsGroupSeparators']
|
64
45
|
end
|
65
46
|
end
|
66
47
|
end
|
@@ -4,31 +4,14 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# Common functionality for handling parentheses.
|
6
6
|
module Parentheses
|
7
|
+
private
|
8
|
+
|
7
9
|
def parens_required?(node)
|
8
10
|
range = node.source_range
|
9
11
|
source = range.source_buffer.source
|
10
12
|
source[range.begin_pos - 1] =~ /[a-z]/ ||
|
11
13
|
source[range.end_pos] =~ /[a-z]/
|
12
14
|
end
|
13
|
-
|
14
|
-
def autocorrect(node)
|
15
|
-
lambda do |corrector|
|
16
|
-
corrector.remove(node.loc.begin)
|
17
|
-
corrector.remove(node.loc.end)
|
18
|
-
|
19
|
-
if ternary_condition?(node) && next_char_is_question_mark?(node)
|
20
|
-
corrector.insert_after(node.loc.end, ' ')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def ternary_condition?(node)
|
26
|
-
node.parent && node.parent.if_type? && node.parent.ternary?
|
27
|
-
end
|
28
|
-
|
29
|
-
def next_char_is_question_mark?(node)
|
30
|
-
node.loc.last_column == node.parent.loc.question.column
|
31
|
-
end
|
32
15
|
end
|
33
16
|
end
|
34
17
|
end
|
@@ -38,7 +38,7 @@ module RuboCop
|
|
38
38
|
escape = words.any? { |w| needs_escaping?(w.children[0]) }
|
39
39
|
char = char.upcase if escape
|
40
40
|
delimiters = preferred_delimiters_for("%#{char}")
|
41
|
-
contents = autocorrect_words(words, escape, node.
|
41
|
+
contents = autocorrect_words(words, escape, node.first_line, delimiters)
|
42
42
|
|
43
43
|
lambda do |corrector|
|
44
44
|
corrector.replace(
|
@@ -51,9 +51,9 @@ module RuboCop
|
|
51
51
|
def autocorrect_words(word_nodes, escape, base_line_number, delimiters)
|
52
52
|
previous_node_line_number = base_line_number
|
53
53
|
word_nodes.map do |node|
|
54
|
-
number_of_line_breaks = node.
|
54
|
+
number_of_line_breaks = node.first_line - previous_node_line_number
|
55
55
|
line_breaks = "\n" * number_of_line_breaks
|
56
|
-
previous_node_line_number = node.
|
56
|
+
previous_node_line_number = node.first_line
|
57
57
|
content = node.children.first.to_s
|
58
58
|
content = escape ? escape_string(content) : content
|
59
59
|
delimiters.each do |delimiter|
|
@@ -4,6 +4,8 @@ module RuboCop
|
|
4
4
|
module Cop
|
5
5
|
# Common functionality for modifier cops.
|
6
6
|
module StatementModifier
|
7
|
+
private
|
8
|
+
|
7
9
|
def single_line_as_modifier?(node)
|
8
10
|
return false if non_eligible_node?(node) ||
|
9
11
|
non_eligible_body?(node.body) ||
|
@@ -19,7 +21,7 @@ module RuboCop
|
|
19
21
|
|
20
22
|
def non_eligible_body?(body)
|
21
23
|
body.nil? ||
|
22
|
-
body.
|
24
|
+
body.empty_source? ||
|
23
25
|
body.begin_type? ||
|
24
26
|
commented?(body.source_range)
|
25
27
|
end
|
@@ -30,7 +32,7 @@ module RuboCop
|
|
30
32
|
|
31
33
|
def modifier_fits_on_single_line?(node)
|
32
34
|
modifier_length = length_in_modifier_form(node, node.condition,
|
33
|
-
node.body.
|
35
|
+
node.body.source_length)
|
34
36
|
|
35
37
|
modifier_length <= max_line_length
|
36
38
|
end
|
@@ -6,6 +6,8 @@ module RuboCop
|
|
6
6
|
module StringLiteralsHelp
|
7
7
|
include StringHelp
|
8
8
|
|
9
|
+
private
|
10
|
+
|
9
11
|
def wrong_quotes?(node)
|
10
12
|
src = node.source
|
11
13
|
return false if src.start_with?('%', '?')
|
@@ -15,19 +17,6 @@ module RuboCop
|
|
15
17
|
src !~ /" | \\[^'] | \#(@|\{)/x
|
16
18
|
end
|
17
19
|
end
|
18
|
-
|
19
|
-
def autocorrect(node)
|
20
|
-
return if node.dstr_type?
|
21
|
-
|
22
|
-
lambda do |corrector|
|
23
|
-
str = node.str_content
|
24
|
-
if style == :single_quotes
|
25
|
-
corrector.replace(node.source_range, to_string_literal(str))
|
26
|
-
else
|
27
|
-
corrector.replace(node.source_range, str.inspect)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
20
|
end
|
32
21
|
end
|
33
22
|
end
|
@@ -7,6 +7,8 @@ module RuboCop
|
|
7
7
|
NO_SPACE_COMMAND = 'Do not use'.freeze
|
8
8
|
SPACE_COMMAND = 'Use'.freeze
|
9
9
|
|
10
|
+
private
|
11
|
+
|
10
12
|
def side_space_range(range:, side:)
|
11
13
|
buffer = @processed_source.buffer
|
12
14
|
src = buffer.source
|
@@ -50,7 +52,8 @@ module RuboCop
|
|
50
52
|
end
|
51
53
|
|
52
54
|
def tokens(node)
|
53
|
-
|
55
|
+
@tokens ||= {}
|
56
|
+
@tokens[node.object_id] ||= processed_source.tokens.select do |token|
|
54
57
|
token.end_pos <= node.source_range.end_pos &&
|
55
58
|
token.begin_pos >= node.source_range.begin_pos
|
56
59
|
end
|
@@ -69,16 +72,6 @@ module RuboCop
|
|
69
72
|
space_offense(node, right_token, :left, message, NO_SPACE_COMMAND)
|
70
73
|
end
|
71
74
|
|
72
|
-
def no_space_corrector(corrector, left_token, right_token)
|
73
|
-
if left_token.space_after?
|
74
|
-
range = side_space_range(range: left_token.pos, side: :right)
|
75
|
-
corrector.remove(range)
|
76
|
-
end
|
77
|
-
return unless right_token.space_before?
|
78
|
-
range = side_space_range(range: right_token.pos, side: :left)
|
79
|
-
corrector.remove(range)
|
80
|
-
end
|
81
|
-
|
82
75
|
def space_offenses(node, # rubocop:disable Metrics/ParameterLists
|
83
76
|
left_token,
|
84
77
|
right_token,
|
@@ -92,16 +85,6 @@ module RuboCop
|
|
92
85
|
space_offense(node, right_token, :none, message, SPACE_COMMAND)
|
93
86
|
end
|
94
87
|
|
95
|
-
def space_corrector(corrector, left_token, right_token)
|
96
|
-
unless left_token.space_after?
|
97
|
-
corrector.insert_after(left_token.pos, ' ')
|
98
|
-
end
|
99
|
-
return if right_token.space_before?
|
100
|
-
corrector.insert_before(right_token.pos, ' ')
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
104
|
-
|
105
88
|
def extra_space?(token, side)
|
106
89
|
return false unless token
|
107
90
|
if side == :left
|
@@ -9,16 +9,7 @@ module RuboCop
|
|
9
9
|
|
10
10
|
MSG = '%<command>s comma after the last %<unit>s.'.freeze
|
11
11
|
|
12
|
-
|
13
|
-
return unless range
|
14
|
-
|
15
|
-
lambda do |corrector|
|
16
|
-
case range.source
|
17
|
-
when ',' then corrector.remove(range)
|
18
|
-
else corrector.insert_after(range, ',')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
12
|
+
private
|
22
13
|
|
23
14
|
def style_parameter_name
|
24
15
|
'EnforcedStyleForMultiline'
|
@@ -17,6 +17,8 @@ module RuboCop
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
private
|
21
|
+
|
20
22
|
def check_argument(variable)
|
21
23
|
return if variable.should_be_unused?
|
22
24
|
return if variable.referenced?
|
@@ -25,21 +27,6 @@ module RuboCop
|
|
25
27
|
add_offense(variable.declaration_node, location: :name,
|
26
28
|
message: message)
|
27
29
|
end
|
28
|
-
|
29
|
-
def autocorrect(node)
|
30
|
-
return if %i[kwarg kwoptarg].include?(node.type)
|
31
|
-
|
32
|
-
if node.blockarg_type?
|
33
|
-
lambda do |corrector|
|
34
|
-
range = range_with_surrounding_space(range: node.source_range,
|
35
|
-
side: :left)
|
36
|
-
range = range_with_surrounding_comma(range, :left)
|
37
|
-
corrector.remove(range)
|
38
|
-
end
|
39
|
-
else
|
40
|
-
->(corrector) { corrector.insert_before(node.loc.name, '_') }
|
41
|
-
end
|
42
|
-
end
|
43
30
|
end
|
44
31
|
end
|
45
32
|
end
|
@@ -36,7 +36,7 @@ module RuboCop
|
|
36
36
|
extend TargetRailsVersion
|
37
37
|
include ConfigurableEnforcedStyle
|
38
38
|
|
39
|
-
MSG = 'Prefer
|
39
|
+
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'.freeze
|
40
40
|
|
41
41
|
FILTER_METHODS = %i[
|
42
42
|
after_filter
|
@@ -96,7 +96,8 @@ module RuboCop
|
|
96
96
|
end
|
97
97
|
|
98
98
|
def message(node)
|
99
|
-
format(MSG, preferred_method(node.method_name),
|
99
|
+
format(MSG, prefer: preferred_method(node.method_name),
|
100
|
+
current: node.method_name)
|
100
101
|
end
|
101
102
|
|
102
103
|
def bad_methods
|
@@ -20,7 +20,7 @@ module RuboCop
|
|
20
20
|
# [1, 2, 'a'].prepend('b')
|
21
21
|
#
|
22
22
|
class ActiveSupportAliases < Cop
|
23
|
-
MSG = 'Use
|
23
|
+
MSG = 'Use `%<prefer>s` instead of `%<current>s`.'.freeze
|
24
24
|
|
25
25
|
ALIASES = {
|
26
26
|
starts_with?: {
|
@@ -58,7 +58,8 @@ module RuboCop
|
|
58
58
|
def register_offense(node, method_name)
|
59
59
|
add_offense(
|
60
60
|
node,
|
61
|
-
message: format(MSG, ALIASES[method_name][:original],
|
61
|
+
message: format(MSG, prefer: ALIASES[method_name][:original],
|
62
|
+
current: method_name)
|
62
63
|
)
|
63
64
|
end
|
64
65
|
end
|
@@ -28,6 +28,12 @@ module RuboCop
|
|
28
28
|
# rubocop:disable Layout/ClassStructure
|
29
29
|
include RuboCop::Cop::EnforceSuperclass
|
30
30
|
# rubocop:enable Layout/ClassStructure
|
31
|
+
|
32
|
+
def autocorrect(node)
|
33
|
+
lambda do |corrector|
|
34
|
+
corrector.replace(node.source_range, self.class::SUPERCLASS)
|
35
|
+
end
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
33
39
|
end
|
@@ -28,6 +28,12 @@ module RuboCop
|
|
28
28
|
# rubocop:disable Layout/ClassStructure
|
29
29
|
include RuboCop::Cop::EnforceSuperclass
|
30
30
|
# rubocop:enable Layout/ClassStructure
|
31
|
+
|
32
|
+
def autocorrect(node)
|
33
|
+
lambda do |corrector|
|
34
|
+
corrector.replace(node.source_range, self.class::SUPERCLASS)
|
35
|
+
end
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
33
39
|
end
|