Server: Allow FixAll action in presence of version-specific syntax errors (#16848)

The single flag `has_syntax_error` on `LinterResult` is replaced with
two (private) flags: `has_valid_syntax` and
`has_no_unsupported_syntax_errors`, which record whether there are
`ParseError`s or `UnsupportedSyntaxError`s, respectively. Only the
former is used to prevent a `FixAll` action.

An attempt has been made to make consistent the usage of the phrases
"valid syntax" (which seems to be used to refer only to _parser_ errors)
and "syntax error" (which refers to both _parser_ errors and
version-specific syntax errors).

Closes #16841
This commit is contained in:
Dylan 2025-03-20 05:09:14 -05:00 committed by GitHub
parent 999fd4f885
commit 74f64d3f96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 111 additions and 73 deletions

View file

@ -10,7 +10,7 @@ use crate::{
};
use ruff_linter::package::PackageRoot;
use ruff_linter::{
linter::{FixerResult, LinterResult},
linter::FixerResult,
packaging::detect_package_root,
settings::{flags, LinterSettings},
};
@ -62,9 +62,7 @@ pub(crate) fn fix_all(
// which is inconsistent with how `ruff check --fix` works.
let FixerResult {
transformed,
result: LinterResult {
has_syntax_error, ..
},
result,
..
} = ruff_linter::linter::lint_fix(
&query.virtual_file_path(),
@ -76,7 +74,7 @@ pub(crate) fn fix_all(
source_type,
)?;
if has_syntax_error {
if result.has_invalid_syntax() {
// If there's a syntax error, then there won't be any fixes to apply.
return Ok(Fixes::default());
}