Skip to content

Commit

Permalink
Add --quote-style argument to ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
sciyoshi committed Nov 30, 2023
1 parent 041163a commit 40dca18
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions crates/ruff_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::PathBuf;

use clap::{command, Parser};
use regex::Regex;
use ruff_python_formatter::QuoteStyle;
use rustc_hash::FxHashMap;

use ruff_linter::line_width::LineLength;
Expand Down Expand Up @@ -417,6 +418,9 @@ pub struct FormatCommand {
/// Set the line-length.
#[arg(long, help_heading = "Format configuration")]
pub line_length: Option<LineLength>,
/// Set the quote-style.
#[arg(long, help_heading = "Format configuration")]
pub quote_style: Option<QuoteStyle>,
/// Ignore all configuration files.
#[arg(long, conflicts_with = "config", help_heading = "Miscellaneous")]
pub isolated: bool,
Expand Down Expand Up @@ -521,6 +525,7 @@ impl CheckCommand {
fixable: self.fixable,
ignore: self.ignore,
line_length: self.line_length,
quote_style: None,
per_file_ignores: self.per_file_ignores,
preview: resolve_bool_arg(self.preview, self.no_preview).map(PreviewMode::from),
respect_gitignore: resolve_bool_arg(
Expand Down Expand Up @@ -562,6 +567,7 @@ impl FormatCommand {
},
CliOverrides {
line_length: self.line_length,
quote_style: self.quote_style,
respect_gitignore: resolve_bool_arg(
self.respect_gitignore,
self.no_respect_gitignore,
Expand Down Expand Up @@ -637,6 +643,7 @@ pub struct CliOverrides {
pub fixable: Option<Vec<RuleSelector>>,
pub ignore: Option<Vec<RuleSelector>>,
pub line_length: Option<LineLength>,
pub quote_style: Option<QuoteStyle>,
pub per_file_ignores: Option<Vec<PatternPrefixPair>>,
pub extend_per_file_ignores: Option<Vec<PatternPrefixPair>>,
pub preview: Option<PreviewMode>,
Expand Down Expand Up @@ -718,6 +725,9 @@ impl ConfigurationTransformer for CliOverrides {
..config.lint.pycodestyle.unwrap_or_default()
});
}
if let Some(quote_style) = self.quote_style {
config.format.quote_style = Some(quote_style);
}
if let Some(preview) = &self.preview {
config.preview = Some(*preview);
config.lint.preview = Some(*preview);
Expand Down
4 changes: 3 additions & 1 deletion crates/ruff_python_formatter/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, MagicTrailingComma, PreviewMode, PyFormatOptions};
use crate::{format_module_ast, MagicTrailingComma, PreviewMode, PyFormatOptions, QuoteStyle};

#[derive(ValueEnum, Clone, Debug)]
pub enum Emit {
Expand Down Expand Up @@ -42,6 +42,8 @@ pub struct Cli {
pub print_comments: bool,
#[clap(long, short = 'C')]
pub skip_magic_trailing_comma: bool,
#[clap(long)]
pub quote_style: QuoteStyle,
}

pub fn format_and_debug_print(source: &str, cli: &Cli, source_path: &Path) -> Result<String> {
Expand Down

0 comments on commit 40dca18

Please sign in to comment.