Skip to content

Commit 36a9efd

Browse files
committed
Remove check, --explain, --clean, --generate-shell-completion aliases (#12011)
1 parent d6a2cad commit 36a9efd

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

crates/ruff/src/args.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pub enum Command {
9595
/// Run Ruff on the given files or directories (default).
9696
Check(CheckCommand),
9797
/// Explain a rule (or all rules).
98-
#[clap(alias = "--explain")]
9998
#[command(group = clap::ArgGroup::new("selector").multiple(false).required(true))]
10099
Rule {
101100
/// Rule to explain
@@ -125,10 +124,9 @@ pub enum Command {
125124
output_format: HelpFormat,
126125
},
127126
/// Clear any caches in the current directory and any subdirectories.
128-
#[clap(alias = "--clean")]
129127
Clean,
130128
/// Generate shell completion.
131-
#[clap(alias = "--generate-shell-completion", hide = true)]
129+
#[clap(hide = true)]
132130
GenerateShellCompletion { shell: clap_complete_command::Shell },
133131
/// Run the Ruff formatter on the given files or directories.
134132
Format(FormatCommand),

crates/ruff/src/lib.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use std::process::ExitCode;
88
use std::sync::mpsc::channel;
99

1010
use anyhow::Result;
11-
use args::{GlobalConfigArgs, ServerCommand};
1211
use clap::CommandFactory;
1312
use colored::Colorize;
1413
use log::warn;
1514
use notify::{recommended_watcher, RecursiveMode, Watcher};
1615

16+
use args::{GlobalConfigArgs, ServerCommand};
1717
use ruff_linter::logging::{set_up_logging, LogLevel};
1818
use ruff_linter::settings::flags::FixMode;
1919
use ruff_linter::settings::types::OutputFormat;
@@ -121,7 +121,6 @@ pub fn run(
121121
command,
122122
global_options,
123123
}: Args,
124-
deprecated_alias_warning: Option<&'static str>,
125124
) -> Result<ExitStatus> {
126125
{
127126
let default_panic_hook = std::panic::take_hook();
@@ -145,23 +144,8 @@ pub fn run(
145144
}));
146145
}
147146

148-
// Enabled ANSI colors on Windows 10.
149-
#[cfg(windows)]
150-
assert!(colored::control::set_virtual_terminal(true).is_ok());
151-
152-
// support FORCE_COLOR env var
153-
if let Some(force_color) = std::env::var_os("FORCE_COLOR") {
154-
if force_color.len() > 0 {
155-
colored::control::set_override(true);
156-
}
157-
}
158-
159147
set_up_logging(global_options.log_level())?;
160148

161-
if let Some(deprecated_alias_warning) = deprecated_alias_warning {
162-
warn_user!("{}", deprecated_alias_warning);
163-
}
164-
165149
match command {
166150
Command::Version { output_format } => {
167151
commands::version::version(output_format)?;

crates/ruff/src/main.rs

+30-10
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use std::process::ExitCode;
22

33
use clap::{Parser, Subcommand};
44
use colored::Colorize;
5+
use log::error;
56

67
use ruff::args::{Args, Command};
78
use ruff::{run, ExitStatus};
9+
use ruff_linter::logging::{set_up_logging, LogLevel};
810

911
#[cfg(target_os = "windows")]
1012
#[global_allocator]
@@ -23,23 +25,33 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
2325
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
2426

2527
pub fn main() -> ExitCode {
28+
// Enabled ANSI colors on Windows 10.
29+
#[cfg(windows)]
30+
assert!(colored::control::set_virtual_terminal(true).is_ok());
31+
32+
// support FORCE_COLOR env var
33+
if let Some(force_color) = std::env::var_os("FORCE_COLOR") {
34+
if force_color.len() > 0 {
35+
colored::control::set_override(true);
36+
}
37+
}
38+
2639
let args = wild::args_os();
27-
let mut args =
28-
argfile::expand_args_from(args, argfile::parse_fromfile, argfile::PREFIX).unwrap();
40+
let args = argfile::expand_args_from(args, argfile::parse_fromfile, argfile::PREFIX).unwrap();
2941

3042
// We can't use `warn_user` here because logging isn't set up at this point
3143
// and we also don't know if the user runs ruff with quiet.
3244
// Keep the message and pass it to `run` that is responsible for emitting the warning.
33-
let deprecated_alias_warning = match args.get(1).and_then(|arg| arg.to_str()) {
45+
let deprecated_alias_error = match args.get(1).and_then(|arg| arg.to_str()) {
3446
// Deprecated aliases that are handled by clap
3547
Some("--explain") => {
36-
Some("`ruff --explain <RULE>` is deprecated. Use `ruff rule <RULE>` instead.")
48+
Some("`ruff --explain <RULE>` has been removed. Use `ruff rule <RULE>` instead.")
3749
}
3850
Some("--clean") => {
39-
Some("`ruff --clean` is deprecated. Use `ruff clean` instead.")
51+
Some("`ruff --clean` has been removed. Use `ruff clean` instead.")
4052
}
4153
Some("--generate-shell-completion") => {
42-
Some("`ruff --generate-shell-completion <SHELL>` is deprecated. Use `ruff generate-shell-completion <SHELL>` instead.")
54+
Some("`ruff --generate-shell-completion <SHELL>` has been removed. Use `ruff generate-shell-completion <SHELL>` instead.")
4355
}
4456
// Deprecated `ruff` alias to `ruff check`
4557
// Clap doesn't support default subcommands but we want to run `check` by
@@ -51,18 +63,26 @@ pub fn main() -> ExitCode {
5163
&& arg != "-V"
5264
&& arg != "--version"
5365
&& arg != "help" => {
54-
5566
{
56-
args.insert(1, "check".into());
57-
Some("`ruff <path>` is deprecated. Use `ruff check <path>` instead.")
67+
Some("`ruff <path>` has been removed. Use `ruff check <path>` instead.")
5868
}
5969
},
6070
_ => None
6171
};
6272

73+
if let Some(error) = deprecated_alias_error {
74+
#[allow(clippy::print_stderr)]
75+
if set_up_logging(LogLevel::Default).is_ok() {
76+
error!("{}", error);
77+
} else {
78+
eprintln!("{}", error.red().bold());
79+
}
80+
return ExitCode::FAILURE;
81+
}
82+
6383
let args = Args::parse_from(args);
6484

65-
match run(args, deprecated_alias_warning) {
85+
match run(args) {
6686
Ok(code) => code.into(),
6787
Err(err) => {
6888
#[allow(clippy::print_stderr)]

crates/ruff/tests/integration_test.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,8 @@ fn unreadable_pyproject_toml() -> Result<()> {
12981298

12991299
// Don't `--isolated` since the configuration discovery is where the error happens
13001300
let args = Args::parse_from(["", "check", "--no-cache", tempdir.path().to_str().unwrap()]);
1301-
let err = run(args, None).err().context("Unexpected success")?;
1301+
let err = run(args).err().context("Unexpected success")?;
1302+
13021303
assert_eq!(
13031304
err.chain()
13041305
.map(std::string::ToString::to_string)

0 commit comments

Comments
 (0)