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.'
Constants inherited from Cop
Instance Attribute Summary
Attributes inherited from Cop
#config, #corrections, #offences, #processed_source
Instance Method Summary collapse
Methods inherited from Cop
#add_offence, all, #autocorrect?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, rails?, style?, #support_autocorrect?, #warning
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#autocorrect(node) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/rubocop/cop/style/def_parentheses.rb', line 33 def autocorrect(node) @corrections << lambda do |corrector| corrector.remove(node.loc.begin) corrector.remove(node.loc.end) end end |
#on_def(node) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# 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 convention(args, :begin) if args.children == [] && args.loc.begin end |
#on_defs(node) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/rubocop/cop/style/def_parentheses.rb', line 23 def on_defs(node) start_line = node.loc.keyword.line end_line = node.loc.end.line return if start_line == end_line _, _, args = *node convention(args, :begin) if args.children == [] && args.loc.begin end |