Skip to content

Instantly share code, notes, and snippets.

@veelenga
Created September 3, 2019 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veelenga/d05eb5a3b346748ed4ba309cf79c73e4 to your computer and use it in GitHub Desktop.
Save veelenga/d05eb5a3b346748ed4ba309cf79c73e4 to your computer and use it in GitHub Desktop.
require "ameba"
source = Ameba::Source.new %(
class Ameba::Internals
getter info : Info
def dump
puts info
end
end
), "source.cr"
module Ameba::Rule
# A rule that disallows calls to `puts` method.
struct NoPuts < Base
def test(source)
AST::NodeVisitor.new self, source
end
def test(source, node : Crystal::Call)
return unless node.name == "puts"
source.add_issue(self, node, "puts method is called")
end
end
end
rule = Ameba::Rule::NoPuts.new
rule.catch(source)
formatter = Ameba::Formatter::JSONFormatter.new(STDOUT)
formatter.started([source])
formatter.source_finished(source)
formatter.finished([source])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment