Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions crates/squawk/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -307,10 +306,9 @@ fn get_sql_file_content(violation: &CheckReport) -> Result<String> {
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!(
Expand Down
25 changes: 16 additions & 9 deletions crates/squawk/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ fn render_lint_error<W: std::io::Write>(
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,
Expand All @@ -115,12 +121,12 @@ fn render_lint_error<W: std::io::Write>(
.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));
Expand Down Expand Up @@ -340,16 +346,17 @@ pub fn fmt_tty_violation<W: io::Write>(
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(())
}

pub fn fmt_tty<W: io::Write>(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)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading