mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-14 15:40:20 +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
|
@ -39,6 +39,9 @@ pub struct PyFormatOptions {
|
|||
/// Should the formatter generate a source map that allows mapping source positions to positions
|
||||
/// in the formatted document.
|
||||
source_map_generation: SourceMapGeneration,
|
||||
|
||||
/// Whether preview style formatting is enabled or not
|
||||
preview: PreviewMode,
|
||||
}
|
||||
|
||||
fn default_line_width() -> LineWidth {
|
||||
|
@ -64,6 +67,7 @@ impl Default for PyFormatOptions {
|
|||
line_ending: LineEnding::default(),
|
||||
magic_trailing_comma: MagicTrailingComma::default(),
|
||||
source_map_generation: SourceMapGeneration::default(),
|
||||
preview: PreviewMode::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +105,10 @@ impl PyFormatOptions {
|
|||
self.line_ending
|
||||
}
|
||||
|
||||
pub fn preview(&self) -> PreviewMode {
|
||||
self.preview
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_tab_width(mut self, tab_width: TabWidth) -> Self {
|
||||
self.tab_width = tab_width;
|
||||
|
@ -136,6 +144,12 @@ impl PyFormatOptions {
|
|||
self.line_ending = line_ending;
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_preview(mut self, preview: PreviewMode) -> Self {
|
||||
self.preview = preview;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl FormatOptions for PyFormatOptions {
|
||||
|
@ -246,3 +260,18 @@ impl FromStr for MagicTrailingComma {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub enum PreviewMode {
|
||||
#[default]
|
||||
Disabled,
|
||||
|
||||
Enabled,
|
||||
}
|
||||
|
||||
impl PreviewMode {
|
||||
pub const fn is_enabled(self) -> bool {
|
||||
matches!(self, PreviewMode::Enabled)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue