mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Add PreviewMode option to formatter
## Summary This PR adds the `--preview` and `--no-preview` options to the `format` command (hidden) and passes it through to the formatte. ## Test Plan I added the `dbg(f.options().preview())` statement in `FormatNodeRule::fmt` and verified that the option gets correctly passed to the formatter.
This commit is contained in:
parent
d9544a2d37
commit
47a253fb62
7 changed files with 54 additions and 7 deletions
|
@ -13,6 +13,7 @@ use tracing::{debug, warn};
|
|||
|
||||
use ruff::fs;
|
||||
use ruff::logging::LogLevel;
|
||||
use ruff::settings::types::PreviewMode;
|
||||
use ruff::warn_user_once;
|
||||
use ruff_formatter::LineWidth;
|
||||
use ruff_python_ast::{PySourceType, SourceType};
|
||||
|
@ -72,9 +73,15 @@ pub(crate) fn format(
|
|||
return None;
|
||||
};
|
||||
|
||||
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 = 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_line_width(LineWidth::from(NonZeroU16::from(line_length)))
|
||||
.with_preview(preview);
|
||||
debug!("Formatting {} with {:?}", path.display(), options);
|
||||
Some(format_path(path, options, mode))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue