rigsql_output/github.rs
1use std::path::Path;
2
3use rigsql_rules::LintViolation;
4
5/// GitHub Actions workflow command formatter.
6///
7/// Outputs violations as `::warning` commands that GitHub Actions
8/// interprets as file annotations visible in pull request diffs.
9///
10/// Format: `::warning file={path},line={line},col={col}::{message}`
11pub struct GithubFormatter;
12
13impl GithubFormatter {
14 pub fn format(file_results: &[(&Path, &str, &[LintViolation])]) -> String {
15 let mut out = String::new();
16
17 for (path, source, violations) in file_results {
18 for v in *violations {
19 let (line, col) = v.line_col(source);
20 out.push_str(&format!(
21 "::warning file={},line={},col={}::{} {}\n",
22 path.display(),
23 line,
24 col,
25 v.rule_code,
26 v.message,
27 ));
28 }
29 }
30
31 out
32 }
33}