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
use crate::enums::report_format::ReportFormat;
use luaur_ast::records::location::Location;
pub fn report(format: ReportFormat, name: &str, loc: &Location, r#type: &str, message: &str) {
match format {
ReportFormat::Default => {
eprintln!(
"{}({},{}): {}: {}",
name,
loc.begin.line + 1,
loc.begin.column + 1,
r#type,
message
);
}
ReportFormat::Luacheck => {
// Note: luacheck's end column is inclusive but our end column is exclusive
// In addition, luacheck doesn't support multi-line messages, so if the error is multiline we'll fake end column as 100 and hope for the best
let column_end = if loc.begin.line == loc.end.line {
loc.end.column
} else {
100
};
// Use stdout to match luacheck behavior
println!(
"{}:{}:{}-{}: (W0) {}: {}",
name,
loc.begin.line + 1,
loc.begin.column + 1,
column_end,
r#type,
message
);
}
ReportFormat::Gnu => {
// Note: GNU end column is inclusive but our end column is exclusive
eprintln!(
"{}:{}.{}-{}.{}: {}: {}",
name,
loc.begin.line + 1,
loc.begin.column + 1,
loc.end.line + 1,
loc.end.column,
r#type,
message
);
}
}
}