Class: Rubocop::Cop::DefWithoutParentheses

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/def_parentheses.rb

Constant Summary collapse

MSG =
'Use def with parentheses when there are arguments.'

Instance Attribute Summary

Attributes inherited from Cop

#debug, #disabled_lines, #offences

Instance Method Summary collapse

Methods inherited from Cop

#add_offence, cop_name, #has_report?, #ignore_node, inherited, #initialize, #inspect, #name, #on_comment

Constructor Details

This class inherits a constructor from Rubocop::Cop::Cop

Instance Method Details

#on_def(node) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/rubocop/cop/def_parentheses.rb', line 41

def on_def(node)
  _, args = *node

  if args.children.size > 0 && args.loc.begin.nil?
    add_offence(:convention, node.loc.line, MSG)
  end

  super
end

#on_defs(node) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/rubocop/cop/def_parentheses.rb', line 51

def on_defs(node)
  _, _, args = *node

  if args.children.size > 0 && args.loc.begin.nil?
    add_offence(:convention, node.loc.line, MSG)
  end

  super
end