From bf53bc42564dcfb28c28d135e23455f78c7e1249 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 7 Jun 2025 11:30:45 -0500 Subject: [PATCH] [syntax errors] Stabilize version-specific unsupported syntax errors (#18522) --- crates/ruff/tests/lint.rs | 11 ++++++----- crates/ruff_linter/src/linter.rs | 8 ++------ crates/ruff_linter/src/preview.rs | 5 ----- crates/ruff_wasm/tests/api.rs | 2 +- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/crates/ruff/tests/lint.rs b/crates/ruff/tests/lint.rs index 49191f5099..fa60551625 100644 --- a/crates/ruff/tests/lint.rs +++ b/crates/ruff/tests/lint.rs @@ -5436,14 +5436,15 @@ match 2: print("it's one") "# ), - @r" - success: true - exit_code: 0 + @r###" + success: false + exit_code: 1 ----- stdout ----- - All checks passed! + test.py:2:1: SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10) + Found 1 error. ----- stderr ----- - " + "### ); // syntax error on 3.9 with preview diff --git a/crates/ruff_linter/src/linter.rs b/crates/ruff_linter/src/linter.rs index 2b31495b2a..422c1348c5 100644 --- a/crates/ruff_linter/src/linter.rs +++ b/crates/ruff_linter/src/linter.rs @@ -30,7 +30,7 @@ use crate::fix::{FixResult, fix_file}; use crate::message::Message; use crate::noqa::add_noqa; use crate::package::PackageRoot; -use crate::preview::{is_py314_support_enabled, is_unsupported_syntax_enabled}; +use crate::preview::is_py314_support_enabled; use crate::registry::{AsRule, Rule, RuleSet}; #[cfg(any(feature = "test-rules", test))] use crate::rules::ruff::rules::test_rules::{self, TEST_RULES, TestRule}; @@ -447,11 +447,7 @@ pub fn check_path( } } - let syntax_errors = if is_unsupported_syntax_enabled(settings) { - parsed.unsupported_syntax_errors() - } else { - &[] - }; + let syntax_errors = parsed.unsupported_syntax_errors(); diagnostics_to_messages( diagnostics, diff --git a/crates/ruff_linter/src/preview.rs b/crates/ruff_linter/src/preview.rs index 6a3c7e818b..7ed2a03333 100644 --- a/crates/ruff_linter/src/preview.rs +++ b/crates/ruff_linter/src/preview.rs @@ -13,11 +13,6 @@ pub(crate) const fn is_semantic_errors_enabled(settings: &LinterSettings) -> boo settings.preview.is_enabled() } -// https://github.com/astral-sh/ruff/pull/16429 -pub(crate) const fn is_unsupported_syntax_enabled(settings: &LinterSettings) -> bool { - settings.preview.is_enabled() -} - pub(crate) const fn is_py314_support_enabled(settings: &LinterSettings) -> bool { settings.preview.is_enabled() } diff --git a/crates/ruff_wasm/tests/api.rs b/crates/ruff_wasm/tests/api.rs index 32177e6bb6..036a435de0 100644 --- a/crates/ruff_wasm/tests/api.rs +++ b/crates/ruff_wasm/tests/api.rs @@ -65,7 +65,7 @@ fn syntax_error() { fn unsupported_syntax_error() { check!( "match 2:\n case 1: ...", - r#"{"preview": true, "target-version": "py39"}"#, + r#"{"target-version": "py39"}"#, [ExpandedMessage { code: None, message: "SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)".to_string(),