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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/milk_tea/tooling/cli/commands/check.rb', line 6
def check_command
args = @argv.dup
@argv = []
until args.empty?
arg = args.shift
@argv << arg
end
unless @argv.any?
@err.puts("missing source file path")
print_usage(@err)
return 1
end
resolution =
input_paths = @argv.dup
return 1 unless ensure_known_source_operands!("check", input_paths)
paths = expand_source_paths(input_paths)
return 0 if print_no_source_files_if_empty(paths, input_paths)
ensure_current_lockfiles!(paths) if resolution[:frozen]
all_diagnostics = []
paths.each do |path|
diagnostics, module_name, closure_errors = check_single_reporting_all(path, locked: resolution[:locked])
closure_errors = [] if paths.length > 1
diagnostics = sort_by_location(diagnostics)
if diagnostics.any? || closure_errors.any?
main_source = read_source_file(path)
main_abs = File.expand_path(path)
diagnostics.each do |d|
same_file = !d.respond_to?(:path) || d.path.nil? || File.expand_path(d.path) == main_abs
source = same_file ? main_source : nil
@err.puts(ErrorFormatter.format(d, source:, color: error_color?(@err)))
end
closure_errors.each do |d|
same_file = !d.respond_to?(:path) || d.path.nil? || File.expand_path(d.path) == main_abs
source = same_file ? main_source : nil
@err.puts(ErrorFormatter.format(d, source:, color: error_color?(@err)))
end
all_diagnostics.concat(diagnostics)
all_diagnostics.concat(closure_errors)
elsif module_name
info("checked #{path} as #{module_name}")
end
end
return 0 if all_diagnostics.empty?
error_count = all_diagnostics.count { |d| !d.respond_to?(:severity) || d.severity == :error }
warning_count = all_diagnostics.count { |d| d.respond_to?(:severity) && d.severity == :warning }
info_count = all_diagnostics.count { |d| d.respond_to?(:severity) && (d.severity == :info || d.severity == :hint) }
@err.puts
parts = []
parts << "#{error_count} #{error_count == 1 ? 'error' : 'errors'}" if error_count > 0
parts << "#{warning_count} #{warning_count == 1 ? 'warning' : 'warnings'}" if warning_count > 0
parts << "#{info_count} #{info_count == 1 ? 'note' : 'notes'}" if info_count > 0
body = parts.join("; ")
if error_count > 0
@err.puts("#{body} found")
elsif warning_count > 0
@err.puts("#{body}")
end
final_error_count = error_count + (resolution[:warnings_as_errors] ? warning_count : 0)
final_error_count > 0 ? 1 : 0
end
|