mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:26:23 +00:00
Add --skip-magic-trailing-comma
to formatter dev comment (#8689)
Testing the compatibility with the future stable black style, i realized the `ruff_python_formatter` dev main was lacking the `--skip-magic-trailing-comma` option. This does not affect `ruff format`. Usage: ```shell cargo run --bin ruff_python_formatter -p ruff_python_formatter -- --skip-magic-trailing-comma --emit stdout scratch.py ```
This commit is contained in:
parent
9d76e4e0b9
commit
a783b14e7d
1 changed files with 14 additions and 6 deletions
|
@ -12,7 +12,7 @@ use ruff_python_parser::{parse_ok_tokens, AsMode};
|
|||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments::collect_comments;
|
||||
use crate::{format_module_ast, PreviewMode, PyFormatOptions};
|
||||
use crate::{format_module_ast, MagicTrailingComma, PreviewMode, PyFormatOptions};
|
||||
|
||||
#[derive(ValueEnum, Clone, Debug)]
|
||||
pub enum Emit {
|
||||
|
@ -40,6 +40,8 @@ pub struct Cli {
|
|||
pub print_ir: bool,
|
||||
#[clap(long)]
|
||||
pub print_comments: bool,
|
||||
#[clap(long, short = 'C')]
|
||||
pub skip_magic_trailing_comma: bool,
|
||||
}
|
||||
|
||||
pub fn format_and_debug_print(source: &str, cli: &Cli, source_path: &Path) -> Result<String> {
|
||||
|
@ -51,11 +53,17 @@ pub fn format_and_debug_print(source: &str, cli: &Cli, source_path: &Path) -> Re
|
|||
let module = parse_ok_tokens(tokens, source, source_type.as_mode(), "<filename>")
|
||||
.context("Syntax error in input")?;
|
||||
|
||||
let options = PyFormatOptions::from_extension(source_path).with_preview(if cli.preview {
|
||||
PreviewMode::Enabled
|
||||
} else {
|
||||
PreviewMode::Disabled
|
||||
});
|
||||
let options = PyFormatOptions::from_extension(source_path)
|
||||
.with_preview(if cli.preview {
|
||||
PreviewMode::Enabled
|
||||
} else {
|
||||
PreviewMode::Disabled
|
||||
})
|
||||
.with_magic_trailing_comma(if cli.skip_magic_trailing_comma {
|
||||
MagicTrailingComma::Ignore
|
||||
} else {
|
||||
MagicTrailingComma::Respect
|
||||
});
|
||||
|
||||
let source_code = SourceCode::new(source);
|
||||
let formatted = format_module_ast(&module, &comment_ranges, source, options)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue