class RuboCop::Cop::Style::OptionHash

Checks for options hashes and discourages them if the current Ruby version supports keyword arguments.

@example

# bad
def fry(options = {})
  temperature = options.fetch(:temperature, 300)
  # ...
end

# good
def fry(temperature: 300)
  # ...
end

Constants

MSG

Public Instance Methods

on_args(node) click to toggle source
# File lib/rubocop/cop/style/option_hash.rb, line 30
def on_args(node)
  return if super_used?(node)
  return if allowlist.include?(node.parent.method_name.to_s)

  option_hash(node) { |options| add_offense(options) }
end

Private Instance Methods

allowlist() click to toggle source
# File lib/rubocop/cop/style/option_hash.rb, line 39
def allowlist
  cop_config['Allowlist'] || []
end
super_used?(node) click to toggle source
# File lib/rubocop/cop/style/option_hash.rb, line 48
def super_used?(node)
  node.parent.each_node(:zsuper).any?
end
suspicious_name?(arg_name) click to toggle source
# File lib/rubocop/cop/style/option_hash.rb, line 43
def suspicious_name?(arg_name)
  cop_config.key?('SuspiciousParamNames') &&
    cop_config['SuspiciousParamNames'].include?(arg_name.to_s)
end