-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathlint.cr
60 lines (52 loc) · 1.45 KB
/
lint.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
module Mint
class Cli < Admiral::Command
class Lint < Admiral::Command
include Command
define_help description: "Lints the project for syntax and type errors."
define_flag json : Bool,
description: "Output errors in a JSON format.",
default: false
def run
ast = Ast.new.merge(Core.ast)
json = MintJson.current
errors = [] of Error
Dir.glob(SourceFiles.globs(json, include_tests: true))
.reduce(ast) do |memo, file|
begin
memo.merge(Parser.parse(file))
rescue error : Error
errors << error
end
memo
end
begin
TypeChecker.new(ast).tap(&.check)
rescue error : Error
errors << error
end if errors.empty?
if errors.empty?
unless flags.json
execute "Linting" do
terminal.puts "No errors detected."
end
end
else
if flags.json
terminal.puts errors.compact_map(&.to_terminal.to_s.uncolorize).to_json
else
if errors.empty?
terminal.puts "No errors were detected!"
else
execute "Linting" do
errors.each do |error|
terminal.print error.to_terminal
end
end
end
end
exit(1)
end
end
end
end
end