Class: Ducalis::OptionsArgument

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Defined in:
lib/ducalis/cops/options_argument.rb

Constant Summary collapse

OFFENSE =
"  | Default `options` (or `args`) argument isn't good idea. It's better to explicitly pass which keys are you interested in as keyword arguments. You can use split operator to support hash arguments.\n".gsub(/^ +\|\s/, '').strip
DETAILS =
"  | Compare:\n\n  | ```ruby\n  | def generate_1(document, options = {})\n  |   format = options.delete(:format)\n  |   limit = options.delete(:limit) || 20\n  |   # ...\n  |   [format, limit, options]\n  | end\n\n  | options = { format: 'csv', limit: 5, useless_arg: :value }\n  | generate_1(1, options) #=> [\"csv\", 5, {:useless_arg=>:value}]\n  | generate_1(1, format: 'csv', limit: 5, useless_arg: :value) #=> [\"csv\", 5, {:useless_arg=>:value}]\n\n  | # vs\n\n  | def generate_2(document, format:, limit: 20, **options)\n  |   # ...\n  |   [format, limit, options]\n  | end\n\n  | options = { format: 'csv', limit: 5, useless_arg: :value }\n  | generate_2(1, **options) #=> [\"csv\", 5, {:useless_arg=>:value}]\n  | generate_2(1, format: 'csv', limit: 5, useless_arg: :value) #=> [\"csv\", 5, {:useless_arg=>:value}]\n  | ```\n\n".gsub(/^ +\|\s/, '').strip

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ Object



40
41
42
43
44
# File 'lib/ducalis/cops/options_argument.rb', line 40

def on_def(node)
  return unless options_like_arg?(node)

  add_offense(node, :expression, OFFENSE)
end