mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-03 15:15:33 +00:00
Avoid syntax error notification for source code actions (#12148)
## Summary This PR avoids the error notification if a user selects the source code actions and there's a syntax error in the source. Before https://github.com/astral-sh/ruff/pull/12134, the change would've been different. But that PR disables generating fixes if there's a syntax error. This means that we can return an empty map instead as there won't be any fixes in the diagnostics returned by the `lint_fix` function. For reference, following are the screenshot as on `main` with the error: **VS Code:** <img width="1715" alt="Screenshot 2024-07-02 at 16 39 59" src="62f3e99b
-0b0c-4608-84a2-26aeabcc6933"> **Neovim:** <img width="1717" alt="Screenshot 2024-07-02 at 16 38 50" src="5d637c36
-d7f8-4a3b-8011-9a89708919a8"> fixes: #11931 ## Test Plan Considering the following code snippet where there are two diagnostics (syntax error and useless semicolon `E703`): ```py x; y = ``` ### VS Code943537fc
-ed8d-448d-8a36-1e34536c4f3e ### Neovim4e6f3372
-6e5b-4380-8919-6221066efd5b
This commit is contained in:
parent
d870720841
commit
e6e09ea93a
1 changed files with 4 additions and 5 deletions
|
@ -69,8 +69,7 @@ pub(crate) fn fix_all(
|
||||||
let FixerResult {
|
let FixerResult {
|
||||||
transformed,
|
transformed,
|
||||||
result: LinterResult {
|
result: LinterResult {
|
||||||
has_syntax_error: has_error,
|
has_syntax_error, ..
|
||||||
..
|
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
} = ruff_linter::linter::lint_fix(
|
} = ruff_linter::linter::lint_fix(
|
||||||
|
@ -83,9 +82,9 @@ pub(crate) fn fix_all(
|
||||||
source_type,
|
source_type,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if has_error {
|
if has_syntax_error {
|
||||||
// abort early if a parsing error occurred
|
// If there's a syntax error, then there won't be any fixes to apply.
|
||||||
return Err(anyhow::anyhow!("A parsing error occurred during `fix_all`"));
|
return Ok(Fixes::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
// fast path: if `transformed` is still borrowed, no changes were made and we can return early
|
// fast path: if `transformed` is still borrowed, no changes were made and we can return early
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue