diff --git a/README.md b/README.md index df8cbc9fb7..2e45b18eec 100644 --- a/README.md +++ b/README.md @@ -350,6 +350,10 @@ Options: List of mappings from file pattern to code to exclude --format Output serialization format for error messages [possible values: text, json, junit, grouped, github, gitlab] + --stdin-filename + The name of the file when passing it through stdin + --cache-dir + Path to the cache directory --show-source Show violations with source code --respect-gitignore @@ -358,12 +362,6 @@ Options: Enforce exclusions, even for paths passed to Ruff directly on the command-line --update-check Enable or disable automatic update checks - --show-files - See the files Ruff will be run against with the current settings - --show-settings - See the settings Ruff will use to check a given Python file - --add-noqa - Enable automatic additions of `noqa` directives to failing lines --dummy-variable-rgx Regular expression matching the name of dummy variables --target-version @@ -372,12 +370,16 @@ Options: Set the line-length for length-associated checks and automatic formatting --max-complexity Maximum McCabe complexity allowed for a given function - --stdin-filename - The name of the file when passing it through stdin + --add-noqa + Enable automatic additions of `noqa` directives to failing lines + --clean + Clear any caches in the current directory or any subdirectories --explain Explain a rule - --cache-dir - Path to the cache directory + --show-files + See the files Ruff will be run against with the current settings + --show-settings + See the settings Ruff will use to check a given Python file -h, --help Print help information -V, --version diff --git a/src/cli.rs b/src/cli.rs index 98a00cbdc6..94af5914a8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -138,7 +138,6 @@ pub struct Cli { #[arg( long, // conflicts_with = "add_noqa", - conflicts_with = "autoformat", conflicts_with = "clean", conflicts_with = "explain", conflicts_with = "generate_shell_completion", @@ -149,29 +148,11 @@ pub struct Cli { conflicts_with = "watch", )] pub add_noqa: bool, - /// Round-trip auto-formatting. - #[arg( - long, - hide = true, - // Fake subcommands. - conflicts_with = "add_noqa", - // conflicts_with = "autoformat", - conflicts_with = "clean", - conflicts_with = "explain", - conflicts_with = "generate_shell_completion", - conflicts_with = "show_files", - conflicts_with = "show_settings", - // Unsupported default-command arguments. - conflicts_with = "stdin_filename", - conflicts_with = "watch", - )] - pub autoformat: bool, /// Clear any caches in the current directory or any subdirectories. #[arg( long, // Fake subcommands. conflicts_with = "add_noqa", - conflicts_with = "autoformat", // conflicts_with = "clean", conflicts_with = "explain", conflicts_with = "generate_shell_completion", @@ -187,7 +168,6 @@ pub struct Cli { long, // Fake subcommands. conflicts_with = "add_noqa", - conflicts_with = "autoformat", conflicts_with = "clean", // conflicts_with = "explain", conflicts_with = "generate_shell_completion", @@ -205,7 +185,6 @@ pub struct Cli { value_name = "SHELL", // Fake subcommands. conflicts_with = "add_noqa", - conflicts_with = "autoformat", conflicts_with = "clean", conflicts_with = "explain", // conflicts_with = "generate_shell_completion", @@ -221,7 +200,6 @@ pub struct Cli { long, // Fake subcommands. conflicts_with = "add_noqa", - conflicts_with = "autoformat", conflicts_with = "clean", conflicts_with = "explain", conflicts_with = "generate_shell_completion", @@ -237,7 +215,6 @@ pub struct Cli { long, // Fake subcommands. conflicts_with = "add_noqa", - conflicts_with = "autoformat", conflicts_with = "clean", conflicts_with = "explain", conflicts_with = "generate_shell_completion", @@ -257,7 +234,6 @@ impl Cli { ( Arguments { add_noqa: self.add_noqa, - autoformat: self.autoformat, clean: self.clean, config: self.config, diff: self.diff, @@ -319,7 +295,6 @@ fn resolve_bool_arg(yes: bool, no: bool) -> Option { #[allow(clippy::struct_excessive_bools)] pub struct Arguments { pub add_noqa: bool, - pub autoformat: bool, pub clean: bool, pub config: Option, pub diff: bool, diff --git a/src/commands.rs b/src/commands.rs index 1506bf345d..9e48eb6adb 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -20,7 +20,7 @@ use crate::cache::DEFAULT_CACHE_DIR_NAME; use crate::checks::{CheckCode, CheckKind}; use crate::cli::Overrides; use crate::iterators::par_iter; -use crate::linter::{add_noqa_to_path, autoformat_path, lint_path, lint_stdin, Diagnostics}; +use crate::linter::{add_noqa_to_path, lint_path, lint_stdin, Diagnostics}; use crate::logging::LogLevel; use crate::message::Message; use crate::resolver::{FileDiscovery, PyprojectDiscovery}; @@ -210,45 +210,6 @@ pub fn add_noqa( Ok(modifications) } -/// Automatically format a collection of files. -pub fn autoformat( - files: &[PathBuf], - pyproject_strategy: &PyprojectDiscovery, - file_strategy: &FileDiscovery, - overrides: &Overrides, -) -> Result { - // Collect all the files to format. - let start = Instant::now(); - let (paths, resolver) = - resolver::python_files_in_path(files, pyproject_strategy, file_strategy, overrides)?; - let duration = start.elapsed(); - debug!("Identified files to lint in: {:?}", duration); - - // Validate the `Settings` and return any errors. - resolver.validate(pyproject_strategy)?; - - let start = Instant::now(); - let modifications = par_iter(&paths) - .flatten() - .filter_map(|entry| { - let path = entry.path(); - let settings = resolver.resolve(path, pyproject_strategy); - match autoformat_path(path, settings) { - Ok(()) => Some(()), - Err(e) => { - error!("Failed to autoformat {}: {e}", path.to_string_lossy()); - None - } - } - }) - .count(); - - let duration = start.elapsed(); - debug!("Auto-formatted files in: {:?}", duration); - - Ok(modifications) -} - /// Print the user-facing configuration settings. pub fn show_settings( files: &[PathBuf], diff --git a/src/linter.rs b/src/linter.rs index cc48db88dd..abb24d1423 100644 --- a/src/linter.rs +++ b/src/linter.rs @@ -23,7 +23,6 @@ use crate::directives::Directives; use crate::message::{Message, Source}; use crate::noqa::add_noqa; use crate::settings::{flags, Settings}; -use crate::source_code_generator::SourceCodeGenerator; use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; use crate::{cache, directives, fs, rustpython_helpers}; @@ -290,32 +289,6 @@ pub fn add_noqa_to_path(path: &Path, settings: &Settings) -> Result { ) } -/// Apply autoformatting to the source code at the given `Path`. -pub fn autoformat_path(path: &Path, settings: &Settings) -> Result<()> { - // Validate the `Settings` and return any errors. - settings.validate()?; - - // Read the file from disk. - let contents = fs::read_file(path)?; - - // Tokenize once. - let tokens: Vec = rustpython_helpers::tokenize(&contents); - - // Map row and column locations to byte slices (lazily). - let locator = SourceCodeLocator::new(&contents); - - // Detect the current code style (lazily). - let stylist = SourceCodeStyleDetector::from_contents(&contents, &locator); - - // Generate the AST. - let python_ast = rustpython_helpers::parse_program_tokens(tokens, "")?; - let mut generator = SourceCodeGenerator::new(stylist.indentation(), stylist.quote()); - generator.unparse_suite(&python_ast); - write(path, generator.generate()?)?; - - Ok(()) -} - /// Generate a list of `Check` violations from source code content derived from /// stdin. pub fn lint_stdin( diff --git a/src/main_native.rs b/src/main_native.rs index 6e0cc545e5..76126a619e 100644 --- a/src/main_native.rs +++ b/src/main_native.rs @@ -235,12 +235,6 @@ pub(crate) fn inner_main() -> Result { if modifications > 0 && log_level >= LogLevel::Default { println!("Added {modifications} noqa directives."); } - } else if cli.autoformat { - let modifications = - commands::autoformat(&cli.files, &pyproject_strategy, &file_strategy, &overrides)?; - if modifications > 0 && log_level >= LogLevel::Default { - println!("Formatted {modifications} files."); - } } else { let is_stdin = cli.files == vec![PathBuf::from("-")];