mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Check LinterSettings::preview
for version-related syntax errors (#16429)
This commit is contained in:
parent
4a23756024
commit
3d72138740
3 changed files with 15 additions and 3 deletions
|
@ -172,6 +172,12 @@ pub(crate) fn check(
|
|||
)
|
||||
});
|
||||
|
||||
let unsupported_syntax_errors = if settings.linter.preview.is_enabled() {
|
||||
parsed.unsupported_syntax_errors()
|
||||
} else {
|
||||
&[]
|
||||
};
|
||||
|
||||
let lsp_diagnostics = lsp_diagnostics.chain(
|
||||
show_syntax_errors
|
||||
.then(|| {
|
||||
|
@ -186,7 +192,7 @@ pub(crate) fn check(
|
|||
encoding,
|
||||
)
|
||||
})
|
||||
.chain(parsed.unsupported_syntax_errors().iter().map(|error| {
|
||||
.chain(unsupported_syntax_errors.iter().map(|error| {
|
||||
unsupported_syntax_error_to_lsp_diagnostic(
|
||||
error,
|
||||
&source_kind,
|
||||
|
|
|
@ -205,6 +205,12 @@ impl Workspace {
|
|||
|
||||
let source_code = locator.to_source_code();
|
||||
|
||||
let unsupported_syntax_errors = if self.settings.linter.preview.is_enabled() {
|
||||
parsed.unsupported_syntax_errors()
|
||||
} else {
|
||||
&[]
|
||||
};
|
||||
|
||||
let messages: Vec<ExpandedMessage> = diagnostics
|
||||
.into_iter()
|
||||
.map(|diagnostic| {
|
||||
|
@ -242,7 +248,7 @@ impl Workspace {
|
|||
fix: None,
|
||||
}
|
||||
}))
|
||||
.chain(parsed.unsupported_syntax_errors().iter().map(|error| {
|
||||
.chain(unsupported_syntax_errors.iter().map(|error| {
|
||||
let start_location = source_code.source_location(error.range.start());
|
||||
let end_location = source_code.source_location(error.range.end());
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ fn syntax_error() {
|
|||
fn unsupported_syntax_error() {
|
||||
check!(
|
||||
"match 2:\n case 1: ...",
|
||||
r#"{}"#,
|
||||
r#"{"preview": true}"#,
|
||||
[ExpandedMessage {
|
||||
code: None,
|
||||
message: "SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)".to_string(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue