diff --git a/crates/ruff_cli/src/commands/format.rs b/crates/ruff_cli/src/commands/format.rs index 789b1511d5..e278f54edf 100644 --- a/crates/ruff_cli/src/commands/format.rs +++ b/crates/ruff_cli/src/commands/format.rs @@ -73,12 +73,14 @@ pub(crate) fn format( return None; }; - let preview = match pyproject_config.settings.lib.preview { + let resolved_settings = resolver.resolve(path, &pyproject_config); + + let preview = match resolved_settings.preview { PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled, PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled, }; + let line_length = resolved_settings.line_length; - let line_length = resolver.resolve(path, &pyproject_config).line_length; let options = PyFormatOptions::from_source_type(source_type) .with_line_width(LineWidth::from(NonZeroU16::from(line_length))) .with_preview(preview); diff --git a/crates/ruff_cli/src/commands/format_stdin.rs b/crates/ruff_cli/src/commands/format_stdin.rs index c430fa6937..0f3b7ab4ea 100644 --- a/crates/ruff_cli/src/commands/format_stdin.rs +++ b/crates/ruff_cli/src/commands/format_stdin.rs @@ -1,8 +1,11 @@ use std::io::{stdout, Write}; +use std::num::NonZeroU16; use std::path::Path; use anyhow::Result; use log::warn; +use ruff::settings::types::PreviewMode; +use ruff_formatter::LineWidth; use ruff_python_formatter::{format_module, PyFormatOptions}; use ruff_workspace::resolver::python_file_at_path; @@ -35,9 +38,19 @@ pub(crate) fn format_stdin(cli: &FormatArguments, overrides: &Overrides) -> Resu // Format the file. let path = cli.stdin_filename.as_deref(); + + let preview = match pyproject_config.settings.lib.preview { + PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled, + PreviewMode::Disabled => ruff_python_formatter::PreviewMode::Disabled, + }; + let line_length = pyproject_config.settings.lib.line_length; + let options = path .map(PyFormatOptions::from_extension) - .unwrap_or_default(); + .unwrap_or_default() + .with_line_width(LineWidth::from(NonZeroU16::from(line_length))) + .with_preview(preview); + match format_source(path, options, mode) { Ok(result) => match mode { FormatMode::Write => Ok(ExitStatus::Success),