mirror of https://github.com/astral-sh/ruff
[syntax errors] Stabilize version-specific unsupported syntax errors (#18522)
This commit is contained in:
parent
9f2ae1f568
commit
bf53bc4256
|
|
@ -5436,14 +5436,15 @@ match 2:
|
||||||
print("it's one")
|
print("it's one")
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
@r"
|
@r###"
|
||||||
success: true
|
success: false
|
||||||
exit_code: 0
|
exit_code: 1
|
||||||
----- stdout -----
|
----- 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 -----
|
----- stderr -----
|
||||||
"
|
"###
|
||||||
);
|
);
|
||||||
|
|
||||||
// syntax error on 3.9 with preview
|
// syntax error on 3.9 with preview
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ use crate::fix::{FixResult, fix_file};
|
||||||
use crate::message::Message;
|
use crate::message::Message;
|
||||||
use crate::noqa::add_noqa;
|
use crate::noqa::add_noqa;
|
||||||
use crate::package::PackageRoot;
|
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};
|
use crate::registry::{AsRule, Rule, RuleSet};
|
||||||
#[cfg(any(feature = "test-rules", test))]
|
#[cfg(any(feature = "test-rules", test))]
|
||||||
use crate::rules::ruff::rules::test_rules::{self, TEST_RULES, TestRule};
|
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) {
|
let syntax_errors = parsed.unsupported_syntax_errors();
|
||||||
parsed.unsupported_syntax_errors()
|
|
||||||
} else {
|
|
||||||
&[]
|
|
||||||
};
|
|
||||||
|
|
||||||
diagnostics_to_messages(
|
diagnostics_to_messages(
|
||||||
diagnostics,
|
diagnostics,
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,6 @@ pub(crate) const fn is_semantic_errors_enabled(settings: &LinterSettings) -> boo
|
||||||
settings.preview.is_enabled()
|
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 {
|
pub(crate) const fn is_py314_support_enabled(settings: &LinterSettings) -> bool {
|
||||||
settings.preview.is_enabled()
|
settings.preview.is_enabled()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ fn syntax_error() {
|
||||||
fn unsupported_syntax_error() {
|
fn unsupported_syntax_error() {
|
||||||
check!(
|
check!(
|
||||||
"match 2:\n case 1: ...",
|
"match 2:\n case 1: ...",
|
||||||
r#"{"preview": true, "target-version": "py39"}"#,
|
r#"{"target-version": "py39"}"#,
|
||||||
[ExpandedMessage {
|
[ExpandedMessage {
|
||||||
code: None,
|
code: None,
|
||||||
message: "SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)".to_string(),
|
message: "SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)".to_string(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue