lib/rubocop/cop/style/method_def_parentheses.rb in rubocop-1.6.1 vs lib/rubocop/cop/style/method_def_parentheses.rb in rubocop-1.7.0
- old
+ new
@@ -4,10 +4,13 @@
module Cop
module Style
# This cop checks for parentheses around the arguments in method
# definitions. Both instance and class/singleton methods are checked.
#
+ # This cop does not consider endless methods, since parentheses are
+ # always required for them.
+ #
# @example EnforcedStyle: require_parentheses (default)
# # The `require_parentheses` style requires method definitions
# # to always use parentheses
#
# # bad
@@ -92,10 +95,12 @@
MSG_PRESENT = 'Use def without parentheses.'
MSG_MISSING = 'Use def with parentheses when there are ' \
'parameters.'
def on_def(node)
+ return if node.endless?
+
args = node.arguments
if require_parentheses?(args)
if arguments_without_parentheses?(node)
missing_parentheses(node)
@@ -140,16 +145,18 @@
def missing_parentheses(node)
location = node.arguments.source_range
add_offense(location, message: MSG_MISSING) do |corrector|
correct_definition(node, corrector)
+ unexpected_style_detected 'require_no_parentheses'
end
end
def unwanted_parentheses(args)
add_offense(args, message: MSG_PRESENT) do |corrector|
# offense is registered on args node when parentheses are unwanted
correct_arguments(args, corrector)
+ unexpected_style_detected 'require_parentheses'
end
end
end
end
end