Class: Pedant::CheckScriptDoesNotUseAuditDotInc

Inherits:
Check
  • Object
show all
Defined in:
lib/pedant/checks/script_missing_audit_inc.rb

Instance Attribute Summary

Attributes inherited from Check

#result

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Check

all, depends, #fail, #fatal, friendly_name, inherited, #initialize, initialize!, list, #pass, provides, ready?, #report, run_checks_in_dependency_order, #skip, #warn

Constructor Details

This class inherits a constructor from Pedant::Check

Class Method Details

.requiresObject



29
30
31
# File 'lib/pedant/checks/script_missing_audit_inc.rb', line 29

def self.requires
  super + [:main, :trees, :codes]
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pedant/checks/script_missing_audit_inc.rb', line 33

def run
  args = []
  tree = @kb[:trees][@kb[:main]]

  tree.all(:Include).each do |node|
    next unless node.filename.text == 'audit.inc'
    report(:info, "#{node.filename.text}")
    args << node
  end # each

  audit_calls = []
  tree.all(:Call).each do |node|
    next unless node.name.ident.name == "audit"
    next if node.args.empty?
    audit_calls << node
  end

  if args.length == 0
    report(:warn, "Plugin does not include audit.inc. Should it?")
    return warn
  elsif args.length == 1
    if audit_calls.length == 0
      report(:warn, "Plugin includes audit.inc but does not make a direct audit call")
      return warn
    end
    pass
  elsif args.length > 1
    report(:error, "Plugin specifies multiple audit.inc:")
    args.each { |call| report(:error, call.context()) }
    return fail
  end

end