From ed2866cebd00b75cceb0f6f9a59742ee27368ee6 Mon Sep 17 00:00:00 2001 From: Tibor Reiss Date: Thu, 8 Feb 2024 20:16:31 +0100 Subject: [PATCH] Remove deprecated configurations 'show-source' and 'no-show-source' --- crates/ruff/src/args.rs | 36 +------ crates/ruff/tests/deprecation.rs | 118 +-------------------- crates/ruff_workspace/src/configuration.rs | 13 --- crates/ruff_workspace/src/options.rs | 15 --- docs/configuration.md | 4 - ruff.schema.json | 8 -- 6 files changed, 5 insertions(+), 189 deletions(-) diff --git a/crates/ruff/src/args.rs b/crates/ruff/src/args.rs index 1a9f62b834ddd2..6f7a207f4b14c3 100644 --- a/crates/ruff/src/args.rs +++ b/crates/ruff/src/args.rs @@ -100,13 +100,6 @@ pub struct CheckCommand { unsafe_fixes: bool, #[arg(long, overrides_with("unsafe_fixes"), hide = true)] no_unsafe_fixes: bool, - /// Show violations with source code. - /// Use `--no-show-source` to disable. - /// (Deprecated: use `--output-format=full` or `--output-format=concise` instead of `--show-source` and `--no-show-source`, respectively) - #[arg(long, overrides_with("no_show_source"))] - show_source: bool, - #[clap(long, overrides_with("show_source"), hide = true)] - no_show_source: bool, /// Show an enumeration of all fixed lint violations. /// Use `--no-show-fixes` to disable. #[arg(long, overrides_with("no_show_fixes"))] @@ -311,7 +304,6 @@ pub struct CheckCommand { long, // Unsupported default-command arguments. conflicts_with = "diff", - conflicts_with = "show_source", conflicts_with = "watch", )] pub statistics: bool, @@ -560,7 +552,6 @@ impl CheckCommand { force_exclude: resolve_bool_arg(self.force_exclude, self.no_force_exclude), output_format: resolve_output_format( self.output_format, - resolve_bool_arg(self.show_source, self.no_show_source), resolve_bool_arg(self.preview, self.no_preview).unwrap_or_default(), ), show_fixes: resolve_bool_arg(self.show_fixes, self.no_show_fixes), @@ -616,32 +607,11 @@ fn resolve_bool_arg(yes: bool, no: bool) -> Option { fn resolve_output_format( output_format: Option, - show_sources: Option, preview: bool, ) -> Option { - Some(match (output_format, show_sources) { - (Some(o), None) => o, - (Some(SerializationFormat::Grouped), Some(true)) => { - warn_user!("`--show-source` with `--output-format=grouped` is deprecated, and will not show source files. Use `--output-format=full` to show source information."); - SerializationFormat::Grouped - } - (Some(fmt), Some(true)) => { - warn_user!("The `--show-source` argument is deprecated and has been ignored in favor of `--output-format={fmt}`."); - fmt - } - (Some(fmt), Some(false)) => { - warn_user!("The `--no-show-source` argument is deprecated and has been ignored in favor of `--output-format={fmt}`."); - fmt - } - (None, Some(true)) => { - warn_user!("The `--show-source` argument is deprecated. Use `--output-format=full` instead."); - SerializationFormat::Full - } - (None, Some(false)) => { - warn_user!("The `--no-show-source` argument is deprecated. Use `--output-format=concise` instead."); - SerializationFormat::Concise - } - (None, None) => return None + Some(match output_format { + Some(o) => o, + None => return None }).map(|format| match format { SerializationFormat::Text => { warn_user!("`--output-format=text` is deprecated. Use `--output-format=full` or `--output-format=concise` instead. `text` will be treated as `{}`.", SerializationFormat::default(preview)); diff --git a/crates/ruff/tests/deprecation.rs b/crates/ruff/tests/deprecation.rs index 0d3215d3bdeb3c..973f0047ac254e 100644 --- a/crates/ruff/tests/deprecation.rs +++ b/crates/ruff/tests/deprecation.rs @@ -9,133 +9,20 @@ const BIN_NAME: &str = "ruff"; const STDIN: &str = "l = 1"; -fn ruff_check(show_source: Option, output_format: Option) -> Command { +fn ruff_check(output_format: Option) -> Command { let mut cmd = Command::new(get_cargo_bin(BIN_NAME)); let output_format = output_format.unwrap_or(format!("{}", SerializationFormat::default(false))); cmd.arg("--output-format"); cmd.arg(output_format); cmd.arg("--no-cache"); - match show_source { - Some(true) => { - cmd.arg("--show-source"); - } - Some(false) => { - cmd.arg("--no-show-source"); - } - None => {} - } cmd.arg("-"); cmd } -#[test] -fn ensure_show_source_is_deprecated() { - assert_cmd_snapshot!(ruff_check(Some(true), None).pass_stdin(STDIN), @r###" - success: false - exit_code: 1 - ----- stdout ----- - -:1:1: E741 Ambiguous variable name: `l` - Found 1 error. - - ----- stderr ----- - warning: The `--show-source` argument is deprecated and has been ignored in favor of `--output-format=concise`. - "###); -} - -#[test] -fn ensure_no_show_source_is_deprecated() { - assert_cmd_snapshot!(ruff_check(Some(false), None).pass_stdin(STDIN), @r###" - success: false - exit_code: 1 - ----- stdout ----- - -:1:1: E741 Ambiguous variable name: `l` - Found 1 error. - - ----- stderr ----- - warning: The `--no-show-source` argument is deprecated and has been ignored in favor of `--output-format=concise`. - "###); -} - #[test] fn ensure_output_format_is_deprecated() { - assert_cmd_snapshot!(ruff_check(None, Some("text".into())).pass_stdin(STDIN), @r###" - success: false - exit_code: 1 - ----- stdout ----- - -:1:1: E741 Ambiguous variable name: `l` - Found 1 error. - - ----- stderr ----- - warning: `--output-format=text` is deprecated. Use `--output-format=full` or `--output-format=concise` instead. `text` will be treated as `concise`. - "###); -} - -#[test] -fn ensure_output_format_overrides_show_source() { - assert_cmd_snapshot!(ruff_check(Some(true), Some("concise".into())).pass_stdin(STDIN), @r###" - success: false - exit_code: 1 - ----- stdout ----- - -:1:1: E741 Ambiguous variable name: `l` - Found 1 error. - - ----- stderr ----- - warning: The `--show-source` argument is deprecated and has been ignored in favor of `--output-format=concise`. - "###); -} - -#[test] -fn ensure_full_output_format_overrides_no_show_source() { - assert_cmd_snapshot!(ruff_check(Some(false), Some("full".into())).pass_stdin(STDIN), @r###" - success: false - exit_code: 1 - ----- stdout ----- - -:1:1: E741 Ambiguous variable name: `l` - | - 1 | l = 1 - | ^ E741 - | - - Found 1 error. - - ----- stderr ----- - warning: The `--no-show-source` argument is deprecated and has been ignored in favor of `--output-format=full`. - "###); -} - -#[test] -fn ensure_output_format_uses_concise_over_no_show_source() { - assert_cmd_snapshot!(ruff_check(Some(false), Some("concise".into())).pass_stdin(STDIN), @r###" - success: false - exit_code: 1 - ----- stdout ----- - -:1:1: E741 Ambiguous variable name: `l` - Found 1 error. - - ----- stderr ----- - warning: The `--no-show-source` argument is deprecated and has been ignored in favor of `--output-format=concise`. - "###); -} - -#[test] -fn ensure_deprecated_output_format_overrides_show_source() { - assert_cmd_snapshot!(ruff_check(Some(true), Some("text".into())).pass_stdin(STDIN), @r###" - success: false - exit_code: 1 - ----- stdout ----- - -:1:1: E741 Ambiguous variable name: `l` - Found 1 error. - - ----- stderr ----- - warning: The `--show-source` argument is deprecated and has been ignored in favor of `--output-format=text`. - warning: `--output-format=text` is deprecated. Use `--output-format=full` or `--output-format=concise` instead. `text` will be treated as `concise`. - "###); -} - -#[test] -fn ensure_deprecated_output_format_overrides_no_show_source() { - assert_cmd_snapshot!(ruff_check(Some(false), Some("text".into())).pass_stdin(STDIN), @r###" + assert_cmd_snapshot!(ruff_check(Some("text".into())).pass_stdin(STDIN), @r###" success: false exit_code: 1 ----- stdout ----- @@ -143,7 +30,6 @@ fn ensure_deprecated_output_format_overrides_no_show_source() { Found 1 error. ----- stderr ----- - warning: The `--no-show-source` argument is deprecated and has been ignored in favor of `--output-format=text`. warning: `--output-format=text` is deprecated. Use `--output-format=full` or `--output-format=concise` instead. `text` will be treated as `concise`. "###); } diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index c41006b09e968b..7edccc5e1f4591 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -421,12 +421,6 @@ impl Configuration { #[allow(deprecated)] let output_format = { - if options.show_source.is_some() { - warn_user_once!( - r#"The `show-source` option has been deprecated in favor of `output-format`'s "full" and "concise" variants. Please update your configuration to use `output-format = ` instead."# - ); - } - options .output_format .map(|format| match format { @@ -436,13 +430,6 @@ impl Configuration { }, other => other }) - .or(options.show_source.map(|show_source| { - if show_source { - SerializationFormat::Full - } else { - SerializationFormat::Concise - } - })) }; Ok(Self { diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index 0a0ed48f47eb07..17200cd61f3f28 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -108,21 +108,6 @@ pub struct Options { #[option(default = "false", value_type = "bool", example = "fix-only = true")] pub fix_only: Option, - /// Whether to show source code snippets when reporting lint violations - /// (overridden by the `--show-source` command-line flag). - #[option( - default = "false", - value_type = "bool", - example = r#" - # By default, always show source code snippets. - show-source = true - "# - )] - #[deprecated( - note = "`show-source` is deprecated and is now part of `output-format` in the form of `full` or `concise` options. Please update your configuration." - )] - pub show_source: Option, - /// Whether to show an enumeration of all fixed lint violations /// (overridden by the `--show-fixes` command-line flag). #[option( diff --git a/docs/configuration.md b/docs/configuration.md index acac5fc29d115b..c614bc6fcab9f5 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -509,10 +509,6 @@ Options: --unsafe-fixes Include fixes that may not retain the original intent of the code. Use `--no-unsafe-fixes` to disable - --show-source - Show violations with source code. Use `--no-show-source` to disable. - (Deprecated: use `--output-format=full` or `--output-format=concise` - instead of `--show-source` and `--no-show-source`, respectively) --show-fixes Show an enumeration of all fixed lint violations. Use `--no-show-fixes` to disable diff --git a/ruff.schema.json b/ruff.schema.json index ec2abdb613faf0..196f6fee82bf07 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -658,14 +658,6 @@ "null" ] }, - "show-source": { - "description": "Whether to show source code snippets when reporting lint violations (overridden by the `--show-source` command-line flag).", - "deprecated": true, - "type": [ - "boolean", - "null" - ] - }, "src": { "description": "The directories to consider when resolving first- vs. third-party imports.\n\nAs an example: given a Python package structure like:\n\n```text my_project ├── pyproject.toml └── src └── my_package ├── __init__.py ├── foo.py └── bar.py ```\n\nThe `./src` directory should be included in the `src` option (e.g., `src = [\"src\"]`), such that when resolving imports, `my_package.foo` is considered a first-party import.\n\nWhen omitted, the `src` directory will typically default to the directory containing the nearest `pyproject.toml`, `ruff.toml`, or `.ruff.toml` file (the \"project root\"), unless a configuration file is explicitly provided (e.g., via the `--config` command-line flag).\n\nThis field supports globs. For example, if you have a series of Python packages in a `python_modules` directory, `src = [\"python_modules/*\"]` would expand to incorporate all of the packages in that directory. User home directory and environment variables will also be expanded.", "type": [