rubocop 1.65.0 → 1.66.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +67 -67
- data/config/default.yml +18 -2
- data/exe/rubocop +4 -3
- data/lib/rubocop/comment_config.rb +1 -1
- data/lib/rubocop/config.rb +5 -1
- data/lib/rubocop/config_loader.rb +14 -8
- data/lib/rubocop/config_loader_resolver.rb +1 -2
- data/lib/rubocop/config_validator.rb +1 -1
- data/lib/rubocop/cop/base.rb +4 -0
- data/lib/rubocop/cop/cop.rb +2 -2
- data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -0
- data/lib/rubocop/cop/documentation.rb +18 -1
- data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +2 -1
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/undefined_config.rb +11 -1
- data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
- data/lib/rubocop/cop/layout/block_alignment.rb +30 -12
- data/lib/rubocop/cop/layout/condition_position.rb +0 -4
- data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
- data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +8 -3
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +0 -3
- data/lib/rubocop/cop/layout/line_length.rb +14 -14
- data/lib/rubocop/cop/lint/ambiguous_block_association.rb +0 -2
- data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
- data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
- data/lib/rubocop/cop/lint/boolean_symbol.rb +0 -2
- data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -13
- data/lib/rubocop/cop/lint/debugger.rb +0 -4
- data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +0 -10
- data/lib/rubocop/cop/lint/duplicate_case_condition.rb +0 -4
- data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
- data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -10
- data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
- data/lib/rubocop/cop/lint/else_layout.rb +0 -2
- data/lib/rubocop/cop/lint/empty_conditional_body.rb +27 -6
- data/lib/rubocop/cop/lint/empty_ensure.rb +1 -11
- data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -4
- data/lib/rubocop/cop/lint/empty_when.rb +0 -2
- data/lib/rubocop/cop/lint/ensure_return.rb +1 -6
- data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -4
- data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -10
- data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +5 -7
- data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
- data/lib/rubocop/cop/lint/interpolation_check.rb +0 -4
- data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
- data/lib/rubocop/cop/lint/literal_in_interpolation.rb +0 -4
- data/lib/rubocop/cop/lint/loop.rb +6 -12
- data/lib/rubocop/cop/lint/nested_method_definition.rb +0 -6
- data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -4
- data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +0 -5
- data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
- data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
- data/lib/rubocop/cop/lint/rand_one.rb +0 -4
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +3 -1
- data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_string_coercion.rb +0 -4
- data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
- data/lib/rubocop/cop/lint/rescue_exception.rb +0 -4
- data/lib/rubocop/cop/lint/return_in_void_context.rb +0 -2
- data/lib/rubocop/cop/lint/safe_navigation_chain.rb +0 -4
- data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +6 -10
- data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
- data/lib/rubocop/cop/lint/unreachable_code.rb +0 -5
- data/lib/rubocop/cop/lint/useless_assignment.rb +19 -16
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -4
- data/lib/rubocop/cop/lint/useless_numeric_operation.rb +77 -0
- data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -4
- data/lib/rubocop/cop/lint/void.rb +30 -8
- data/lib/rubocop/cop/metrics/block_length.rb +6 -5
- data/lib/rubocop/cop/metrics/class_length.rb +6 -5
- data/lib/rubocop/cop/metrics/method_length.rb +6 -5
- data/lib/rubocop/cop/metrics/module_length.rb +6 -5
- data/lib/rubocop/cop/mixin/annotation_comment.rb +0 -2
- data/lib/rubocop/cop/mixin/frozen_string_literal.rb +19 -9
- data/lib/rubocop/cop/mixin/line_length_help.rb +7 -2
- data/lib/rubocop/cop/mixin/string_literals_help.rb +12 -0
- data/lib/rubocop/cop/naming/accessor_method_name.rb +5 -0
- data/lib/rubocop/cop/naming/predicate_name.rb +52 -26
- data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -1
- data/lib/rubocop/cop/style/alias.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +8 -3
- data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -2
- data/lib/rubocop/cop/style/each_for_simple_loop.rb +0 -1
- data/lib/rubocop/cop/style/empty_else.rb +6 -5
- data/lib/rubocop/cop/style/empty_heredoc.rb +1 -14
- data/lib/rubocop/cop/style/empty_literal.rb +31 -22
- data/lib/rubocop/cop/style/eval_with_location.rb +12 -11
- data/lib/rubocop/cop/style/file_read.rb +2 -5
- data/lib/rubocop/cop/style/file_write.rb +2 -5
- data/lib/rubocop/cop/style/format_string_token.rb +2 -2
- data/lib/rubocop/cop/style/global_std_stream.rb +7 -1
- data/lib/rubocop/cop/style/guard_clause.rb +2 -0
- data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
- data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +0 -1
- data/lib/rubocop/cop/style/if_with_semicolon.rb +45 -6
- data/lib/rubocop/cop/style/in_pattern_then.rb +6 -2
- data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
- data/lib/rubocop/cop/style/magic_comment_format.rb +1 -1
- data/lib/rubocop/cop/style/map_into_array.rb +12 -5
- data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
- data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/missing_else.rb +0 -4
- data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
- data/lib/rubocop/cop/style/multiple_comparison.rb +3 -11
- data/lib/rubocop/cop/style/numeric_predicate.rb +2 -2
- data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
- data/lib/rubocop/cop/style/parallel_assignment.rb +5 -4
- data/lib/rubocop/cop/style/quoted_symbols.rb +0 -2
- data/lib/rubocop/cop/style/redundant_condition.rb +3 -3
- data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +46 -0
- data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -1
- data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -24
- data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +21 -2
- data/lib/rubocop/cop/style/while_until_do.rb +0 -2
- data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
- data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -1
- data/lib/rubocop/cop/team.rb +6 -2
- data/lib/rubocop/cop/variable_force.rb +13 -1
- data/lib/rubocop/core_ext/string.rb +2 -6
- data/lib/rubocop/ext/regexp_node.rb +9 -31
- data/lib/rubocop/formatter/junit_formatter.rb +70 -23
- data/lib/rubocop/lockfile.rb +6 -4
- data/lib/rubocop/options.rb +3 -1
- data/lib/rubocop/remote_config.rb +5 -1
- data/lib/rubocop/result_cache.rb +2 -8
- data/lib/rubocop/rspec/shared_contexts.rb +2 -2
- data/lib/rubocop/server/cache.rb +1 -1
- data/lib/rubocop/target_ruby.rb +7 -3
- data/lib/rubocop/version.rb +1 -1
- data/lib/rubocop/yaml_duplication_checker.rb +1 -0
- data/lib/rubocop.rb +7 -1
- metadata +8 -26
@@ -149,7 +149,8 @@ module RuboCop
|
|
149
149
|
newline_pos = source_buffer.source.index("\n", end_pos)
|
150
150
|
|
151
151
|
# Handle the case when multiple one-liners are on the same line.
|
152
|
-
|
152
|
+
begin_pos = node.source_range.begin_pos
|
153
|
+
newline_pos = begin_pos - 1 if newline_pos > begin_pos
|
153
154
|
|
154
155
|
if count > maximum_empty_lines
|
155
156
|
autocorrect_remove_lines(corrector, newline_pos, count)
|
@@ -83,7 +83,7 @@ module RuboCop
|
|
83
83
|
|
84
84
|
locations.each do |loc|
|
85
85
|
line = loc.line
|
86
|
-
next if line == line_of_def_or_kwbegin ||
|
86
|
+
next if line == line_of_def_or_kwbegin || last_body_and_end_on_same_line?(body)
|
87
87
|
|
88
88
|
keyword = loc.source
|
89
89
|
# below the keyword
|
@@ -93,8 +93,13 @@ module RuboCop
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
def
|
97
|
-
|
96
|
+
def last_body_and_end_on_same_line?(body)
|
97
|
+
end_keyword_line = body.parent.loc.end.line
|
98
|
+
return body.loc.last_line == end_keyword_line unless body.rescue_type?
|
99
|
+
|
100
|
+
last_body_line = body.else? ? body.loc.else.line : body.resbody_branches.last.loc.line
|
101
|
+
|
102
|
+
last_body_line == end_keyword_line
|
98
103
|
end
|
99
104
|
|
100
105
|
def message(location, keyword)
|
@@ -51,7 +51,6 @@ module RuboCop
|
|
51
51
|
# # defined inside a method call.
|
52
52
|
#
|
53
53
|
# # bad
|
54
|
-
# # consistent
|
55
54
|
# array = [
|
56
55
|
# :value
|
57
56
|
# ]
|
@@ -72,13 +71,11 @@ module RuboCop
|
|
72
71
|
# # brackets are indented to the same position.
|
73
72
|
#
|
74
73
|
# # bad
|
75
|
-
# # align_brackets
|
76
74
|
# and_now_for_something = [
|
77
75
|
# :completely_different
|
78
76
|
# ]
|
79
77
|
#
|
80
78
|
# # good
|
81
|
-
# # align_brackets
|
82
79
|
# and_now_for_something = [
|
83
80
|
# :completely_different
|
84
81
|
# ]
|
@@ -25,20 +25,20 @@ module RuboCop
|
|
25
25
|
# * `Layout/ArrayAlignment`
|
26
26
|
# * `Layout/BlockAlignment`
|
27
27
|
# * `Layout/BlockEndNewline`
|
28
|
-
# * `
|
29
|
-
# * `
|
30
|
-
# * `
|
31
|
-
# * `
|
32
|
-
# * `
|
33
|
-
# * `
|
34
|
-
# * `
|
35
|
-
# * `
|
36
|
-
# * `
|
37
|
-
# * `
|
38
|
-
# * `
|
39
|
-
# * `
|
40
|
-
# * `
|
41
|
-
# * `Layout
|
28
|
+
# * `Layout/ClosingParenthesisIndentation`
|
29
|
+
# * `Layout/FirstArgumentIndentation`
|
30
|
+
# * `Layout/FirstArrayElementIndentation`
|
31
|
+
# * `Layout/FirstHashElementIndentation`
|
32
|
+
# * `Layout/FirstParameterIndentation`
|
33
|
+
# * `Layout/HashAlignment`
|
34
|
+
# * `Layout/IndentationWidth`
|
35
|
+
# * `Layout/MultilineArrayLineBreaks`
|
36
|
+
# * `Layout/MultilineBlockLayout`
|
37
|
+
# * `Layout/MultilineHashBraceLayout`
|
38
|
+
# * `Layout/MultilineHashKeyLineBreaks`
|
39
|
+
# * `Layout/MultilineMethodArgumentLineBreaks`
|
40
|
+
# * `Layout/MultilineMethodParameterLineBreaks`
|
41
|
+
# * `Layout//ParameterAlignment`
|
42
42
|
# * `Style/BlockDelimiters`
|
43
43
|
#
|
44
44
|
# Together, these cops will pretty print hashes, arrays,
|
@@ -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
|
@@ -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
|
@@ -67,19 +67,31 @@ module RuboCop
|
|
67
67
|
|
68
68
|
MSG = 'Avoid `%<keyword>s` branches without a body.'
|
69
69
|
|
70
|
+
# rubocop:disable Metrics/AbcSize
|
70
71
|
def on_if(node)
|
71
72
|
return if node.body || same_line?(node.loc.begin, node.loc.end)
|
72
73
|
return if cop_config['AllowComments'] && contains_comments?(node)
|
73
74
|
|
74
|
-
|
75
|
+
range = offense_range(node)
|
76
|
+
|
77
|
+
add_offense(range, message: format(MSG, keyword: node.keyword)) do |corrector|
|
75
78
|
next if node.parent&.call_type?
|
76
79
|
|
77
80
|
autocorrect(corrector, node)
|
78
81
|
end
|
79
82
|
end
|
83
|
+
# rubocop:enable Metrics/AbcSize
|
80
84
|
|
81
85
|
private
|
82
86
|
|
87
|
+
def offense_range(node)
|
88
|
+
if node.loc.else
|
89
|
+
node.source_range.begin.join(node.loc.else.begin)
|
90
|
+
else
|
91
|
+
node.source_range
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
83
95
|
def autocorrect(corrector, node)
|
84
96
|
remove_comments(corrector, node)
|
85
97
|
remove_empty_branch(corrector, node)
|
@@ -93,13 +105,22 @@ module RuboCop
|
|
93
105
|
end
|
94
106
|
end
|
95
107
|
|
108
|
+
# rubocop:disable Metrics/AbcSize
|
96
109
|
def remove_empty_branch(corrector, node)
|
97
|
-
if empty_if_branch?(node) && else_branch?(node)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
110
|
+
range = if empty_if_branch?(node) && else_branch?(node)
|
111
|
+
branch_range(node)
|
112
|
+
elsif same_line?(node, else_kw_loc = node.loc.else)
|
113
|
+
node.source_range.begin.join(else_kw_loc.begin)
|
114
|
+
elsif node.parent&.loc.respond_to?(:end) &&
|
115
|
+
same_line?(node, end_loc = node.parent.loc.end)
|
116
|
+
node.source_range.begin.join(end_loc.begin)
|
117
|
+
else
|
118
|
+
deletion_range(branch_range(node))
|
119
|
+
end
|
120
|
+
|
121
|
+
corrector.remove(range)
|
102
122
|
end
|
123
|
+
# rubocop:enable Metrics/AbcSize
|
103
124
|
|
104
125
|
def correct_other_branches(corrector, node)
|
105
126
|
return unless require_other_branches_correction?(node)
|
@@ -3,40 +3,30 @@
|
|
3
3
|
module RuboCop
|
4
4
|
module Cop
|
5
5
|
module Lint
|
6
|
-
# Checks for empty `ensure` blocks
|
6
|
+
# Checks for empty `ensure` blocks.
|
7
7
|
#
|
8
8
|
# @example
|
9
9
|
#
|
10
10
|
# # bad
|
11
|
-
#
|
12
11
|
# def some_method
|
13
12
|
# do_something
|
14
13
|
# ensure
|
15
14
|
# end
|
16
15
|
#
|
17
|
-
# @example
|
18
|
-
#
|
19
16
|
# # bad
|
20
|
-
#
|
21
17
|
# begin
|
22
18
|
# do_something
|
23
19
|
# ensure
|
24
20
|
# end
|
25
21
|
#
|
26
|
-
# @example
|
27
|
-
#
|
28
22
|
# # good
|
29
|
-
#
|
30
23
|
# def some_method
|
31
24
|
# do_something
|
32
25
|
# ensure
|
33
26
|
# do_something_else
|
34
27
|
# end
|
35
28
|
#
|
36
|
-
# @example
|
37
|
-
#
|
38
29
|
# # good
|
39
|
-
#
|
40
30
|
# begin
|
41
31
|
# do_something
|
42
32
|
# ensure
|
@@ -13,7 +13,6 @@ module RuboCop
|
|
13
13
|
# @example
|
14
14
|
#
|
15
15
|
# # bad
|
16
|
-
#
|
17
16
|
# def foo
|
18
17
|
# do_something
|
19
18
|
# ensure
|
@@ -21,10 +20,7 @@ module RuboCop
|
|
21
20
|
# return self
|
22
21
|
# end
|
23
22
|
#
|
24
|
-
# @example
|
25
|
-
#
|
26
23
|
# # good
|
27
|
-
#
|
28
24
|
# def foo
|
29
25
|
# do_something
|
30
26
|
# self
|
@@ -32,8 +28,7 @@ module RuboCop
|
|
32
28
|
# cleanup
|
33
29
|
# end
|
34
30
|
#
|
35
|
-
# #
|
36
|
-
#
|
31
|
+
# # good
|
37
32
|
# def foo
|
38
33
|
# begin
|
39
34
|
# do_something
|
@@ -14,25 +14,15 @@ module RuboCop
|
|
14
14
|
# @example
|
15
15
|
#
|
16
16
|
# # bad
|
17
|
-
#
|
18
17
|
# format('A value: %s and another: %i', a_value)
|
19
18
|
#
|
20
|
-
# @example
|
21
|
-
#
|
22
19
|
# # good
|
23
|
-
#
|
24
20
|
# format('A value: %s and another: %i', a_value, another)
|
25
21
|
#
|
26
|
-
# @example
|
27
|
-
#
|
28
22
|
# # bad
|
29
|
-
#
|
30
23
|
# format('Unnumbered format: %s and numbered: %2$s', a_value, another)
|
31
24
|
#
|
32
|
-
# @example
|
33
|
-
#
|
34
25
|
# # good
|
35
|
-
#
|
36
26
|
# format('Numbered format: %1$s and numbered %2$s', a_value, another)
|
37
27
|
class FormatParameterMismatch < Base
|
38
28
|
# http://rubular.com/r/CvpbxkcTzy
|
@@ -9,13 +9,9 @@ module RuboCop
|
|
9
9
|
# @example
|
10
10
|
#
|
11
11
|
# # bad
|
12
|
-
#
|
13
12
|
# array = ['Item 1' 'Item 2']
|
14
13
|
#
|
15
|
-
# @example
|
16
|
-
#
|
17
14
|
# # good
|
18
|
-
#
|
19
15
|
# array = ['Item 1Item 2']
|
20
16
|
# array = ['Item 1' + 'Item 2']
|
21
17
|
# array = [
|
@@ -44,9 +40,9 @@ module RuboCop
|
|
44
40
|
end
|
45
41
|
|
46
42
|
add_offense(range, message: message) do |corrector|
|
47
|
-
|
43
|
+
range = lhs_node.source_range.end.join(rhs_node.source_range.begin)
|
48
44
|
|
49
|
-
corrector.replace(range,
|
45
|
+
corrector.replace(range, ' + ')
|
50
46
|
end
|
51
47
|
end
|
52
48
|
end
|
@@ -80,7 +76,7 @@ module RuboCop
|
|
80
76
|
end
|
81
77
|
|
82
78
|
def string_literal?(node)
|
83
|
-
node.str_type? ||
|
79
|
+
node.str_type? || node.dstr_type?
|
84
80
|
end
|
85
81
|
|
86
82
|
def string_literals?(node1, node2)
|
@@ -96,6 +92,8 @@ module RuboCop
|
|
96
92
|
end
|
97
93
|
|
98
94
|
def str_content(node)
|
95
|
+
return unless node.respond_to?(:str_type?)
|
96
|
+
|
99
97
|
if node.str_type?
|
100
98
|
node.children[0]
|
101
99
|
else
|
@@ -11,7 +11,6 @@ module RuboCop
|
|
11
11
|
# @example
|
12
12
|
#
|
13
13
|
# # bad
|
14
|
-
#
|
15
14
|
# class C
|
16
15
|
# private
|
17
16
|
#
|
@@ -20,10 +19,7 @@ module RuboCop
|
|
20
19
|
# end
|
21
20
|
# end
|
22
21
|
#
|
23
|
-
# @example
|
24
|
-
#
|
25
22
|
# # good
|
26
|
-
#
|
27
23
|
# class C
|
28
24
|
# def self.method
|
29
25
|
# puts 'hi'
|
@@ -32,10 +28,7 @@ module RuboCop
|
|
32
28
|
# private_class_method :method
|
33
29
|
# end
|
34
30
|
#
|
35
|
-
# @example
|
36
|
-
#
|
37
31
|
# # good
|
38
|
-
#
|
39
32
|
# class C
|
40
33
|
# class << self
|
41
34
|
# private
|
@@ -14,13 +14,9 @@ module RuboCop
|
|
14
14
|
# @example
|
15
15
|
#
|
16
16
|
# # bad
|
17
|
-
#
|
18
17
|
# foo = 'something with #{interpolation} inside'
|
19
18
|
#
|
20
|
-
# @example
|
21
|
-
#
|
22
19
|
# # good
|
23
|
-
#
|
24
20
|
# foo = "something with #{interpolation} inside"
|
25
21
|
class InterpolationCheck < Base
|
26
22
|
extend AutoCorrector
|
@@ -19,17 +19,6 @@ module RuboCop
|
|
19
19
|
# do_something
|
20
20
|
# end while some_condition
|
21
21
|
#
|
22
|
-
# @example
|
23
|
-
#
|
24
|
-
# # bad
|
25
|
-
#
|
26
|
-
# # using until
|
27
|
-
# begin
|
28
|
-
# do_something
|
29
|
-
# end until some_condition
|
30
|
-
#
|
31
|
-
# @example
|
32
|
-
#
|
33
22
|
# # good
|
34
23
|
#
|
35
24
|
# # while replacement
|
@@ -38,7 +27,12 @@ module RuboCop
|
|
38
27
|
# break unless some_condition
|
39
28
|
# end
|
40
29
|
#
|
41
|
-
#
|
30
|
+
# # bad
|
31
|
+
#
|
32
|
+
# # using until
|
33
|
+
# begin
|
34
|
+
# do_something
|
35
|
+
# end until some_condition
|
42
36
|
#
|
43
37
|
# # good
|
44
38
|
#
|