Class: Rubocop::Cop::DefWithoutParentheses

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

Constant Summary

Constants included from DefParentheses

Rubocop::Cop::DefParentheses::EMPTY_PARAMS

Instance Attribute Summary

Attributes inherited from Cop

#correlations, #offences

Instance Method Summary collapse

Methods included from DefParentheses

#inspect

Methods inherited from Cop

#add_offence, #has_report?, inherited, #initialize

Constructor Details

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

Instance Method Details

#check(tokens, def_sexp) ⇒ Object



47
48
49
50
51
# File 'lib/rubocop/cop/def_parentheses.rb', line 47

def check(tokens, def_sexp)
  if def_sexp[2][0] == :params && def_sexp[2] != EMPTY_PARAMS
    add_offence(:convention, def_sexp[1][-1].lineno, error_message)
  end
end

#error_messageObject



43
44
45
# File 'lib/rubocop/cop/def_parentheses.rb', line 43

def error_message
  'Use def with parentheses when there are arguments.'
end