Repository: astral-sh/ruff
File: crates/ruff/src/commands/format.rs (Rust)

Code before:
    if config_arguments.log_level >= LogLevel::Default {
        match mode {
            FormatMode::Write => {}
            FormatMode::Check => {
                results.write_changed(&mut stdout().lock())?;
            }
            FormatMode::Diff => {
                results.write_diff(&mut stdout().lock())?;
            }
        }

        if mode.is_diff() {
            // Allow piping the diff to e.g. a file by writing the summary to stderr
            results.write_summary(&mut stderr().lock())?;
        } else {
            results.write_summary(&mut stdout().lock())?;
        }
    }

    match mode {
        FormatMode::Write => {
            if errors.is_empty() {
                if cli.exit_non_zero_on_format && results.any_formatted() {
                    Ok(ExitStatus::Failure)
                } else {
                    Ok(ExitStatus::Success)
                }
            } else {
                Ok(ExitStatus::Error)
            }
        }
        FormatMode::Check | FormatMode::Diff => {
            if errors.is_empty() {
                if results.any_formatted() {
                    Ok(ExitStatus::Failure)
                } else {
                    Ok(ExitStatus::Success)
                }
            } else {
                Ok(ExitStatus::Error)
            }
        }
    }
}

/// Format the file at the given [`Path`].
#[tracing::instrument(level = "debug", skip_all, fields(path = %path.display()))]
pub(crate) fn format_path(
    path: &Path,
    settings: &FormatterSettings,
    source_type: PySourceType,

Review comment (suggestion):
We should compare the behavior with `ruff check` but I think `ruff check` still writes the diagnostics (the diff) when `--quiet` is used. I'm not sure what it does for `--silent`. 

Code after:
    // Report on any errors.
    //
    // We only convert errors to `Diagnostic`s in `Check` mode with preview enabled, otherwise we
    // fall back on printing simple messages.
    if !(preview.is_enabled() && mode.is_check()) {
        errors.sort_unstable_by(|a, b| a.path().cmp(&b.path()));

        for error in &errors {
            error!("{error}");
        }
    }

    let results = FormatResults::new(results.as_slice(), mode);
    if config_arguments.log_level > LogLevel::Silent {
        match mode {
            FormatMode::Write => {}
            FormatMode::Check => {
                if preview.is_enabled() {
                    results.write_changed_preview(&mut stdout().lock(), output_format, &errors)?;
                } else {
                    results.write_changed(&mut stdout().lock())?;
                }
            }
            FormatMode::Diff => {
                results.write_diff(&mut stdout().lock())?;
            }
        }
    }

    // Report on the formatting changes.
    if config_arguments.log_level >= LogLevel::Default {
        if mode.is_diff() {
            // Allow piping the diff to e.g. a file by writing the summary to stderr
            results.write_summary(&mut stderr().lock())?;
        } else if !preview.is_enabled() || output_format.is_human_readable() {
            results.write_summary(&mut stdout().lock())?;
        }
    }

    match mode {
        FormatMode::Write => {
            if errors.is_empty() {
                if cli.exit_non_zero_on_format && results.any_formatted() {
                    Ok(ExitStatus::Failure)
                } else {
                    Ok(ExitStatus::Success)
                }
            } else {
                Ok(ExitStatus::Error)
            }
        }