Skip to content

Commit 3d72138

Browse files
authoredFeb 28, 2025··
Check LinterSettings::preview for version-related syntax errors (#16429)
1 parent 4a23756 commit 3d72138

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed
 

‎crates/ruff_server/src/lint.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ pub(crate) fn check(
172172
)
173173
});
174174

175+
let unsupported_syntax_errors = if settings.linter.preview.is_enabled() {
176+
parsed.unsupported_syntax_errors()
177+
} else {
178+
&[]
179+
};
180+
175181
let lsp_diagnostics = lsp_diagnostics.chain(
176182
show_syntax_errors
177183
.then(|| {
@@ -186,7 +192,7 @@ pub(crate) fn check(
186192
encoding,
187193
)
188194
})
189-
.chain(parsed.unsupported_syntax_errors().iter().map(|error| {
195+
.chain(unsupported_syntax_errors.iter().map(|error| {
190196
unsupported_syntax_error_to_lsp_diagnostic(
191197
error,
192198
&source_kind,

‎crates/ruff_wasm/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ impl Workspace {
205205

206206
let source_code = locator.to_source_code();
207207

208+
let unsupported_syntax_errors = if self.settings.linter.preview.is_enabled() {
209+
parsed.unsupported_syntax_errors()
210+
} else {
211+
&[]
212+
};
213+
208214
let messages: Vec<ExpandedMessage> = diagnostics
209215
.into_iter()
210216
.map(|diagnostic| {
@@ -242,7 +248,7 @@ impl Workspace {
242248
fix: None,
243249
}
244250
}))
245-
.chain(parsed.unsupported_syntax_errors().iter().map(|error| {
251+
.chain(unsupported_syntax_errors.iter().map(|error| {
246252
let start_location = source_code.source_location(error.range.start());
247253
let end_location = source_code.source_location(error.range.end());
248254

‎crates/ruff_wasm/tests/api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn syntax_error() {
6565
fn unsupported_syntax_error() {
6666
check!(
6767
"match 2:\n case 1: ...",
68-
r#"{}"#,
68+
r#"{"preview": true}"#,
6969
[ExpandedMessage {
7070
code: None,
7171
message: "SyntaxError: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)".to_string(),

0 commit comments

Comments
 (0)
Please sign in to comment.