lib/rubocop/cop/style/method_def_parentheses.rb in rubocop-0.89.0 vs lib/rubocop/cop/style/method_def_parentheses.rb in rubocop-0.89.1
- old
+ new
@@ -82,13 +82,14 @@
# def foo(descriptive_var_name,
# another_descriptive_var_name,
# last_descriptive_var_name)
# do_something
# end
- class MethodDefParentheses < Cop
+ class MethodDefParentheses < Base
include ConfigurableEnforcedStyle
include RangeHelp
+ extend AutoCorrector
MSG_PRESENT = 'Use def without parentheses.'
MSG_MISSING = 'Use def with parentheses when there are ' \
'parameters.'
@@ -107,21 +108,10 @@
correct_style_detected
end
end
alias on_defs on_def
- def autocorrect(node)
- lambda do |corrector|
- if node.args_type?
- # offense is registered on args node when parentheses are unwanted
- correct_arguments(node, corrector)
- else
- correct_definition(node, corrector)
- end
- end
- end
-
private
def correct_arguments(arg_node, corrector)
corrector.replace(arg_node.loc.begin, ' ')
corrector.remove(arg_node.loc.end)
@@ -148,17 +138,22 @@
end
def missing_parentheses(node)
location = node.arguments.source_range
- add_offense(node, location: location, message: MSG_MISSING) do
- unexpected_style_detected(:require_no_parentheses)
+ return unless unexpected_style_detected(:require_no_parentheses)
+
+ add_offense(location, message: MSG_MISSING) do |corrector|
+ correct_definition(node, corrector)
end
end
def unwanted_parentheses(args)
- add_offense(args, message: MSG_PRESENT) do
- unexpected_style_detected(:require_parentheses)
+ return unless unexpected_style_detected(:require_parentheses)
+
+ add_offense(args, message: MSG_PRESENT) do |corrector|
+ # offense is registered on args node when parentheses are unwanted
+ correct_arguments(args, corrector)
end
end
end
end
end