rubocop 1.65.0 → 1.66.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +67 -67
  3. data/config/default.yml +18 -2
  4. data/exe/rubocop +4 -3
  5. data/lib/rubocop/comment_config.rb +1 -1
  6. data/lib/rubocop/config.rb +5 -1
  7. data/lib/rubocop/config_loader.rb +14 -8
  8. data/lib/rubocop/config_loader_resolver.rb +1 -2
  9. data/lib/rubocop/config_validator.rb +1 -1
  10. data/lib/rubocop/cop/base.rb +4 -0
  11. data/lib/rubocop/cop/cop.rb +2 -2
  12. data/lib/rubocop/cop/correctors/line_break_corrector.rb +2 -0
  13. data/lib/rubocop/cop/documentation.rb +18 -1
  14. data/lib/rubocop/cop/internal_affairs/empty_line_between_expect_offense_and_correction.rb +2 -1
  15. data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -1
  16. data/lib/rubocop/cop/internal_affairs/undefined_config.rb +11 -1
  17. data/lib/rubocop/cop/layout/assignment_indentation.rb +3 -2
  18. data/lib/rubocop/cop/layout/block_alignment.rb +30 -12
  19. data/lib/rubocop/cop/layout/condition_position.rb +0 -4
  20. data/lib/rubocop/cop/layout/empty_line_between_defs.rb +2 -1
  21. data/lib/rubocop/cop/layout/empty_lines_around_exception_handling_keywords.rb +8 -3
  22. data/lib/rubocop/cop/layout/first_array_element_indentation.rb +0 -3
  23. data/lib/rubocop/cop/layout/line_length.rb +14 -14
  24. data/lib/rubocop/cop/lint/ambiguous_block_association.rb +0 -2
  25. data/lib/rubocop/cop/lint/ambiguous_operator.rb +0 -2
  26. data/lib/rubocop/cop/lint/ambiguous_regexp_literal.rb +0 -2
  27. data/lib/rubocop/cop/lint/boolean_symbol.rb +0 -2
  28. data/lib/rubocop/cop/lint/circular_argument_reference.rb +0 -13
  29. data/lib/rubocop/cop/lint/debugger.rb +0 -4
  30. data/lib/rubocop/cop/lint/deprecated_open_ssl_constant.rb +0 -10
  31. data/lib/rubocop/cop/lint/duplicate_case_condition.rb +0 -4
  32. data/lib/rubocop/cop/lint/duplicate_hash_key.rb +0 -4
  33. data/lib/rubocop/cop/lint/duplicate_methods.rb +0 -10
  34. data/lib/rubocop/cop/lint/each_with_object_argument.rb +0 -4
  35. data/lib/rubocop/cop/lint/else_layout.rb +0 -2
  36. data/lib/rubocop/cop/lint/empty_conditional_body.rb +27 -6
  37. data/lib/rubocop/cop/lint/empty_ensure.rb +1 -11
  38. data/lib/rubocop/cop/lint/empty_interpolation.rb +0 -4
  39. data/lib/rubocop/cop/lint/empty_when.rb +0 -2
  40. data/lib/rubocop/cop/lint/ensure_return.rb +1 -6
  41. data/lib/rubocop/cop/lint/float_out_of_range.rb +0 -4
  42. data/lib/rubocop/cop/lint/format_parameter_mismatch.rb +0 -10
  43. data/lib/rubocop/cop/lint/implicit_string_concatenation.rb +5 -7
  44. data/lib/rubocop/cop/lint/ineffective_access_modifier.rb +0 -7
  45. data/lib/rubocop/cop/lint/interpolation_check.rb +0 -4
  46. data/lib/rubocop/cop/lint/literal_assignment_in_condition.rb +1 -1
  47. data/lib/rubocop/cop/lint/literal_in_interpolation.rb +0 -4
  48. data/lib/rubocop/cop/lint/loop.rb +6 -12
  49. data/lib/rubocop/cop/lint/nested_method_definition.rb +0 -6
  50. data/lib/rubocop/cop/lint/next_without_accumulator.rb +0 -4
  51. data/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb +0 -5
  52. data/lib/rubocop/cop/lint/percent_string_array.rb +0 -4
  53. data/lib/rubocop/cop/lint/percent_symbol_array.rb +0 -4
  54. data/lib/rubocop/cop/lint/rand_one.rb +0 -4
  55. data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +3 -1
  56. data/lib/rubocop/cop/lint/redundant_splat_expansion.rb +1 -1
  57. data/lib/rubocop/cop/lint/redundant_string_coercion.rb +0 -4
  58. data/lib/rubocop/cop/lint/require_parentheses.rb +0 -4
  59. data/lib/rubocop/cop/lint/rescue_exception.rb +0 -4
  60. data/lib/rubocop/cop/lint/return_in_void_context.rb +0 -2
  61. data/lib/rubocop/cop/lint/safe_navigation_chain.rb +0 -4
  62. data/lib/rubocop/cop/lint/shadowing_outer_local_variable.rb +6 -10
  63. data/lib/rubocop/cop/lint/unified_integer.rb +0 -4
  64. data/lib/rubocop/cop/lint/unreachable_code.rb +0 -5
  65. data/lib/rubocop/cop/lint/useless_assignment.rb +19 -16
  66. data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +0 -4
  67. data/lib/rubocop/cop/lint/useless_numeric_operation.rb +77 -0
  68. data/lib/rubocop/cop/lint/useless_setter_call.rb +0 -4
  69. data/lib/rubocop/cop/lint/void.rb +30 -8
  70. data/lib/rubocop/cop/metrics/block_length.rb +6 -5
  71. data/lib/rubocop/cop/metrics/class_length.rb +6 -5
  72. data/lib/rubocop/cop/metrics/method_length.rb +6 -5
  73. data/lib/rubocop/cop/metrics/module_length.rb +6 -5
  74. data/lib/rubocop/cop/mixin/annotation_comment.rb +0 -2
  75. data/lib/rubocop/cop/mixin/frozen_string_literal.rb +19 -9
  76. data/lib/rubocop/cop/mixin/line_length_help.rb +7 -2
  77. data/lib/rubocop/cop/mixin/string_literals_help.rb +12 -0
  78. data/lib/rubocop/cop/naming/accessor_method_name.rb +5 -0
  79. data/lib/rubocop/cop/naming/predicate_name.rb +52 -26
  80. data/lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb +10 -1
  81. data/lib/rubocop/cop/style/alias.rb +1 -1
  82. data/lib/rubocop/cop/style/arguments_forwarding.rb +8 -3
  83. data/lib/rubocop/cop/style/def_with_parentheses.rb +0 -2
  84. data/lib/rubocop/cop/style/each_for_simple_loop.rb +0 -1
  85. data/lib/rubocop/cop/style/empty_else.rb +6 -5
  86. data/lib/rubocop/cop/style/empty_heredoc.rb +1 -14
  87. data/lib/rubocop/cop/style/empty_literal.rb +31 -22
  88. data/lib/rubocop/cop/style/eval_with_location.rb +12 -11
  89. data/lib/rubocop/cop/style/file_read.rb +2 -5
  90. data/lib/rubocop/cop/style/file_write.rb +2 -5
  91. data/lib/rubocop/cop/style/format_string_token.rb +2 -2
  92. data/lib/rubocop/cop/style/global_std_stream.rb +7 -1
  93. data/lib/rubocop/cop/style/guard_clause.rb +2 -0
  94. data/lib/rubocop/cop/style/identical_conditional_branches.rb +1 -1
  95. data/lib/rubocop/cop/style/if_with_boolean_literal_branches.rb +0 -1
  96. data/lib/rubocop/cop/style/if_with_semicolon.rb +45 -6
  97. data/lib/rubocop/cop/style/in_pattern_then.rb +6 -2
  98. data/lib/rubocop/cop/style/invertible_unless_condition.rb +2 -2
  99. data/lib/rubocop/cop/style/magic_comment_format.rb +1 -1
  100. data/lib/rubocop/cop/style/map_into_array.rb +12 -5
  101. data/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +1 -1
  102. data/lib/rubocop/cop/style/method_call_without_args_parentheses.rb +2 -2
  103. data/lib/rubocop/cop/style/missing_else.rb +0 -4
  104. data/lib/rubocop/cop/style/multiline_when_then.rb +0 -4
  105. data/lib/rubocop/cop/style/multiple_comparison.rb +3 -11
  106. data/lib/rubocop/cop/style/numeric_predicate.rb +2 -2
  107. data/lib/rubocop/cop/style/one_line_conditional.rb +1 -1
  108. data/lib/rubocop/cop/style/parallel_assignment.rb +5 -4
  109. data/lib/rubocop/cop/style/quoted_symbols.rb +0 -2
  110. data/lib/rubocop/cop/style/redundant_condition.rb +3 -3
  111. data/lib/rubocop/cop/style/redundant_interpolation_unfreeze.rb +46 -0
  112. data/lib/rubocop/cop/style/redundant_regexp_argument.rb +4 -1
  113. data/lib/rubocop/cop/style/redundant_regexp_escape.rb +8 -24
  114. data/lib/rubocop/cop/style/safe_navigation.rb +2 -2
  115. data/lib/rubocop/cop/style/sole_nested_conditional.rb +21 -2
  116. data/lib/rubocop/cop/style/while_until_do.rb +0 -2
  117. data/lib/rubocop/cop/style/while_until_modifier.rb +0 -1
  118. data/lib/rubocop/cop/style/zero_length_predicate.rb +5 -1
  119. data/lib/rubocop/cop/team.rb +6 -2
  120. data/lib/rubocop/cop/variable_force.rb +13 -1
  121. data/lib/rubocop/core_ext/string.rb +2 -6
  122. data/lib/rubocop/ext/regexp_node.rb +9 -31
  123. data/lib/rubocop/formatter/junit_formatter.rb +70 -23
  124. data/lib/rubocop/lockfile.rb +6 -4
  125. data/lib/rubocop/options.rb +3 -1
  126. data/lib/rubocop/remote_config.rb +5 -1
  127. data/lib/rubocop/result_cache.rb +2 -8
  128. data/lib/rubocop/rspec/shared_contexts.rb +2 -2
  129. data/lib/rubocop/server/cache.rb +1 -1
  130. data/lib/rubocop/target_ruby.rb +7 -3
  131. data/lib/rubocop/version.rb +1 -1
  132. data/lib/rubocop/yaml_duplication_checker.rb +1 -0
  133. data/lib/rubocop.rb +7 -1
  134. metadata +8 -26
