Skip to content

Commit

Permalink
Rename format option to output-format
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 19, 2023
1 parent fdbefd7 commit bd84520
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 57 deletions.
2 changes: 1 addition & 1 deletion crates/ruff/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct CliSettings {
pub cache_dir: PathBuf,
pub fix: bool,
pub fix_only: bool,
pub format: SerializationFormat,
pub output_format: SerializationFormat,
pub show_fixes: bool,
pub show_source: bool,
}
Expand Down
24 changes: 18 additions & 6 deletions crates/ruff_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,21 @@ pub struct CheckCommand {
/// Ignore any `# noqa` comments.
#[arg(long)]
ignore_noqa: bool,
/// Output serialization format for violations.
#[arg(long, value_enum, env = "RUFF_FORMAT")]

/// Output serialization format for violations. (Deprecated: Use `--output-format` instead).
#[arg(
long,
value_enum,
env = "RUFF_FORMAT",
conflicts_with = "output_format",
hide = true
)]
pub format: Option<SerializationFormat>,

/// Output serialization format for violations.
#[arg(long, value_enum, env = "RUFF_OUTPUT_FORMAT")]
pub output_format: Option<SerializationFormat>,

/// Specify file to write the linter output to (default: stdout).
#[arg(short, long)]
pub output_file: Option<PathBuf>,
Expand Down Expand Up @@ -476,7 +488,7 @@ impl CheckCommand {
fix: resolve_bool_arg(self.fix, self.no_fix),
fix_only: resolve_bool_arg(self.fix_only, self.no_fix_only),
force_exclude: resolve_bool_arg(self.force_exclude, self.no_force_exclude),
format: self.format,
output_format: self.output_format.or(self.format),
show_fixes: resolve_bool_arg(self.show_fixes, self.no_show_fixes),
},
)
Expand Down Expand Up @@ -578,7 +590,7 @@ pub struct Overrides {
pub fix: Option<bool>,
pub fix_only: Option<bool>,
pub force_exclude: Option<bool>,
pub format: Option<SerializationFormat>,
pub output_format: Option<SerializationFormat>,
pub show_fixes: Option<bool>,
}

Expand Down Expand Up @@ -622,8 +634,8 @@ impl ConfigProcessor for Overrides {
.collect(),
extend_fixable: self.extend_fixable.clone().unwrap_or_default(),
});
if let Some(format) = &self.format {
config.format = Some(*format);
if let Some(output_format) = &self.output_format {
config.output_format = Some(*output_format);
}
if let Some(force_exclude) = &self.force_exclude {
config.force_exclude = Some(*force_exclude);
Expand Down
24 changes: 16 additions & 8 deletions crates/ruff_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use notify::{recommended_watcher, RecursiveMode, Watcher};
use ruff::logging::{set_up_logging, LogLevel};
use ruff::settings::types::SerializationFormat;
use ruff::settings::{flags, CliSettings};
use ruff::{fs, warn_user_once};
use ruff::{fs, warn_user, warn_user_once};

use crate::args::{Args, CheckCommand, Command, FormatCommand};
use crate::printer::{Flags as PrinterFlags, Printer};
Expand Down Expand Up @@ -180,6 +180,14 @@ fn format(args: FormatCommand, log_level: LogLevel) -> Result<ExitStatus> {
}

pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
if args.format.is_some() {
if std::env::var("RUFF_FORMAT").is_ok() {
warn_user!("The environment variable `RUFF_FORMAT` is deprecated. Use `RUFF_OUTPUT_FORMAT` instead.");
} else {
warn_user!("The argument `--format=<FORMAT>` is deprecated. Use `--output-format=<FORMAT>` instead.");
}
}

let (cli, overrides) = args.partition();

// Construct the "default" settings. These are used when no `pyproject.toml`
Expand Down Expand Up @@ -219,7 +227,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
let CliSettings {
fix,
fix_only,
format,
output_format,
show_fixes,
show_source,
..
Expand Down Expand Up @@ -251,7 +259,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
printer_flags |= PrinterFlags::SHOW_SOURCE;
}
if cli.ecosystem_ci {
warn_user_once!(
warn_user!(
"The formatting of fixes emitted by this option is a work-in-progress, subject to \
change at any time, and intended only for internal use."
);
Expand All @@ -262,12 +270,12 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
if cache {
// `--no-cache` doesn't respect code changes, and so is often confusing during
// development.
warn_user_once!("Detected debug build without --no-cache.");
warn_user!("Detected debug build without --no-cache.");
}

if cli.add_noqa {
if !autofix.is_generate() {
warn_user_once!("--fix is incompatible with --add-noqa.");
warn_user!("--fix is incompatible with --add-noqa.");
}
let modifications =
commands::add_noqa::add_noqa(&cli.files, &pyproject_config, &overrides)?;
Expand All @@ -281,11 +289,11 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
return Ok(ExitStatus::Success);
}

let printer = Printer::new(format, log_level, autofix, printer_flags);
let printer = Printer::new(output_format, log_level, autofix, printer_flags);

if cli.watch {
if format != SerializationFormat::Text {
warn_user_once!("--format 'text' is used in watch mode.");
if output_format != SerializationFormat::Text {
warn_user!("--format 'text' is used in watch mode.");
}

// Configure the file watcher.
Expand Down

0 comments on commit bd84520

Please sign in to comment.