Skip to content

Remove check, --explain, --clean, --generate-shell-completion aliases #12011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pub enum Command {
/// Run Ruff on the given files or directories (default).
Check(CheckCommand),
/// Explain a rule (or all rules).
#[clap(alias = "--explain")]
#[command(group = clap::ArgGroup::new("selector").multiple(false).required(true))]
Rule {
/// Rule to explain
Expand Down Expand Up @@ -125,10 +124,8 @@ pub enum Command {
output_format: HelpFormat,
},
/// Clear any caches in the current directory and any subdirectories.
#[clap(alias = "--clean")]
Clean,
/// Generate shell completion.
#[clap(alias = "--generate-shell-completion", hide = true)]
GenerateShellCompletion { shell: clap_complete_command::Shell },
/// Run the Ruff formatter on the given files or directories.
Format(FormatCommand),
Expand Down
5 changes: 0 additions & 5 deletions crates/ruff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pub fn run(
command,
global_options,
}: Args,
deprecated_alias_warning: Option<&'static str>,
) -> Result<ExitStatus> {
{
let default_panic_hook = std::panic::take_hook();
Expand Down Expand Up @@ -158,10 +157,6 @@ pub fn run(

set_up_logging(global_options.log_level())?;

if let Some(deprecated_alias_warning) = deprecated_alias_warning {
warn_user!("{}", deprecated_alias_warning);
}

match command {
Command::Version { output_format } => {
commands::version::version(output_format)?;
Expand Down
43 changes: 4 additions & 39 deletions crates/ruff/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::process::ExitCode;

use clap::{Parser, Subcommand};
use clap::Parser;
use colored::Colorize;

use ruff::args::{Args, Command};
use ruff::args::Args;
use ruff::{run, ExitStatus};

#[cfg(target_os = "windows")]
Expand All @@ -24,45 +24,10 @@ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

pub fn main() -> ExitCode {
let args = wild::args_os();
let mut args =
argfile::expand_args_from(args, argfile::parse_fromfile, argfile::PREFIX).unwrap();

// We can't use `warn_user` here because logging isn't set up at this point
// and we also don't know if the user runs ruff with quiet.
// Keep the message and pass it to `run` that is responsible for emitting the warning.
let deprecated_alias_warning = match args.get(1).and_then(|arg| arg.to_str()) {
// Deprecated aliases that are handled by clap
Some("--explain") => {
Some("`ruff --explain <RULE>` is deprecated. Use `ruff rule <RULE>` instead.")
}
Some("--clean") => {
Some("`ruff --clean` is deprecated. Use `ruff clean` instead.")
}
Some("--generate-shell-completion") => {
Some("`ruff --generate-shell-completion <SHELL>` is deprecated. Use `ruff generate-shell-completion <SHELL>` instead.")
}
// Deprecated `ruff` alias to `ruff check`
// Clap doesn't support default subcommands but we want to run `check` by
// default for convenience and backwards-compatibility, so we just
// preprocess the arguments accordingly before passing them to Clap.
Some(arg) if !Command::has_subcommand(arg)
&& arg != "-h"
&& arg != "--help"
&& arg != "-V"
&& arg != "--version"
&& arg != "help" => {

{
args.insert(1, "check".into());
Some("`ruff <path>` is deprecated. Use `ruff check <path>` instead.")
}
},
_ => None
};

let args = argfile::expand_args_from(args, argfile::parse_fromfile, argfile::PREFIX).unwrap();
let args = Args::parse_from(args);

match run(args, deprecated_alias_warning) {
match run(args) {
Ok(code) => code.into(),
Err(err) => {
#[allow(clippy::print_stderr)]
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ fn unreadable_pyproject_toml() -> Result<()> {

// Don't `--isolated` since the configuration discovery is where the error happens
let args = Args::parse_from(["", "check", "--no-cache", tempdir.path().to_str().unwrap()]);
let err = run(args, None).err().context("Unexpected success")?;
let err = run(args).err().context("Unexpected success")?;
assert_eq!(
err.chain()
.map(std::string::ToString::to_string)
Expand Down
24 changes: 15 additions & 9 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,21 @@ Ruff: An extremely fast Python linter.
Usage: ruff [OPTIONS] <COMMAND>

Commands:
check Run Ruff on the given files or directories (default)
rule Explain a rule (or all rules)
config List or describe the available configuration options
linter List all supported upstream linters
clean Clear any caches in the current directory and any subdirectories
format Run the Ruff formatter on the given files or directories
server Run the language server
version Display Ruff's version
help Print this message or the help of the given subcommand(s)
check Run Ruff on the given files or directories
(default)
rule Explain a rule (or all rules)
config List or describe the available configuration
options
linter List all supported upstream linters
clean Clear any caches in the current directory and
any subdirectories
generate-shell-completion Generate shell completion
format Run the Ruff formatter on the given files or
directories
server Run the language server
version Display Ruff's version
help Print this message or the help of the given
subcommand(s)

Options:
-h, --help Print help
Expand Down
Loading