rubocop 0.21.0 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubocop might be problematic. Click here for more details.

Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/{rubocop-todo.yml → .rubocop_todo.yml} +5 -5
  4. data/CHANGELOG.md +41 -0
  5. data/README.md +21 -11
  6. data/config/default.yml +33 -10
  7. data/config/disabled.yml +0 -4
  8. data/config/enabled.yml +27 -1
  9. data/lib/rubocop.rb +17 -1
  10. data/lib/rubocop/config.rb +32 -27
  11. data/lib/rubocop/config_loader.rb +21 -8
  12. data/lib/rubocop/cop/cop.rb +8 -8
  13. data/lib/rubocop/cop/lint/block_alignment.rb +22 -22
  14. data/lib/rubocop/cop/lint/condition_position.rb +3 -5
  15. data/lib/rubocop/cop/lint/debugger.rb +4 -5
  16. data/lib/rubocop/cop/lint/end_alignment.rb +11 -10
  17. data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +10 -11
  18. data/lib/rubocop/cop/lint/require_parentheses.rb +7 -7
  19. data/lib/rubocop/cop/lint/rescue_exception.rb +3 -3
  20. data/lib/rubocop/cop/lint/string_conversion_in_interpolation.rb +6 -7
  21. data/lib/rubocop/cop/lint/unreachable_code.rb +2 -3
  22. data/lib/rubocop/cop/lint/unused_block_argument.rb +2 -15
  23. data/lib/rubocop/cop/lint/unused_method_argument.rb +2 -14
  24. data/lib/rubocop/cop/lint/useless_comparison.rb +4 -5
  25. data/lib/rubocop/cop/lint/void.rb +6 -8
  26. data/lib/rubocop/cop/mixin/autocorrect_alignment.rb +4 -2
  27. data/lib/rubocop/cop/mixin/autocorrect_unless_changing_ast.rb +1 -3
  28. data/lib/rubocop/cop/mixin/code_length.rb +5 -5
  29. data/lib/rubocop/cop/mixin/negative_conditional.rb +6 -6
  30. data/lib/rubocop/cop/mixin/percent_literal.rb +2 -3
  31. data/lib/rubocop/cop/mixin/space_after_punctuation.rb +5 -5
  32. data/lib/rubocop/cop/mixin/space_inside.rb +10 -11
  33. data/lib/rubocop/cop/mixin/unused_argument.rb +35 -0
  34. data/lib/rubocop/cop/offense.rb +1 -1
  35. data/lib/rubocop/cop/rails/action_filter.rb +6 -8
  36. data/lib/rubocop/cop/rails/default_scope.rb +2 -4
  37. data/lib/rubocop/cop/rails/delegate.rb +2 -0
  38. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +2 -3
  39. data/lib/rubocop/cop/rails/output.rb +2 -3
  40. data/lib/rubocop/cop/rails/read_write_attribute.rb +3 -4
  41. data/lib/rubocop/cop/rails/validation.rb +2 -3
  42. data/lib/rubocop/cop/style/alias.rb +3 -3
  43. data/lib/rubocop/cop/style/align_hash.rb +4 -4
  44. data/lib/rubocop/cop/style/align_parameters.rb +13 -1
  45. data/lib/rubocop/cop/style/and_or.rb +2 -5
  46. data/lib/rubocop/cop/style/array_join.rb +3 -4
  47. data/lib/rubocop/cop/style/ascii_identifiers.rb +2 -3
  48. data/lib/rubocop/cop/style/block_comments.rb +2 -3
  49. data/lib/rubocop/cop/style/block_nesting.rb +2 -3
  50. data/lib/rubocop/cop/style/blocks.rb +9 -9
  51. data/lib/rubocop/cop/style/braces_around_hash_parameters.rb +5 -5
  52. data/lib/rubocop/cop/style/class_and_module_children.rb +1 -1
  53. data/lib/rubocop/cop/style/class_methods.rb +3 -5
  54. data/lib/rubocop/cop/style/collection_methods.rb +8 -11
  55. data/lib/rubocop/cop/style/comment_annotation.rb +9 -9
  56. data/lib/rubocop/cop/style/comment_indentation.rb +66 -0
  57. data/lib/rubocop/cop/style/constant_name.rb +3 -3
  58. data/lib/rubocop/cop/style/cyclomatic_complexity.rb +5 -5
  59. data/lib/rubocop/cop/style/deprecated_hash_methods.rb +6 -6
  60. data/lib/rubocop/cop/style/each_with_object.rb +38 -0
  61. data/lib/rubocop/cop/style/empty_lines.rb +8 -8
  62. data/lib/rubocop/cop/style/empty_lines_around_body.rb +7 -7
  63. data/lib/rubocop/cop/style/encoding.rb +6 -7
  64. data/lib/rubocop/cop/style/end_of_line.rb +10 -10
  65. data/lib/rubocop/cop/style/file_name.rb +11 -7
  66. data/lib/rubocop/cop/style/guard_clause.rb +32 -22
  67. data/lib/rubocop/cop/style/indentation_width.rb +25 -26
  68. data/lib/rubocop/cop/style/lambda.rb +8 -9
  69. data/lib/rubocop/cop/style/leading_comment_space.rb +4 -5
  70. data/lib/rubocop/cop/style/line_end_concatenation.rb +29 -6
  71. data/lib/rubocop/cop/style/line_length.rb +9 -9
  72. data/lib/rubocop/cop/style/method_called_on_do_end_block.rb +7 -6
  73. data/lib/rubocop/cop/style/module_function.rb +3 -4
  74. data/lib/rubocop/cop/style/multiline_if_then.rb +3 -3
  75. data/lib/rubocop/cop/style/negated_if.rb +2 -0
  76. data/lib/rubocop/cop/style/next.rb +80 -0
  77. data/lib/rubocop/cop/style/nil_comparison.rb +2 -3
  78. data/lib/rubocop/cop/style/non_nil_check.rb +15 -3
  79. data/lib/rubocop/cop/style/not.rb +4 -4
  80. data/lib/rubocop/cop/style/numeric_literals.rb +7 -8
  81. data/lib/rubocop/cop/style/op_method.rb +3 -5
  82. data/lib/rubocop/cop/style/parameter_lists.rb +4 -4
  83. data/lib/rubocop/cop/style/parentheses_around_condition.rb +5 -6
  84. data/lib/rubocop/cop/style/percent_literal_delimiters.rb +5 -5
  85. data/lib/rubocop/cop/style/predicate_name.rb +2 -4
  86. data/lib/rubocop/cop/style/redundant_self.rb +11 -12
  87. data/lib/rubocop/cop/style/self_assignment.rb +8 -13
  88. data/lib/rubocop/cop/style/semicolon.rb +16 -19
  89. data/lib/rubocop/cop/style/signal_exception.rb +10 -11
  90. data/lib/rubocop/cop/style/single_line_block_params.rb +2 -3
  91. data/lib/rubocop/cop/style/single_line_methods.rb +3 -4
  92. data/lib/rubocop/cop/style/space_after_colon.rb +9 -9
  93. data/lib/rubocop/cop/style/space_after_control_keyword.rb +3 -3
  94. data/lib/rubocop/cop/style/space_after_method_name.rb +3 -3
  95. data/lib/rubocop/cop/style/space_after_not.rb +3 -4
  96. data/lib/rubocop/cop/style/space_around_operators.rb +5 -4
  97. data/lib/rubocop/cop/style/space_before_comment.rb +29 -0
  98. data/lib/rubocop/cop/style/space_before_modifier_keyword.rb +6 -7
  99. data/lib/rubocop/cop/style/symbol_array.rb +2 -3
  100. data/lib/rubocop/cop/style/tab.rb +8 -8
  101. data/lib/rubocop/cop/style/trailing_blank_lines.rb +10 -10
  102. data/lib/rubocop/cop/style/trailing_whitespace.rb +6 -7
  103. data/lib/rubocop/cop/style/trivial_accessors.rb +3 -4
  104. data/lib/rubocop/cop/style/unless_else.rb +2 -3
  105. data/lib/rubocop/cop/style/unneeded_capital_w.rb +3 -3
  106. data/lib/rubocop/cop/style/unneeded_percent_x.rb +26 -0
  107. data/lib/rubocop/cop/style/when_then.rb +3 -3
  108. data/lib/rubocop/cop/style/while_until_do.rb +3 -6
  109. data/lib/rubocop/cop/style/word_array.rb +8 -7
  110. data/lib/rubocop/cop/team.rb +9 -11
  111. data/lib/rubocop/cop/util.rb +2 -3
  112. data/lib/rubocop/cop/variable_force.rb +2 -3
  113. data/lib/rubocop/cop/variable_force/variable_table.rb +1 -2
  114. data/lib/rubocop/file_inspector.rb +5 -0
  115. data/lib/rubocop/formatter/clang_style_formatter.rb +3 -4
  116. data/lib/rubocop/formatter/disabled_config_formatter.rb +6 -6
  117. data/lib/rubocop/options.rb +14 -11
  118. data/lib/rubocop/target_finder.rb +12 -1
  119. data/lib/rubocop/version.rb +1 -1
  120. data/relnotes/v0.21.0.md +11 -0
  121. data/relnotes/v0.22.0.md +77 -0
  122. data/spec/rubocop/cli_spec.rb +86 -40
  123. data/spec/rubocop/comment_config_spec.rb +1 -1
  124. data/spec/rubocop/config_loader_spec.rb +3 -3
  125. data/spec/rubocop/config_spec.rb +14 -3
  126. data/spec/rubocop/cop/force_spec.rb +1 -1
  127. data/spec/rubocop/cop/lint/unused_block_argument_spec.rb +164 -99
  128. data/spec/rubocop/cop/lint/unused_method_argument_spec.rb +195 -85
  129. data/spec/rubocop/cop/lint/void_spec.rb +8 -0
  130. data/spec/rubocop/cop/rails/delegate_spec.rb +17 -0
  131. data/spec/rubocop/cop/rails/output_spec.rb +3 -3
  132. data/spec/rubocop/cop/severity_spec.rb +5 -5
  133. data/spec/rubocop/cop/style/align_parameters_spec.rb +108 -0
  134. data/spec/rubocop/cop/style/block_nesting_spec.rb +3 -3
  135. data/spec/rubocop/cop/style/class_and_module_children_spec.rb +12 -10
  136. data/spec/rubocop/cop/style/comment_indentation_spec.rb +174 -0
  137. data/spec/rubocop/cop/style/each_with_object_spec.rb +44 -0
  138. data/spec/rubocop/cop/style/end_of_line_spec.rb +3 -5
  139. data/spec/rubocop/cop/style/guard_clause_spec.rb +135 -57
  140. data/spec/rubocop/cop/style/if_unless_modifier_spec.rb +7 -7
  141. data/spec/rubocop/cop/style/line_end_concatenation_spec.rb +75 -1
  142. data/spec/rubocop/cop/style/line_length_spec.rb +7 -7
  143. data/spec/rubocop/cop/style/negated_if_spec.rb +5 -1
  144. data/spec/rubocop/cop/style/next_spec.rb +210 -0
  145. data/spec/rubocop/cop/style/non_nil_check_spec.rb +44 -13
  146. data/spec/rubocop/cop/style/self_assignment_spec.rb +1 -1
  147. data/spec/rubocop/cop/style/space_around_operators_spec.rb +1 -0
  148. data/spec/rubocop/cop/style/space_before_comment_spec.rb +34 -0
  149. data/spec/rubocop/cop/style/unneeded_percent_x_spec.rb +34 -0
  150. data/spec/rubocop/cop/style/while_until_modifier_spec.rb +2 -2
  151. data/spec/rubocop/cop/util_spec.rb +2 -2
  152. data/spec/rubocop/cop/variable_force_spec.rb +1 -1
  153. data/spec/rubocop/formatter/disabled_config_formatter_spec.rb +4 -4
  154. data/spec/rubocop/formatter/disabled_lines_formatter_spec.rb +2 -2
  155. data/spec/rubocop/formatter/offense_count_formatter_spec.rb +2 -2
  156. data/spec/rubocop/options_spec.rb +3 -0
  157. data/spec/support/shared_context.rb +1 -3
  158. data/spec/support/statement_modifier_helper.rb +2 -2
  159. metadata +20 -3
@@ -19,15 +19,14 @@ module Rubocop
19
19
  # ...)
20
20
  block_method, = *node
21
21
 
22
- if block_method == TARGET
23
- selector = block_method.loc.selector.source
24
- lambda_length = lambda_length(node)
25
-
26
- if selector != '->' && lambda_length == 0
27
- add_offense(block_method, :expression, SINGLE_MSG)
28
- elsif selector == '->' && lambda_length > 0
29
- add_offense(block_method, :expression, MULTI_MSG)
30
- end
22
+ return unless block_method == TARGET
23
+ selector = block_method.loc.selector.source
24
+ lambda_length = lambda_length(node)
25
+
26
+ if selector != '->' && lambda_length == 0
27
+ add_offense(block_method, :expression, SINGLE_MSG)
28
+ elsif selector == '->' && lambda_length > 0
29
+ add_offense(block_method, :expression, MULTI_MSG)
31
30
  end
32
31
  end
33
32
 
@@ -12,11 +12,10 @@ module Rubocop
12
12
 
13
13
  def investigate(processed_source)
14
14
  processed_source.comments.each do |comment|
15
- if comment.text =~ /^#+[^#\s:+-]/
16
- unless comment.text.start_with?('#!') && comment.loc.line == 1
17
- add_offense(comment, :expression)
18
- end
19
- end
15
+ next unless comment.text =~ /^#+[^#\s:+-]/
16
+ next if comment.text.start_with?('#!') && comment.loc.line == 1
17
+
18
+ add_offense(comment, :expression)
20
19
  end
21
20
  end
22
21
 
@@ -20,7 +20,7 @@ module Rubocop
20
20
  # 'bala'
21
21
  #
22
22
  class LineEndConcatenation < Cop
23
- MSG = 'Use \\ instead of + or << to concatenate those strings.'
23
+ MSG = 'Use `\\` instead of `+` or `<<` to concatenate those strings.'
24
24
 
25
25
  def on_send(node)
26
26
  add_offense(node, :selector) if offending_node?(node)
@@ -35,15 +35,18 @@ module Rubocop
35
35
 
36
36
  private
37
37
 
38
+ def concat?(method)
39
+ [:+, :<<].include?(method)
40
+ end
41
+
38
42
  def offending_node?(node)
39
- receiver, method, arg = *node
43
+ receiver, method, first_arg = *node
40
44
 
41
- # TODO: Report Emacs bug.
42
- return false unless [:+, :<<].include?(method)
45
+ return false unless concat?(method)
43
46
 
44
- return false unless string_type?(receiver)
47
+ return false unless final_node_is_string_type?(receiver)
45
48
 
46
- return false unless string_type?(arg)
49
+ return false unless root_node_is_string_type?(first_arg)
47
50
 
48
51
  expression = node.loc.expression.source
49
52
  concatenator_at_line_end?(expression)
@@ -56,10 +59,30 @@ module Rubocop
56
59
 
57
60
  def string_type?(node)
58
61
  return false unless [:str, :dstr].include?(node.type)
62
+ # strings like __FILE__ are of no interest
63
+ return false unless node.loc.respond_to?(:begin)
59
64
 
60
65
  # we care only about quotes-delimited literals
61
66
  node.loc.begin && ["'", '"'].include?(node.loc.begin.source)
62
67
  end
68
+
69
+ def final_node_is_string_type?(node)
70
+ if node.type == :send
71
+ _, method, first_arg = *node
72
+ concat?(method) && final_node_is_string_type?(first_arg)
73
+ else
74
+ string_type?(node)
75
+ end
76
+ end
77
+
78
+ def root_node_is_string_type?(node)
79
+ if node.type == :send
80
+ receiver, method, _ = *node
81
+ concat?(method) && root_node_is_string_type?(receiver)
82
+ else
83
+ string_type?(node)
84
+ end
85
+ end
63
86
  end
64
87
  end
65
88
  end
@@ -12,15 +12,15 @@ module Rubocop
12
12
 
13
13
  def investigate(processed_source)
14
14
  processed_source.lines.each_with_index do |line, index|
15
- if line.length > max
16
- message = format(MSG, line.length, max)
17
- add_offense(nil,
18
- source_range(processed_source.buffer,
19
- processed_source[0...index], max,
20
- line.length - max),
21
- message) do
22
- self.max = line.length
23
- end
15
+ next unless line.length > max
16
+
17
+ message = format(MSG, line.length, max)
18
+ add_offense(nil,
19
+ source_range(processed_source.buffer,
20
+ processed_source[0...index], max,
21
+ line.length - max),
22
+ message) do
23
+ self.max = line.length
24
24
  end
25
25
  end
26
26
  end
@@ -28,12 +28,13 @@ module Rubocop
28
28
  def on_send(node)
29
29
  return if ignored_node?(node)
30
30
  receiver, _method_name, *_args = *node
31
- if receiver && receiver.type == :block && receiver.loc.end.is?('end')
32
- range = Parser::Source::Range.new(receiver.loc.end.source_buffer,
33
- receiver.loc.end.begin_pos,
34
- node.loc.expression.end_pos)
35
- add_offense(nil, range)
36
- end
31
+ return unless receiver && receiver.type == :block &&
32
+ receiver.loc.end.is?('end')
33
+
34
+ range = Parser::Source::Range.new(receiver.loc.end.source_buffer,
35
+ receiver.loc.end.begin_pos,
36
+ node.loc.expression.end_pos)
37
+ add_offense(nil, range)
37
38
  end
38
39
  end
39
40
  end
@@ -19,11 +19,10 @@ module Rubocop
19
19
 
20
20
  def on_module(node)
21
21
  _name, body = *node
22
+ return unless body && body.type == :begin
22
23
 
23
- if body && body.type == :begin
24
- body.children.each do |body_node|
25
- add_offense(body_node, :expression) if body_node == TARGET_NODE
26
- end
24
+ body.children.each do |body_node|
25
+ add_offense(body_node, :expression) if body_node == TARGET_NODE
27
26
  end
28
27
  end
29
28
  end
@@ -32,9 +32,9 @@ module Rubocop
32
32
  Parser::Source::Range.new(next_thing.source_buffer,
33
33
  end_position(condition),
34
34
  next_thing.begin_pos)
35
- if right_after_cond.source =~ /\A\s*then\s*(#.*)?\s*\n/
36
- node.loc.expression.begin.line
37
- end
35
+ return unless right_after_cond.source =~ /\A\s*then\s*(#.*)?\s*\n/
36
+
37
+ node.loc.expression.begin.line
38
38
  end
39
39
 
40
40
  def end_position(conditional_node)
@@ -30,6 +30,8 @@ module Rubocop
30
30
  def autocorrect(node)
31
31
  @corrections << lambda do |corrector|
32
32
  condition, _body, _rest = *node
33
+ # look inside parentheses around the condition
34
+ condition = condition.children.first while condition.type == :begin
33
35
  # unwrap the negated portion of the condition (a send node)
34
36
  pos_condition, _method, = *condition
35
37
  corrector.replace(
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+
3
+ module Rubocop
4
+ module Cop
5
+ module Style
6
+ # Use `next` to skip iteration instead of a condition at the end.
7
+ #
8
+ # @example
9
+ # # bad
10
+ # [1, 2].each do |a|
11
+ # if a == 1 do
12
+ # puts a
13
+ # end
14
+ # end
15
+ #
16
+ # # good
17
+ # [1, 2].each do |a|
18
+ # next unless a == 1
19
+ # puts a
20
+ # end
21
+ class Next < Cop
22
+ include IfNode
23
+ include ConfigurableEnforcedStyle
24
+
25
+ MSG = 'Use `next` to skip iteration.'
26
+ METHODS = [:collect, :detect, :downto, :each, :find, :find_all,
27
+ :inject, :loop, :map!, :map, :reduce, :reverse_each,
28
+ :select, :times, :upto]
29
+
30
+ def on_block(node)
31
+ method, _, body = *node
32
+ return if body.nil?
33
+
34
+ _, method_name = *method
35
+ return unless method?(method_name)
36
+ return unless ends_with_condition?(body)
37
+
38
+ add_offense(method, :selector, MSG)
39
+ end
40
+
41
+ def on_while(node)
42
+ _, body = *node
43
+ return unless ends_with_condition?(body)
44
+
45
+ add_offense(node, :keyword, MSG)
46
+ end
47
+ alias_method :on_until, :on_while
48
+
49
+ def on_for(node)
50
+ _, _, body = *node
51
+ return unless ends_with_condition?(body)
52
+
53
+ add_offense(node, :keyword, MSG)
54
+ end
55
+
56
+ private
57
+
58
+ def method?(method_name)
59
+ METHODS.include?(method_name) || /\Aeach_/.match(method_name)
60
+ end
61
+
62
+ def ends_with_condition?(body)
63
+ return true if simple_if_without_break?(body)
64
+
65
+ body.type == :begin && simple_if_without_break?(body.children.last)
66
+ end
67
+
68
+ def simple_if_without_break?(body)
69
+ return false if ternary_op?(body)
70
+ return false if if_else?(body)
71
+ return false unless body.type == :if
72
+ return false if style == :skip_modifier_ifs && modifier_if?(body)
73
+
74
+ _, return_method, return_body = *body
75
+ (return_method || return_body).type != :break
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -21,10 +21,9 @@ module Rubocop
21
21
 
22
22
  def on_send(node)
23
23
  _receiver, method, args = *node
24
+ return unless OPS.include?(method)
24
25
 
25
- if OPS.include?(method)
26
- add_offense(node, :selector) if args == NIL_NODE
27
- end
26
+ add_offense(node, :selector) if args == NIL_NODE
28
27
  end
29
28
 
30
29
  private
@@ -9,9 +9,12 @@ module Rubocop
9
9
  #
10
10
  # # bad
11
11
  # if x != nil
12
+ #
13
+ # # good (when not allowing semantic changes)
14
+ # # bad (when allowing semantic changes)
12
15
  # if !x.nil?
13
16
  #
14
- # # good
17
+ # # good (when allowing semantic changes)
15
18
  # if x
16
19
  #
17
20
  # Non-nil checks are allowed if they are the final nodes of predicate.
@@ -43,13 +46,17 @@ module Rubocop
43
46
 
44
47
  if method == :!=
45
48
  add_offense(node, :selector) if args == NIL_NODE
46
- elsif method == :!
49
+ elsif include_semantic_changes? && method == :!
47
50
  add_offense(node, :expression) if nil_check?(receiver)
48
51
  end
49
52
  end
50
53
 
51
54
  private
52
55
 
56
+ def include_semantic_changes?
57
+ cop_config['IncludeSemanticChanges']
58
+ end
59
+
53
60
  def process_method(name, body)
54
61
  # only predicate methods are handled differently
55
62
  return unless name.to_s.end_with?('?')
@@ -82,7 +89,12 @@ module Rubocop
82
89
  def autocorrect_comparison(node)
83
90
  @corrections << lambda do |corrector|
84
91
  expr = node.loc.expression
85
- new_code = expr.source.sub(/\s*!=\s*nil/, '')
92
+ new_code =
93
+ if include_semantic_changes?
94
+ expr.source.sub(/\s*!=\s*nil/, '')
95
+ else
96
+ expr.source.sub(/^(\S*)\s*!=\s*nil/, '!\1.nil?')
97
+ end
86
98
  corrector.replace(expr, new_code)
87
99
  end
88
100
  end
@@ -13,10 +13,10 @@ module Rubocop
13
13
  _receiver, method_name, *args = *node
14
14
 
15
15
  # not does not take any arguments
16
- if args.empty? && method_name == :! &&
17
- node.loc.selector.is?('not')
18
- add_offense(node, :selector)
19
- end
16
+ return unless args.empty? && method_name == :! &&
17
+ node.loc.selector.is?('not')
18
+
19
+ add_offense(node, :selector)
20
20
  end
21
21
 
22
22
  private
@@ -33,15 +33,14 @@ module Rubocop
33
33
 
34
34
  # TODO: handle non-decimal literals as well
35
35
  return if int.start_with?('0')
36
+ return unless int.size >= min_digits
36
37
 
37
- if int.size >= min_digits
38
- case int
39
- when /^\d+$/
40
- add_offense(node, :expression) { self.max = int.size + 1 }
41
- when /\d{4}/, /_\d{1,2}_/
42
- add_offense(node, :expression) do
43
- self.config_to_allow_offenses = { 'Enabled' => false }
44
- end
38
+ case int
39
+ when /^\d+$/
40
+ add_offense(node, :expression) { self.max = int.size + 1 }
41
+ when /\d{4}/, /_\d{1,2}_/
42
+ add_offense(node, :expression) do
43
+ self.config_to_allow_offenses = { 'Enabled' => false }
45
44
  end
46
45
  end
47
46
  end
@@ -14,12 +14,10 @@ module Rubocop
14
14
 
15
15
  def on_def(node)
16
16
  name, args, _body = *node
17
+ return unless name !~ /\A\w/ && !BLACKLISTED.include?(name) &&
18
+ args.children.size == 1 && !TARGET_ARGS.include?(args)
17
19
 
18
- if name !~ /\A\w/ && !BLACKLISTED.include?(name) &&
19
- args.children.size == 1 && !TARGET_ARGS.include?(args)
20
- add_offense(args.children[0], :expression,
21
- format(MSG, name))
22
- end
20
+ add_offense(args.children[0], :expression, format(MSG, name))
23
21
  end
24
22
  end
25
23
  end
@@ -14,10 +14,10 @@ module Rubocop
14
14
 
15
15
  def on_args(node)
16
16
  count = args_count(node)
17
- if count > max_params
18
- add_offense(node, :expression, format(MSG, max_params)) do
19
- self.max = count
20
- end
17
+ return unless count > max_params
18
+
19
+ add_offense(node, :expression, format(MSG, max_params)) do
20
+ self.max = count
21
21
  end
22
22
  end
23
23
 
@@ -27,13 +27,12 @@ module Rubocop
27
27
  def process_control_op(node)
28
28
  cond, _body = *node
29
29
 
30
- if cond.type == :begin
31
- return if parens_required?(node)
32
- # allow safe assignment
33
- return if safe_assignment?(cond) && safe_assignment_allowed?
30
+ return unless cond.type == :begin
31
+ return if parens_required?(node)
32
+ # allow safe assignment
33
+ return if safe_assignment?(cond) && safe_assignment_allowed?
34
34
 
35
- add_offense(cond, :expression, message(node))
36
- end
35
+ add_offense(cond, :expression, message(node))
37
36
  end
38
37
 
39
38
  def parens_required?(node)
@@ -61,11 +61,11 @@ module Rubocop
61
61
 
62
62
  def on_percent_literal(node, types)
63
63
  type = type(node)
64
- if types.include?(type) &&
65
- !uses_preferred_delimiter?(node, type) &&
66
- !contains_preferred_delimiter?(node, type)
67
- add_offense(node, :expression)
68
- end
64
+ return unless types.include?(type) &&
65
+ !uses_preferred_delimiter?(node, type) &&
66
+ !contains_preferred_delimiter?(node, type)
67
+
68
+ add_offense(node, :expression)
69
69
  end
70
70
 
71
71
  def preferred_delimiters(type)