@@ -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
@@ -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
- newline_pos = end_pos + 1 if newline_pos > node.source_range.begin_pos
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 || last_rescue_and_end_on_same_line(body)
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 last_rescue_and_end_on_same_line(body)
97
- body.rescue_type? && body.resbody_branches.last.loc.line == body.parent.loc.end.line
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
- # * `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`
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,
@@ -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
@@ -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.
@@ -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
- add_offense(node, message: format(MSG, keyword: node.keyword)) do |corrector|
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
- corrector.remove(branch_range(node))
99
- else
100
- corrector.remove(deletion_range(branch_range(node)))
101
- end
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
@@ -8,13 +8,9 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # "result is #{}"
13
12
  #
14
- # @example
15
- #
16
13
  # # good
17
- #
18
14
  # "result is #{some_result}"
19
15
  class EmptyInterpolation < Base
20
16
  include Interpolation
@@ -14,8 +14,6 @@ module RuboCop
14
14
  # when baz
15
15
  # end
16
16
  #
17
- # @example
18
- #
19
17
  # # good
20
18
  # case condition
21
19
  # when foo
@@ -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
- # # also good
36
- #
31
+ # # good
37
32
  # def foo
38
33
  # begin
39
34
  # do_something
@@ -10,13 +10,9 @@ module RuboCop
10
10
  # @example
11
11
  #
12
12
  # # bad
13
- #
14
13
  # float = 3.0e400
15
14
  #
16
- # @example
17
- #
18
15
  # # good
19
- #
20
16
  # float = 42.9
21
17
  class FloatOutOfRange < Base
22
18
  MSG = 'Float out of range.'
@@ -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
- preferred = "#{lhs_node.source} + #{rhs_node.source}"
43
+ range = lhs_node.source_range.end.join(rhs_node.source_range.begin)
48
44
 
49
- corrector.replace(range, preferred)
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? || (node.dstr_type? && node.children.all? { |c| string_literal?(c) })
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
@@ -54,7 +54,7 @@ module RuboCop
54
54
  private
55
55
 
56
56
  def traverse_node(node, &block)
57
- yield node if AST::Node::EQUALS_ASSIGNMENTS.include?(node.type)
57
+ yield node if node.equals_asgn?
58
58
 
59
59
  node.each_child_node { |child| traverse_node(child, &block) }
60
60
  end
@@ -8,13 +8,9 @@ module RuboCop
8
8
  # @example
9
9
  #
10
10
  # # bad
11
- #
12
11
  # "result is #{10}"
13
12
  #
14
- # @example
15
- #
16
13
  # # good
17
- #
18
14
  # "result is 10"
19
15
  class LiteralInInterpolation < Base
20
16
  include Interpolation
@@ -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
- # @example
30
+ # # bad
31
+ #
32
+ # # using until
33
+ # begin
34
+ # do_something
35
+ # end until some_condition
42
36
  #
43
37
  # # good
44
38
  #