Class: Rubocop::Cop::Style::DefWithParentheses
- Defined in:
- lib/rubocop/cop/style/def_parentheses.rb
Overview
This cop checks for parentheses in the definition of a method, that does not take any arguments. Both instance and class/singleton methods are checked.
Constant Summary collapse
- MSG =
"Omit the parentheses in defs when the method doesn't accept " + 'any arguments.'
Instance Attribute Summary
Attributes inherited from Cop
#autocorrect, #corrections, #debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, #autocorrect_action, cop_name, cop_type, #do_autocorrect, #ignore_node, inherited, #initialize, lint?, #name, rails?, style?
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#on_def(node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rubocop/cop/style/def_parentheses.rb', line 13 def on_def(node) start_line = node.loc.keyword.line end_line = node.loc.end.line return if start_line == end_line _, args = *node if args.children == [] && args.loc.begin add_offence(:convention, args.loc.begin, MSG) end end |
#on_defs(node) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubocop/cop/style/def_parentheses.rb', line 25 def on_defs(node) start_line = node.loc.keyword.line end_line = node.loc.end.line return if start_line == end_line _, _, args = *node if args.children == [] && args.loc.begin add_offence(:convention, args.loc.begin, MSG) end end |