mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-15 08:00:19 +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 ruff_text_size::Ranged;
|
||||||
|
|
||||||
use crate::comments::collect_comments;
|
use crate::comments::collect_comments;
|
||||||
use crate::{format_module_ast, PreviewMode, PyFormatOptions};
|
use crate::{format_module_ast, MagicTrailingComma, PreviewMode, PyFormatOptions};
|
||||||
|
|
||||||
#[derive(ValueEnum, Clone, Debug)]
|
#[derive(ValueEnum, Clone, Debug)]
|
||||||
pub enum Emit {
|
pub enum Emit {
|
||||||
|
@ -40,6 +40,8 @@ pub struct Cli {
|
||||||
pub print_ir: bool,
|
pub print_ir: bool,
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
pub print_comments: bool,
|
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> {
|
pub fn format_and_debug_print(source: &str, cli: &Cli, source_path: &Path) -> Result<String> {
|
||||||
|
@ -51,10 +53,16 @@ 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>")
|
let module = parse_ok_tokens(tokens, source, source_type.as_mode(), "<filename>")
|
||||||
.context("Syntax error in input")?;
|
.context("Syntax error in input")?;
|
||||||
|
|
||||||
let options = PyFormatOptions::from_extension(source_path).with_preview(if cli.preview {
|
let options = PyFormatOptions::from_extension(source_path)
|
||||||
|
.with_preview(if cli.preview {
|
||||||
PreviewMode::Enabled
|
PreviewMode::Enabled
|
||||||
} else {
|
} else {
|
||||||
PreviewMode::Disabled
|
PreviewMode::Disabled
|
||||||
|
})
|
||||||
|
.with_magic_trailing_comma(if cli.skip_magic_trailing_comma {
|
||||||
|
MagicTrailingComma::Ignore
|
||||||
|
} else {
|
||||||
|
MagicTrailingComma::Respect
|
||||||
});
|
});
|
||||||
|
|
||||||
let source_code = SourceCode::new(source);
|
let source_code = SourceCode::new(source);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue