lib/rubocop/cop/style/method_def_parentheses.rb in rubocop-0.35.1 vs lib/rubocop/cop/style/method_def_parentheses.rb in rubocop-0.36.0
- old
+ new
@@ -1,6 +1,7 @@
# encoding: utf-8
+# frozen_string_literal: true
module RuboCop
module Cop
module Style
# This cops checks for parentheses around the arguments in method
@@ -30,11 +31,11 @@
if node.args_type?
# offense is registered on args node when parentheses are unwanted
corrector.replace(node.loc.begin, ' ')
corrector.remove(node.loc.end)
else
- args_expr = args_node(node).loc.expression
+ args_expr = args_node(node).source_range
args_with_space = range_with_surrounding_space(args_expr, :left)
just_space = Parser::Source::Range.new(args_expr.source_buffer,
args_with_space.begin_pos,
args_expr.begin_pos)
corrector.replace(just_space, '(')
@@ -44,11 +45,11 @@
end
private
def missing_parentheses(node, args)
- add_offense(node, args.loc.expression,
+ add_offense(node, args.source_range,
'Use def with parentheses when there are parameters.') do
unexpected_style_detected(:require_no_parentheses)
end
end
@@ -59,14 +60,13 @@
end
def args_node(def_node)
if def_node.type == :def
_method_name, args, _body = *def_node
- args
else
_scope, _method_name, args, _body = *def_node
- args
end
+ args
end
def arguments?(args)
args.children.size > 0
end