From 3a83a946c18408bb45f51215505def2b8591f1ce Mon Sep 17 00:00:00 2001 From: Ben King <9087625+benfdking@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:46:17 +0000 Subject: [PATCH 1/2] temp --- crates/cli/src/commands_fix.rs | 11 ++++++++++- crates/cli/tests/ui.rs | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/cli/src/commands_fix.rs b/crates/cli/src/commands_fix.rs index 9212905dd..8a16e2246 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 83bf4fb24..75313eadf 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); } + } From 85509be6c6369c436ddf5521ceb2db55b7fe65b4 Mon Sep 17 00:00:00 2001 From: Ben King <9087625+benfdking@users.noreply.github.com> Date: Sun, 15 Dec 2024 21:21:30 +0100 Subject: [PATCH 2/2] temp [ci skip] --- crates/lib/src/cli.rs | 2 ++ crates/lib/src/cli/formatters.rs | 18 +----------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/crates/lib/src/cli.rs b/crates/lib/src/cli.rs index 17c1ff7a3..4a7990550 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 495752475..caed9c38f 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,