2017-10-26 16:46:58 +00:00
|
|
|
require "./ameba/*"
|
2017-10-26 17:47:42 +00:00
|
|
|
require "./ameba/rule/*"
|
2017-10-26 16:46:58 +00:00
|
|
|
|
|
|
|
module Ameba
|
2017-10-26 17:47:42 +00:00
|
|
|
extend self
|
|
|
|
|
|
|
|
RULES = [
|
|
|
|
Rule::LineLength,
|
|
|
|
]
|
|
|
|
|
2017-10-26 19:45:48 +00:00
|
|
|
def run(formatter = DotFormatter.new)
|
|
|
|
run Dir["**/*.cr"], formatter
|
2017-10-26 17:47:42 +00:00
|
|
|
end
|
|
|
|
|
2017-10-26 19:45:48 +00:00
|
|
|
def run(files, formatter : Formatter)
|
2017-10-26 21:01:23 +00:00
|
|
|
sources = files.map { |path| Source.new(path) }
|
2017-10-26 19:45:48 +00:00
|
|
|
|
|
|
|
reporter = Reporter.new formatter
|
|
|
|
reporter.start sources
|
|
|
|
sources.each do |source|
|
|
|
|
catch(source)
|
|
|
|
reporter.report source
|
2017-10-26 17:47:42 +00:00
|
|
|
end
|
2017-10-26 19:45:48 +00:00
|
|
|
reporter.try &.finish sources
|
2017-10-26 17:47:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def catch(source : Source)
|
|
|
|
RULES.each do |rule|
|
|
|
|
rule.new.test(source)
|
|
|
|
end
|
|
|
|
end
|
2017-10-26 16:46:58 +00:00
|
|
|
end
|