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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ url = "2.5.4"
crossbeam-channel = "0.5.15"
crossbeam-utils = "0.8.21"
jod-thread = "0.1.2"
rayon = "1"
libc = "0.2.171"
tracing = "0.1.40"
rustc-hash = "2.1.1"
Expand Down
1 change: 1 addition & 0 deletions crates/squawk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ squawk-server.workspace = true
squawk-thread.workspace = true
toml.workspace = true
glob.workspace = true
rayon.workspace = true
anyhow.workspace = true
annotate-snippets.workspace = true
line-index.workspace = true
Expand Down
57 changes: 30 additions & 27 deletions crates/squawk/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use console::style;
use line_index::LineIndex;
use line_index::TextRange;
use log::info;
use rayon::prelude::*;
use serde::Serialize;
use squawk_linter::{Fix, Linter, Rule, Version};
use squawk_syntax::SourceFile;
Expand Down Expand Up @@ -151,44 +152,45 @@ pub(crate) struct LintArgs {
}

pub fn lint_files(args: &LintArgs) -> Result<Vec<CheckReport>> {
let mut violations = vec![];
match &args.input {
Input::Stdin(stdin) => {
info!("reading content from stdin");
let sql = sql_from_stdin()?;
// ignore stdin if it's empty.
if sql.trim().is_empty() {
info!("ignoring empty stdin");
} else {
let path = stdin.path.clone().unwrap_or_else(|| "stdin".into());
let content = check_sql(
&sql,
&path,
&args.included_rules,
&args.excluded_rules,
args.pg_version,
args.assume_in_transaction,
);
violations.push(content);
return Ok(vec![]);
}
let path = stdin.path.clone().unwrap_or_else(|| "stdin".into());
let content = check_sql(
&sql,
&path,
&args.included_rules,
&args.excluded_rules,
args.pg_version,
args.assume_in_transaction,
);
Ok(vec![content])
}
Input::Paths(path_bufs) => {
for path in path_bufs {
info!("checking file path: {}", path.display());
let sql = sql_from_path(path)?;
let content = check_sql(
&sql,
path.to_str().unwrap(),
&args.included_rules,
&args.excluded_rules,
args.pg_version,
args.assume_in_transaction,
);
violations.push(content);
}
let mut reports: Vec<CheckReport> = path_bufs
.par_iter()
.map(|path| {
info!("checking file path: {}", path.display());
let sql = sql_from_path(path)?;
Ok(check_sql(
&sql,
path.to_str().unwrap(),
&args.included_rules,
&args.excluded_rules,
args.pg_version,
args.assume_in_transaction,
))
})
.collect::<Result<Vec<_>>>()?;
reports.sort_by(|a, b| a.filename.cmp(&b.filename));
Ok(reports)
}
}
Ok(violations)
}

pub fn lint_and_report<W: io::Write>(f: &mut W, args: LintArgs) -> Result<ExitCode> {
Expand Down Expand Up @@ -460,6 +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 sql: String,
pub violations: Vec<ReportViolation>,
Expand Down
Loading