Class: RemLint::Rules::FunctionArity

Inherits:
RemLint::Rule show all
Defined in:
lib/remlint/rules/function_arity.rb

Overview

Calls that pass the wrong number of arguments.

The arities come from Remind's own function table (src/funcs.c), so this is not a guess about what ampm accepts -- it is what ampm accepts. defs.rem defines fifteen-odd helpers and calls them throughout, and astro threads sunrise($T+1) through four separate heredocs; getting an argument count wrong there fails at trigger time, on the one day of the year the reminder fires.

Two deliberate silences:

UNKNOWN FUNCTIONS ARE NOT REPORTED. A reminder file's helpers usually arrive through INCLUDE, and this rule reads one file. Complaining about every call into $SysInclude would drown the calls it can actually check.

A FUNCTION DEFINED LATER IN THE FILE STILL COUNTS. Definitions are collected in a first pass, because FSET at the bottom of a file is legal and common. A call is checked against the definition in force where it sits -- the nearest one above it -- and only falls back to a later definition when there is nothing above. Remind's own tests/test.rem defines g(x, y) on line 356 and redefines it as g(x) on line 1545; taking the last definition file-wide would report all three of the perfectly correct two-argument calls in between.

Constant Summary collapse

DEFINITION =

FSET name(a, b) -- the parameter list ends at the first ), since Remind's parameters are plain names.

/\A\s*(?<name>[A-Za-z_]\w*)\s*\((?<params>[^)]*)\)/

Constants inherited from RemLint::Rule

RemLint::Rule::REGISTRY

Instance Attribute Summary

Attributes inherited from RemLint::Rule

#config, #document, #offenses

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RemLint::Rule

all, enabled_by_default?, find, inherited, #initialize, rule_name, #rule_name, #run

Constructor Details

This class inherits a constructor from RemLint::Rule

Class Method Details

.default_severityObject



36
37
38
# File 'lib/remlint/rules/function_arity.rb', line 36

def self.default_severity
  "error"
end

.descriptionObject



40
41
42
# File 'lib/remlint/rules/function_arity.rb', line 40

def self.description
  "Calls that pass more or fewer arguments than the function takes."
end

Instance Method Details

#checkObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/remlint/rules/function_arity.rb', line 44

def check
  @definitions = collect_definitions

  document.logical_lines.each_with_index do |logical_line, index|
    command = document.commands[index]

    if command.code?
      check_calls(logical_line, command)
    end
  end
end