Skip to main content

luaur_analyze_cli/functions/
report.rs

1use crate::enums::report_format::ReportFormat;
2use luaur_ast::records::location::Location;
3
4pub fn report(format: ReportFormat, name: &str, loc: &Location, r#type: &str, message: &str) {
5    match format {
6        ReportFormat::Default => {
7            eprintln!(
8                "{}({},{}): {}: {}",
9                name,
10                loc.begin.line + 1,
11                loc.begin.column + 1,
12                r#type,
13                message
14            );
15        }
16        ReportFormat::Luacheck => {
17            // Note: luacheck's end column is inclusive but our end column is exclusive
18            // 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
19            let column_end = if loc.begin.line == loc.end.line {
20                loc.end.column
21            } else {
22                100
23            };
24
25            // Use stdout to match luacheck behavior
26            println!(
27                "{}:{}:{}-{}: (W0) {}: {}",
28                name,
29                loc.begin.line + 1,
30                loc.begin.column + 1,
31                column_end,
32                r#type,
33                message
34            );
35        }
36        ReportFormat::Gnu => {
37            // Note: GNU end column is inclusive but our end column is exclusive
38            eprintln!(
39                "{}:{}.{}-{}.{}: {}: {}",
40                name,
41                loc.begin.line + 1,
42                loc.begin.column + 1,
43                loc.end.line + 1,
44                loc.end.column,
45                r#type,
46                message
47            );
48        }
49    }
50}