From 539a6ab7f808bac228bad3097e0ebe473fa66443 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 18 Nov 2024 11:27:38 +0100 Subject: [PATCH 1/2] Remove the deprecated `E999` rule code --- crates/ruff/tests/integration_test.rs | 23 +------------------ ...ow_settings__display_default_settings.snap | 2 -- crates/ruff_linter/src/codes.rs | 3 ++- .../src/rules/pycodestyle/rules/errors.rs | 18 ++++++++------- crates/ruff_macros/src/violation.rs | 4 ++++ crates/ruff_workspace/src/configuration.rs | 11 +++------ ruff.schema.json | 2 -- 7 files changed, 20 insertions(+), 43 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 034b35321a1a3..759df792b3a1c 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -840,7 +840,7 @@ fn stdin_multiple_parse_error() { #[test] fn parse_error_not_included() { - // Select any rule except for `E999`, syntax error should still be shown. + // Parse errors are always shown let mut cmd = RuffCheck::default().args(["--select=I"]).build(); assert_cmd_snapshot!(cmd .pass_stdin("foo =\n"), @r" @@ -859,27 +859,6 @@ fn parse_error_not_included() { "); } -#[test] -fn deprecated_parse_error_selection() { - let mut cmd = RuffCheck::default().args(["--select=E999"]).build(); - assert_cmd_snapshot!(cmd - .pass_stdin("foo =\n"), @r" - success: false - exit_code: 1 - ----- stdout ----- - -:1:6: SyntaxError: Expected an expression - | - 1 | foo = - | ^ - | - - Found 1 error. - - ----- stderr ----- - warning: Rule `E999` is deprecated and will be removed in a future release. Syntax errors will always be shown regardless of whether this rule is selected or not. - "); -} - #[test] fn full_output_preview() { let mut cmd = RuffCheck::default().args(["--preview"]).build(); diff --git a/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap b/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap index f2d4c8556ada6..dc4fad00a75d7 100644 --- a/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap +++ b/crates/ruff/tests/snapshots/show_settings__display_default_settings.snap @@ -88,7 +88,6 @@ linter.rules.enabled = [ ambiguous-class-name (E742), ambiguous-function-name (E743), io-error (E902), - syntax-error (E999), unused-import (F401), import-shadowed-by-loop-var (F402), undefined-local-with-import-star (F403), @@ -150,7 +149,6 @@ linter.rules.should_fix = [ ambiguous-class-name (E742), ambiguous-function-name (E743), io-error (E902), - syntax-error (E999), unused-import (F401), import-shadowed-by-loop-var (F402), undefined-local-with-import-star (F403), diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 4405757aa3b63..5f940cdecfab9 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -126,7 +126,8 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pycodestyle, "E742") => (RuleGroup::Stable, rules::pycodestyle::rules::AmbiguousClassName), (Pycodestyle, "E743") => (RuleGroup::Stable, rules::pycodestyle::rules::AmbiguousFunctionName), (Pycodestyle, "E902") => (RuleGroup::Stable, rules::pycodestyle::rules::IOError), - (Pycodestyle, "E999") => (RuleGroup::Deprecated, rules::pycodestyle::rules::SyntaxError), + #[allow(deprecated)] + (Pycodestyle, "E999") => (RuleGroup::Removed, rules::pycodestyle::rules::SyntaxError), // pycodestyle warnings (Pycodestyle, "W191") => (RuleGroup::Stable, rules::pycodestyle::rules::TabIndentation), diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/errors.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/errors.rs index 225840b33837f..d96de51762129 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/errors.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/errors.rs @@ -39,8 +39,8 @@ impl Violation for IOError { } } -/// ## Deprecated -/// This rule has been deprecated and will be removed in a future release. Syntax errors will +/// ## Removed +/// This rule has been removed. Syntax errors will /// always be shown regardless of whether this rule is selected or not. /// /// ## What it does @@ -63,14 +63,16 @@ impl Violation for IOError { /// ## References /// - [Python documentation: Syntax Errors](https://docs.python.org/3/tutorial/errors.html#syntax-errors) #[violation] -pub struct SyntaxError { - pub message: String, -} +#[deprecated(note = "E999 has been removed")] +pub struct SyntaxError; +#[allow(deprecated)] impl Violation for SyntaxError { - #[derive_message_formats] fn message(&self) -> String { - let SyntaxError { message } = self; - format!("SyntaxError: {message}") + unreachable!("E999 has been removed") + } + + fn message_formats() -> &'static [&'static str] { + &["SyntaxError"] } } diff --git a/crates/ruff_macros/src/violation.rs b/crates/ruff_macros/src/violation.rs index 028a5e5a41330..93a9efa5bd7be 100644 --- a/crates/ruff_macros/src/violation.rs +++ b/crates/ruff_macros/src/violation.rs @@ -53,6 +53,7 @@ pub(crate) fn violation(violation: &ItemStruct) -> Result { #[derive(Debug, PartialEq, Eq)] #violation + #[allow(deprecated)] #[automatically_derived] impl From<#ident> for ruff_diagnostics::DiagnosticKind { fn from(value: #ident) -> Self { @@ -71,12 +72,15 @@ pub(crate) fn violation(violation: &ItemStruct) -> Result { #[derive(Debug, PartialEq, Eq)] #violation + #[automatically_derived] + #[allow(deprecated)] impl #ident { pub fn explanation() -> Option<&'static str> { Some(#explanation) } } + #[allow(deprecated)] #[automatically_derived] impl From<#ident> for ruff_diagnostics::DiagnosticKind { fn from(value: #ident) -> Self { diff --git a/crates/ruff_workspace/src/configuration.rs b/crates/ruff_workspace/src/configuration.rs index 27422c1740021..56b8f479dfb35 100644 --- a/crates/ruff_workspace/src/configuration.rs +++ b/crates/ruff_workspace/src/configuration.rs @@ -1000,13 +1000,9 @@ impl LintConfiguration { if preview.mode.is_disabled() { for selection in deprecated_selectors.iter().sorted() { let (prefix, code) = selection.prefix_and_code(); - let rule = format!("{prefix}{code}"); - let mut message = - format!("Rule `{rule}` is deprecated and will be removed in a future release."); - if matches!(rule.as_str(), "E999") { - message.push_str(" Syntax errors will always be shown regardless of whether this rule is selected or not."); - } - warn_user_once_by_message!("{message}"); + warn_user_once_by_message!( + "Rule `{prefix}{code}` is deprecated and will be removed in a future release." + ); } } else { let deprecated_selectors = deprecated_selectors.iter().sorted().collect::>(); @@ -1632,7 +1628,6 @@ mod tests { Rule::AmbiguousClassName, Rule::AmbiguousFunctionName, Rule::IOError, - Rule::SyntaxError, Rule::TabIndentation, Rule::TrailingWhitespace, Rule::MissingNewlineAtEndOfFile, diff --git a/ruff.schema.json b/ruff.schema.json index 856b434f0547a..f46b1455f0fdd 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3112,8 +3112,6 @@ "E9", "E90", "E902", - "E99", - "E999", "EM", "EM1", "EM10", From d1cd09096e96154c547b1aeb85a275468cd8d733 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 19 Nov 2024 12:11:48 +0000 Subject: [PATCH 2/2] two other minor changes --- python/ruff-ecosystem/ruff_ecosystem/defaults.py | 3 +-- scripts/check_ecosystem.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/python/ruff-ecosystem/ruff_ecosystem/defaults.py b/python/ruff-ecosystem/ruff_ecosystem/defaults.py index fb7e84985a449..90d12a487b575 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/defaults.py +++ b/python/ruff-ecosystem/ruff_ecosystem/defaults.py @@ -34,8 +34,7 @@ repo=Repository(owner="bokeh", name="bokeh", ref="branch-3.3"), check_options=CheckOptions(select="ALL"), ), - # Disabled due to use of explicit `select` with `E999`, which is no longer - # supported in `--preview`. + # Disabled due to use of explicit `select` with `E999`, which has been removed. # See: https://github.com/astral-sh/ruff/pull/12129 # Project( # repo=Repository(owner="demisto", name="content", ref="master"), diff --git a/scripts/check_ecosystem.py b/scripts/check_ecosystem.py index e9b38d3d4e136..d7fb1837de460 100755 --- a/scripts/check_ecosystem.py +++ b/scripts/check_ecosystem.py @@ -126,8 +126,7 @@ async def _get_commit(self: Self, checkout_dir: Path) -> str: Repository("binary-husky", "gpt_academic", "master"), Repository("bloomberg", "pytest-memray", "main"), Repository("bokeh", "bokeh", "branch-3.3", select="ALL"), - # Disabled due to use of explicit `select` with `E999`, which is no longer - # supported in `--preview`. + # Disabled due to use of explicit `select` with `E999`, which has been removed. # See: https://github.com/astral-sh/ruff/pull/12129 # Repository("demisto", "content", "master"), Repository("docker", "docker-py", "main"),