mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Simple reporter
This commit is contained in:
parent
4e84ac871a
commit
ffd44dc77b
2 changed files with 56 additions and 5 deletions
16
src/ameba.cr
16
src/ameba.cr
|
@ -8,14 +8,20 @@ module Ameba
|
||||||
Rule::LineLength,
|
Rule::LineLength,
|
||||||
]
|
]
|
||||||
|
|
||||||
def run
|
def run(formatter = DotFormatter.new)
|
||||||
run Dir["**/*.cr"]
|
run Dir["**/*.cr"], formatter
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(files)
|
def run(files, formatter : Formatter)
|
||||||
files.each do |path|
|
sources = files.map { |path| Source.new(File.read path) }
|
||||||
catch Source.new(File.read path)
|
|
||||||
|
reporter = Reporter.new formatter
|
||||||
|
reporter.start sources
|
||||||
|
sources.each do |source|
|
||||||
|
catch(source)
|
||||||
|
reporter.report source
|
||||||
end
|
end
|
||||||
|
reporter.try &.finish sources
|
||||||
end
|
end
|
||||||
|
|
||||||
def catch(source : Source)
|
def catch(source : Source)
|
||||||
|
|
45
src/ameba/formatter.cr
Normal file
45
src/ameba/formatter.cr
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
module Ameba
|
||||||
|
abstract class Formatter
|
||||||
|
abstract def before(sources)
|
||||||
|
abstract def format(source : Source)
|
||||||
|
abstract def after(sources)
|
||||||
|
end
|
||||||
|
|
||||||
|
class Reporter
|
||||||
|
property formatter : Formatter
|
||||||
|
|
||||||
|
def initialize(@formatter : Formatter)
|
||||||
|
end
|
||||||
|
|
||||||
|
def start(sources)
|
||||||
|
puts formatter.before sources
|
||||||
|
end
|
||||||
|
|
||||||
|
def report(source)
|
||||||
|
print formatter.format source
|
||||||
|
end
|
||||||
|
|
||||||
|
def finish(sources)
|
||||||
|
puts
|
||||||
|
puts formatter.after sources
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class DotFormatter < Formatter
|
||||||
|
def before(sources)
|
||||||
|
if (len = sources.size) == 1
|
||||||
|
"Inspecting 1 file."
|
||||||
|
else
|
||||||
|
"Inspecting #{len} files."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def format(source : Source)
|
||||||
|
source.errors.size == 0 ? "." : "F"
|
||||||
|
end
|
||||||
|
|
||||||
|
def after(sources)
|
||||||
|
"Done!"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue