a static analyzer for C proglam. ▪ In this talk, Lint means a bug detector for any languages. For example: • JavaScript: ESLint • Python: Pylint • Ruby: RuboCop
node.children.each do |child| traverse(child, visitor) if child.is_a?(Parser::AST::Node) end end ▪ Depth-first search. ▪ Call “on_#{node.type}”(e.g. on_send) each node.
cond = node.children.first if cond.type == :int warn "Do not use an int literal in condition!!!" \ " (#{cond.loc.line}:#{cond.loc.column})" end end # TODO def method_missing(*); end end
variable ▪ Many Lint doesn’t trace local variables. • In `var = 1; puts var`. • “var” is just a variable, not an integer. • It is not impossible, but complexity. • For example: Brakeman can trace lvar.
For general cases. • `if 1 ; end` • Like `ruby -cw` ▪ Easy to write. • RuboCop has many helper methods. • AST matcher, extended AST node. • RuboCop provides visitor, config file, etc.
Lint + X; e.g. Lint + Git Diff. • Ruby + X; e.g. Ruby + YAML. ▪ It is out of scope of RuboCop. • You should create a new Lint tool. • Or use tool except RuboCop.