Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: on fix command non-fixable violations force return of 1 #1057

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
11 changes: 10 additions & 1 deletion crates/cli/src/commands_fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,25 @@ pub(crate) fn run_fix(
}
}

let mut unfixable_errors = false;

for linted_dir in result.paths {
for mut file in linted_dir.files {
let violations = file.get_violations(Some(false));
unfixable_errors = unfixable_errors || !violations.is_empty();

let path = std::mem::take(&mut file.path);
let write_buff = file.fix_string();
std::fs::write(path, write_buff).unwrap();
}
}

linter.formatter_mut().unwrap().completion_message();
0
if unfixable_errors {
1
} else {
0
}
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/cli/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ fn main() {
expect_file![expected_output_path_stdout].assert_eq(&stdout_str);
expect_file![expected_output_path_exitcode].assert_eq(&exit_code_str);
}

}
2 changes: 2 additions & 0 deletions crates/lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ pub mod formatters;
pub mod github_annotation_native_formatter;
pub mod json;
pub mod json_types;
mod manage_fails;
mod formatter;
18 changes: 1 addition & 17 deletions crates/lib/src/cli/formatters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize};
use anstyle::{AnsiColor, Effects, Style};
use itertools::enumerate;
use sqruff_lib_core::errors::SQLBaseError;

use crate::cli::formatter::Formatter;
use crate::core::config::FluffConfig;
use crate::core::linter::linted_file::LintedFile;

Expand Down Expand Up @@ -40,22 +40,6 @@ fn split_string_on_spaces(s: &str, line_length: usize) -> Vec<&str> {
lines
}

pub trait Formatter: Send + Sync {
fn dispatch_template_header(
&self,
f_name: String,
linter_config: FluffConfig,
file_config: FluffConfig,
);

fn dispatch_parse_header(&self, f_name: String);

fn dispatch_file_violations(&self, linted_file: &LintedFile, only_fixable: bool);

fn has_fail(&self) -> bool;

fn completion_message(&self);
}

pub struct OutputStreamFormatter {
output_stream: Option<Stderr>,
Expand Down