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
20 changes: 10 additions & 10 deletions crates/squawk/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ fn get_summary_comment_body(

let summary = format!(
r"
<h3><code>{filename}</code></h3>
<h3><code>{path}</code></h3>

📄 **{line_count} lines** | {violations_emoji} **{violation_count} violations**

{violations_detail}

---
",
filename = file.filename,
path = file.path,
line_count = line_count,
violations_emoji = violations_emoji,
violation_count = violation_count,
Expand Down Expand Up @@ -312,7 +312,7 @@ 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.filename, sql)?;
fmt_tty_violation(&mut buff, v, &violation.path, sql)?;
}
let violations_text_raw = &String::from_utf8_lossy(&buff);
let violations_text = strip_ansi_codes(violations_text_raw);
Expand Down Expand Up @@ -340,7 +340,7 @@ fn get_sql_file_content(violation: &CheckReport) -> Result<String> {

Ok(format!(
r"
<h3><code>{filename}</code></h3>
<h3><code>{path}</code></h3>

```sql
{sql}
Expand All @@ -353,7 +353,7 @@ fn get_sql_file_content(violation: &CheckReport) -> Result<String> {
---
",
violations_emoji = violations_emoji,
filename = violation.filename,
path = violation.path,
sql = display_sql,
truncation_notice = truncation_notice,
violation_count = violation_count,
Expand All @@ -376,7 +376,7 @@ mod test_github_comment {
#[test]
fn generating_comment_multiple_files() {
let violations = vec![CheckReport {
filename: "alpha.sql".into(),
path: "alpha.sql".into(),
sql: "SELECT 1;".into(),
violations: vec![ReportViolation {
file: "alpha.sql".into(),
Expand Down Expand Up @@ -405,7 +405,7 @@ mod test_github_comment {
fn generating_comment_no_violations() {
let violations = vec![
CheckReport {
filename: "alpha.sql".into(),
path: "alpha.sql".into(),
sql: r#"
BEGIN;
--
Expand All @@ -420,7 +420,7 @@ CREATE TABLE "core_bar" (
violations: vec![],
},
CheckReport {
filename: "bravo.sql".into(),
path: "bravo.sql".into(),
sql: r#"
ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
"#
Expand Down Expand Up @@ -470,7 +470,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
.join("\n");

let violations = vec![CheckReport {
filename: "large.sql".into(),
path: "large.sql".into(),
sql: large_sql,
violations: vec![ReportViolation {
file: "large.sql".into(),
Expand Down Expand Up @@ -505,7 +505,7 @@ ALTER TABLE "core_recipe" ADD COLUMN "foo" integer DEFAULT 10;
.join("\n");

let violations = vec![CheckReport {
filename: "massive.sql".into(),
path: "massive.sql".into(),
sql: massive_sql,
violations: vec![ReportViolation {
file: "massive.sql".into(),
Expand Down
11 changes: 5 additions & 6 deletions crates/squawk/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn check_sql(
})
.collect();
return CheckReport {
filename: path.into(),
path: path.into(),
sql: sql.into(),
violations,
};
Expand Down Expand Up @@ -92,7 +92,7 @@ fn check_sql(
.collect();

CheckReport {
filename: path.into(),
path: path.into(),
sql: sql.into(),
violations,
}
Expand Down Expand Up @@ -187,7 +187,7 @@ pub fn lint_files(args: &LintArgs) -> Result<Vec<CheckReport>> {
))
})
.collect::<Result<Vec<_>>>()?;
reports.sort_by(|a, b| a.filename.cmp(&b.filename));
reports.sort_by(|a, b| a.path.cmp(&b.path));
Ok(reports)
}
}
Expand Down Expand Up @@ -339,7 +339,7 @@ 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.filename, &report.sql)?;
fmt_tty_violation(f, violation, &report.path, &report.sql)?;
}
}
print_summary(f, &summary)?;
Expand Down Expand Up @@ -462,8 +462,7 @@ fn fmt_gitlab<W: io::Write>(f: &mut W, reports: Vec<CheckReport>) -> Result<()>

#[derive(Debug)]
pub struct CheckReport {
// TODO: rename this to path
pub filename: String,
pub path: String,
pub sql: String,
pub violations: Vec<ReportViolation>,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
source: crates/squawk/src/reporter.rs
expression: "check_sql(sql, filename, &[], None, false)"
expression: "check_sql(sql, filename, &[], &[], None, false)"
---
CheckReport {
filename: "main.sql",
path: "main.sql",
sql: "\n\n ALTER TABLE \"core_recipe\" ADD COLUMN \"foo\" integer NOT NULL;\nALTER TABLE \"core_foo\" ADD COLUMN \"bar\" integer NOT NULL;\nSELECT 1;\n",
violations: [
ReportViolation {
Expand Down
Loading