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
@@ -16,11 +16,11 @@ module Rubocop
16
16
 
17
17
  def check(node, *_)
18
18
  length = code_length(node)
19
- if length > max_length
20
- add_offense(node, :keyword, format(message, length,
21
- max_length)) do
22
- self.max = length
23
- end
19
+ return unless length > max_length
20
+
21
+ add_offense(node, :keyword, format(message, length,
22
+ max_length)) do
23
+ self.max = length
24
24
  end
25
25
  end
26
26
 
@@ -11,13 +11,13 @@ module Rubocop
11
11
  # Look at last expression of contents if there's a parenthesis
12
12
  # around condition.
13
13
  condition = condition.children.last while condition.type == :begin
14
+ return unless condition.type == :send
14
15
 
15
- if condition.type == :send
16
- _object, method = *condition
17
- if method == :! && !(node.loc.respond_to?(:else) && node.loc.else)
18
- add_offense(node, :expression)
19
- end
20
- end
16
+ _object, method = *condition
17
+ return unless method == :! && !(node.loc.respond_to?(:else) &&
18
+ node.loc.else)
19
+
20
+ add_offense(node, :expression)
21
21
  end
22
22
  end
23
23
  end
@@ -5,9 +5,8 @@ module Rubocop
5
5
  # Common functionality for handling percent literals.
6
6
  module PercentLiteral
7
7
  def percent_literal?(node)
8
- if (begin_source = begin_source(node))
9
- begin_source.start_with?('%')
10
- end
8
+ return unless (begin_source = begin_source(node))
9
+ begin_source.start_with?('%')
11
10
  end
12
11
 
13
12
  def process(node, *types)
@@ -9,11 +9,11 @@ module Rubocop
9
9
 
10
10
  def investigate(processed_source)
11
11
  processed_source.tokens.each_cons(2) do |t1, t2|
12
- if kind(t1) && t1.pos.line == t2.pos.line &&
13
- t2.pos.column == t1.pos.column + offset &&
14
- ![:tRPAREN, :tRBRACK].include?(t2.type)
15
- add_offense(t1, t1.pos, format(MSG, kind(t1)))
16
- end
12
+ next unless kind(t1) && t1.pos.line == t2.pos.line &&
13
+ t2.pos.column == t1.pos.column + offset &&
14
+ ![:tRPAREN, :tRBRACK].include?(t2.type)
15
+
16
+ add_offense(t1, t1.pos, format(MSG, kind(t1)))
17
17
  end
18
18
  end
19
19
 
@@ -12,18 +12,17 @@ module Rubocop
12
12
  @processed_source = processed_source
13
13
  left, right, kind = specifics
14
14
  processed_source.tokens.each_cons(2) do |t1, t2|
15
- if t1.type == left || t2.type == right
16
- # If the second token is a comment, that means that a line break
17
- # follows, and that the rules for space inside don't apply.
18
- next if t2.type == :tCOMMENT
15
+ next unless t1.type == left || t2.type == right
19
16
 
20
- if t2.pos.line == t1.pos.line && space_between?(t1, t2)
21
- range = Parser::Source::Range.new(processed_source.buffer,
22
- t1.pos.end_pos,
23
- t2.pos.begin_pos)
24
- add_offense(range, range, format(MSG, kind))
25
- end
26
- end
17
+ # If the second token is a comment, that means that a line break
18
+ # follows, and that the rules for space inside don't apply.
19
+ next if t2.type == :tCOMMENT
20
+ next unless t2.pos.line == t1.pos.line && space_between?(t1, t2)
21
+
22
+ range = Parser::Source::Range.new(processed_source.buffer,
23
+ t1.pos.end_pos,
24
+ t2.pos.begin_pos)
25
+ add_offense(range, range, format(MSG, kind))
27
26
  end
28
27
  end
29
28
 
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module Rubocop
4
+ module Cop
5
+ module Lint
6
+ # Common functionality for cops handling unused arguments.
7
+ module UnusedArgument
8
+ def join_force?(force_class)
9
+ force_class == VariableForce
10
+ end
11
+
12
+ def autocorrect(node)
13
+ new_name = node.loc.expression.source.sub(/(\W?)(\w+)/, '\\1_\\2')
14
+ @corrections << lambda do |corrector|
15
+ corrector.replace(node.loc.expression, new_name)
16
+ end
17
+ end
18
+
19
+ def after_leaving_scope(scope, _variable_table)
20
+ scope.variables.each_value do |variable|
21
+ check_argument(variable)
22
+ end
23
+ end
24
+
25
+ def check_argument(variable)
26
+ return if variable.name.to_s.start_with?('_')
27
+ return if variable.referenced?
28
+
29
+ message = message(variable)
30
+ add_offense(variable.declaration_node, :name, message)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -32,7 +32,7 @@ module Rubocop
32
32
  # human-readable message
33
33
  #
34
34
  # @example
35
- # 'Line is too long. [90/79]'
35
+ # 'Line is too long. [90/80]'
36
36
  attr_reader :message
37
37
 
38
38
  # @api public
@@ -41,15 +41,13 @@ module Rubocop
41
41
 
42
42
  def check_method_node(node)
43
43
  _receiver, method_name, *_args = *node
44
+ return unless offending_method?(method_name)
44
45
 
45
- if offending_method?(method_name)
46
- add_offense(
47
- node, :selector,
48
- format(MSG,
49
- preferred_method(method_name),
50
- method_name)
51
- )
52
- end
46
+ add_offense(node, :selector,
47
+ format(MSG,
48
+ preferred_method(method_name),
49
+ method_name)
50
+ )
53
51
  end
54
52
 
55
53
  def offending_method?(method_name)
@@ -20,14 +20,12 @@ module Rubocop
20
20
  return unless command?(:default_scope, node)
21
21
 
22
22
  _receiver, _method_name, *args = *node
23
-
24
23
  return unless args.size == 1
25
24
 
26
25
  first_arg = args[0]
26
+ return unless first_arg.type != :block || lambda_or_proc?(first_arg)
27
27
 
28
- if first_arg.type != :block || lambda_or_proc?(first_arg)
29
- add_offense(first_arg, :expression)
30
- end
28
+ add_offense(first_arg, :expression)
31
29
  end
32
30
  end
33
31
  end
@@ -65,6 +65,8 @@ module Rubocop
65
65
 
66
66
  def delegate?(body)
67
67
  receiver, * = *body
68
+ return false unless receiver.is_a? Parser::AST::Node
69
+ return false unless receiver.type == :send
68
70
  receiver.children.none? { |n| n.is_a? Parser::AST::Node }
69
71
  end
70
72
 
@@ -8,9 +8,8 @@ module Rubocop
8
8
  MSG = 'Prefer `has_many :through` to `has_and_belongs_to_many`.'
9
9
 
10
10
  def on_send(node)
11
- if command?(:has_and_belongs_to_many, node)
12
- add_offense(node, :selector)
13
- end
11
+ return unless command?(:has_and_belongs_to_many, node)
12
+ add_offense(node, :selector)
14
13
  end
15
14
  end
16
15
  end
@@ -15,10 +15,9 @@ module Rubocop
15
15
 
16
16
  def on_send(node)
17
17
  receiver, method_name, *_args = *node
18
+ return unless receiver.nil? && BLACKLIST.include?(method_name)
18
19
 
19
- if receiver.nil? && BLACKLIST.include?(method_name)
20
- add_offense(node, :selector)
21
- end
20
+ add_offense(node, :selector)
22
21
  end
23
22
  end
24
23
  end
@@ -20,12 +20,11 @@ module Rubocop
20
20
 
21
21
  def on_send(node)
22
22
  receiver, method_name, *_args = *node
23
-
24
23
  return if receiver
24
+ return unless [:read_attribute,
25
+ :write_attribute].include?(method_name)
25
26
 
26
- if [:read_attribute, :write_attribute].include?(method_name)
27
- add_offense(node, :selector)
28
- end
27
+ add_offense(node, :selector)
29
28
  end
30
29
 
31
30
  def message(node)
@@ -20,10 +20,9 @@ module Rubocop
20
20
 
21
21
  def on_send(node)
22
22
  receiver, method_name, *_args = *node
23
+ return unless receiver.nil? && BLACKLIST.include?(method_name)
23
24
 
24
- if receiver.nil? && BLACKLIST.include?(method_name)
25
- add_offense(node, :selector)
26
- end
25
+ add_offense(node, :selector)
27
26
  end
28
27
  end
29
28
  end
@@ -14,9 +14,9 @@ module Rubocop
14
14
 
15
15
  # using alias is the only option in certain scenarios
16
16
  # in such scenarios we don't want to report an offense
17
- if method_name == :instance_exec
18
- on_node(:alias, body) { |n| ignore_node(n) }
19
- end
17
+ return unless method_name == :instance_exec
18
+
19
+ on_node(:alias, body) { |n| ignore_node(n) }
20
20
  end
21
21
 
22
22
  def on_alias(node)
@@ -147,10 +147,10 @@ module Rubocop
147
147
  'one line.'
148
148
 
149
149
  def on_send(node)
150
- if (last_child = node.children.last) && hash?(last_child) &&
151
- ignore_last_argument_hash?(last_child)
152
- ignore_node(last_child)
153
- end
150
+ return unless (last_child = node.children.last) &&
151
+ hash?(last_child) && ignore_last_argument_hash?(last_child)
152
+
153
+ ignore_node(last_child)
154
154
  end
155
155
 
156
156
  def on_hash(node)
@@ -28,11 +28,23 @@ module Rubocop
28
28
 
29
29
  def base_column(node, args)
30
30
  if fixed_indentation?
31
- node.loc.column + 2
31
+ lineno = target_method_lineno(node)
32
+ line = node.loc.expression.source_buffer.source_line(lineno)
33
+ indentation_of_line = /\S.*/.match(line).begin(0)
34
+ indentation_of_line + 2
32
35
  else
33
36
  args.first.loc.column
34
37
  end
35
38
  end
39
+
40
+ def target_method_lineno(node)
41
+ if node.loc.selector
42
+ node.loc.selector.line
43
+ else
44
+ # l.(1) has no selector, so we use the opening parenthesis instead
45
+ node.loc.begin.line
46
+ end
47
+ end
36
48
  end
37
49
  end
38
50
  end
@@ -24,12 +24,9 @@ module Rubocop
24
24
  def process_logical_op(node)
25
25
  op = node.loc.operator.source
26
26
  op_type = node.type.to_s
27
+ return unless op == op_type
27
28
 
28
- if op == op_type
29
- add_offense(node,
30
- :operator,
31
- format(MSG, OPS[op], op))
32
- end
29
+ add_offense(node, :operator, format(MSG, OPS[op], op))
33
30
  end
34
31
 
35
32
  def correction(node)
@@ -13,11 +13,10 @@ module Rubocop
13
13
 
14
14
  def on_send(node)
15
15
  receiver_node, method_name, *arg_nodes = *node
16
+ return unless receiver_node && receiver_node.type == :array &&
17
+ method_name == :* && arg_nodes[0].type == :str
16
18
 
17
- if receiver_node && receiver_node.type == :array &&
18
- method_name == :* && arg_nodes[0].type == :str
19
- add_offense(node, :selector)
20
- end
19
+ add_offense(node, :selector)
21
20
  end
22
21
  end
23
22
  end
@@ -9,9 +9,8 @@ module Rubocop
9
9
 
10
10
  def investigate(processed_source)
11
11
  processed_source.tokens.each do |t|
12
- if t.type == :tIDENTIFIER && !t.text.ascii_only?
13
- add_offense(nil, t.pos)
14
- end
12
+ next unless t.type == :tIDENTIFIER && !t.text.ascii_only?
13
+ add_offense(nil, t.pos)
15
14
  end
16
15
  end
17
16
  end
@@ -9,9 +9,8 @@ module Rubocop
9
9
 
10
10
  def investigate(processed_source)
11
11
  processed_source.comments.each do |comment|
12
- if comment.text.start_with?('=begin')
13
- add_offense(comment, :expression)
14
- end
12
+ next unless comment.text.start_with?('=begin')
13
+ add_offense(comment, :expression)
15
14
  end
16
15
  end
17
16
  end
@@ -40,9 +40,8 @@ module Rubocop
40
40
  end
41
41
  end
42
42
  node.children.each do |child|
43
- if child.is_a?(Parser::AST::Node)
44
- check_nesting_level(child, max, current_level)
45
- end
43
+ next unless child.is_a?(Parser::AST::Node)
44
+ check_nesting_level(child, max, current_level)
46
45
  end
47
46
  end
48
47
 
@@ -13,15 +13,15 @@ module Rubocop
13
13
 
14
14
  def on_send(node)
15
15
  _receiver, method_name, *args = *node
16
- if args.any?
17
- block = get_block(args.last)
18
- if block && !parentheses?(node) && !operator?(method_name)
19
- # If there are no parentheses around the arguments, then braces
20
- # and do-end have different meaning due to how they bind, so we
21
- # allow either.
22
- ignore_node(block)
23
- end
24
- end
16
+ return unless args.any?
17
+
18
+ block = get_block(args.last)
19
+ return unless block && !parentheses?(node) && !operator?(method_name)
20
+
21
+ # If there are no parentheses around the arguments, then braces and
22
+ # do-end have different meaning due to how they bind, so we allow
23
+ # either.
24
+ ignore_node(block)
25
25
  end
26
26
 
27
27
  def on_block(node)
@@ -63,11 +63,11 @@ module Rubocop
63
63
  Parser::Source::Range.new(sb, pos_after_last_pair,
64
64
  node.loc.end.begin_pos)
65
65
  trailing_comma_offset = range_after_last_pair.source =~ /,/
66
- if trailing_comma_offset
67
- comma_begin = pos_after_last_pair + trailing_comma_offset
68
- corrector.remove(Parser::Source::Range.new(sb, comma_begin,
69
- comma_begin + 1))
70
- end
66
+ return unless trailing_comma_offset
67
+
68
+ comma_begin = pos_after_last_pair + trailing_comma_offset
69
+ corrector.remove(Parser::Source::Range.new(sb, comma_begin,
70
+ comma_begin + 1))
71
71
  end
72
72
 
73
73
  def non_empty_hash?(arg)
@@ -57,7 +57,7 @@ module Rubocop
57
57
  end
58
58
 
59
59
  def one_child?(body)
60
- body && body.type != :begin
60
+ body && [:module, :class].include?(body.type)
61
61
  end
62
62
 
63
63
  def compact_node_name?(node)
@@ -33,12 +33,10 @@ module Rubocop
33
33
 
34
34
  def check_defs(node)
35
35
  definee, method_name, _args, _body = *node
36
+ return unless definee.type == :const
36
37
 
37
- if definee.type == :const
38
- _, class_name = *definee
39
- add_offense(definee, :name,
40
- message(class_name, method_name))
41
- end
38
+ _, class_name = *definee
39
+ add_offense(definee, :name, message(class_name, method_name))
42
40
  end
43
41
 
44
42
  def message(class_name, method_name)