diff --git a/crates/cli/src/commands_fix.rs b/crates/cli/src/commands_fix.rs index 9212905d..8a16e224 100644 --- a/crates/cli/src/commands_fix.rs +++ b/crates/cli/src/commands_fix.rs @@ -45,8 +45,13 @@ 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(); @@ -54,7 +59,11 @@ pub(crate) fn run_fix( } linter.formatter_mut().unwrap().completion_message(); - 0 + if unfixable_errors { + 1 + } else { + 0 + } } } diff --git a/crates/cli/tests/ui.rs b/crates/cli/tests/ui.rs index 83bf4fb2..75313ead 100644 --- a/crates/cli/tests/ui.rs +++ b/crates/cli/tests/ui.rs @@ -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); } + } diff --git a/crates/lib/src/cli.rs b/crates/lib/src/cli.rs index 17c1ff7a..4a799055 100644 --- a/crates/lib/src/cli.rs +++ b/crates/lib/src/cli.rs @@ -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; diff --git a/crates/lib/src/cli/formatters.rs b/crates/lib/src/cli/formatters.rs index 49575247..caed9c38 100644 --- a/crates/lib/src/cli/formatters.rs +++ b/crates/lib/src/cli/formatters.rs @@ -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; @@ -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,