Sha256: 7f4e7bdbb5896b2d35b1d9492a003223810559aef7d1d6398d53ddd5516f8b2a
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
# encoding: utf-8 module Rubocop module Cop class DefWithParentheses < Cop MSG = "Omit the parentheses in defs when the method doesn't accept " + 'any arguments.' 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, node.loc.line, MSG) end super end 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, node.loc.line, MSG) end super end end class DefWithoutParentheses < Cop MSG = 'Use def with parentheses when there are arguments.' 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 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 end end end
Version data entries
4 entries across 4 versions & 1 rubygems