diff --git a/crates/squawk/src/github.rs b/crates/squawk/src/github.rs index f112ae3a0..50b119dc8 100644 --- a/crates/squawk/src/github.rs +++ b/crates/squawk/src/github.rs @@ -4,7 +4,6 @@ use crate::reporter::{CheckReport, fmt_github_annotations, fmt_tty_violation}; use crate::{LintArgs, UploadToGithubArgs}; use crate::{file_finding::find_paths, reporter::lint_files}; use anyhow::{Context, Result, anyhow, bail}; -use console::strip_ansi_codes; use log::info; use squawk_github::{GitHubApi, actions, app, comment_on_pr}; use squawk_line_index::UniversalNewlines; @@ -307,10 +306,9 @@ fn get_sql_file_content(violation: &CheckReport) -> Result { let mut buff = Vec::new(); let violation_count = violation.violations.len(); for v in &violation.violations { - fmt_tty_violation(&mut buff, v, &violation.path, sql)?; + fmt_tty_violation(&mut buff, v, &violation.path, sql, false)?; } - let violations_text_raw = &String::from_utf8_lossy(&buff); - let violations_text = strip_ansi_codes(violations_text_raw); + let violations_text = String::from_utf8_lossy(&buff); let violation_content = if violation_count > 0 { format!( diff --git a/crates/squawk/src/reporter.rs b/crates/squawk/src/reporter.rs index 54dd24a47..7538816de 100644 --- a/crates/squawk/src/reporter.rs +++ b/crates/squawk/src/reporter.rs @@ -103,8 +103,14 @@ fn render_lint_error( err: &ReportViolation, filename: &str, sql: &str, + styled: bool, ) -> Result<()> { - let renderer = Renderer::styled().decor_style(DecorStyle::Unicode); + let renderer = if styled { + Renderer::styled() + } else { + Renderer::plain() + } + .decor_style(DecorStyle::Unicode); let level = match err.level { ViolationLevel::Warning => Level::WARNING, ViolationLevel::Error => Level::ERROR, @@ -115,12 +121,12 @@ fn render_lint_error( .fold(true) .annotation(AnnotationKind::Primary.span(err.range.into())); - let rule_url = format!("https://squawkhq.com/docs/{}", err.rule_name); - let mut group = level - .primary_title(&err.message) - .id(&err.rule_name) - .id_url(&rule_url) - .element(snippet); + let mut title = level.primary_title(&err.message).id(&err.rule_name); + // annotate-snippets emits OSC 8 hyperlinks even with the plain renderer + if styled { + title = title.id_url(format!("https://squawkhq.com/docs/{}", err.rule_name)); + } + let mut group = title.element(snippet); if let Some(help) = &err.help { group = group.element(Level::HELP.message(help)); @@ -340,8 +346,9 @@ pub fn fmt_tty_violation( violation: &ReportViolation, filename: &str, sql: &str, + styled: bool, ) -> Result<()> { - render_lint_error(f, violation, filename, sql)?; + render_lint_error(f, violation, filename, sql, styled)?; Ok(()) } @@ -349,7 +356,7 @@ pub fn fmt_tty(f: &mut W, reports: &[CheckReport]) -> Result<()> { let summary = Summary::from(reports); for report in reports { for violation in &report.violations { - fmt_tty_violation(f, violation, &report.path, &report.sql)?; + fmt_tty_violation(f, violation, &report.path, &report.sql, true)?; } } print_summary(f, &summary)?; diff --git a/crates/squawk/src/snapshots/squawk__github__test_github_comment__generating_comment_multiple_files.snap b/crates/squawk/src/snapshots/squawk__github__test_github_comment__generating_comment_multiple_files.snap index b2a150cf0..fd9725703 100644 --- a/crates/squawk/src/snapshots/squawk__github__test_github_comment__generating_comment_multiple_files.snap +++ b/crates/squawk/src/snapshots/squawk__github__test_github_comment__generating_comment_multiple_files.snap @@ -17,7 +17,7 @@ SELECT 1; ``` -warning[]8;;https://squawkhq.com/docs/adding-not-nullable-field\adding-not-nullable-field]8;;\]: Adding a NOT NULL field requires exclusive locks and table rewrites. +warning[adding-not-nullable-field]: Adding a NOT NULL field requires exclusive locks and table rewrites. ╭▸ alpha.sql:1:8 │ 1 │ SELECT 1;