class Pedant::CheckArityOfBuiltins

Public Class Methods

requires() click to toggle source
Calls superclass method Pedant::Check::requires
# File lib/pedant/checks/arity_of_builtins.rb, line 90
def self.requires
  super + [:trees]
end

Public Instance Methods

check(file, tree) click to toggle source
# File lib/pedant/checks/arity_of_builtins.rb, line 94
def check(file, tree)
  tree.all(:Call).each do |call|
    next unless call.name.indexes == []
    name = call.name.ident.name

    if @@anon_arity_of_one.include? name
      next if call.args.length == 1 and call.args.first.type == :anonymous
      fail
      report(:error, "The builtin function '#{name}' takes a single anonymous argument.")
      # Pick the right thing to highlight.
      if call.args.length == 0
        report(:error, call.context(call))
      elsif call.args.first.type != :anonymous
        report(:error, call.args[0].context(call))
      elsif call.args.length > 1
        report(:error, call.args[1].context(call))
      end
    end

    if name == "make_array"
      next if call.args.length.even?
      fail
      report(:error, "The builtin function 'make_array()' takes an even number of arguments.")
      report(:error, call.context(call))
    end
  end
end
run() click to toggle source
# File lib/pedant/checks/arity_of_builtins.rb, line 122
def run
  # This check will pass by default.
  pass

  # Run this check on the tree from every file.
  @kb[:trees].each { |file, tree| check(file, tree) }
end