Skip to content

Commit a39a1df

Browse files
authored
[FastAPI] Add sub-diagnostic explaining why a fix was unavailable (FAST002) (#22565)
## Summary This PR fixes #22188 by adding autofix skipped reason as diagnostic info. ## Test Plan snapshots are updated accordingly. --------- Signed-off-by: Bhuminjay <bhuminjaysoni@gmail.com>
1 parent e5019b3 commit a39a1df

5 files changed

Lines changed: 6 additions & 0 deletions

crates/ruff_linter/src/rules/fastapi/rules/fastapi_non_annotated_dependency.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ fn create_diagnostic(
284284

285285
if is_default_argument_ellipsis && seen_default {
286286
// For ellipsis after a parameter with default, can't remove the default
287+
diagnostic.info("Automatic fix is unavailable because a required parameter would follow an optional parameter. Consider reordering arguments to enable the fix.");
287288
return Ok(None);
288289
}
289290

@@ -315,6 +316,7 @@ fn create_diagnostic(
315316
}
316317
_ => {
317318
if seen_default {
319+
diagnostic.info("Automatic fix is unavailable because a required parameter would follow an optional parameter. Consider reordering arguments to enable the fix.");
318320
return Ok(None);
319321
}
320322
format!(

crates/ruff_linter/src/rules/fastapi/snapshots/ruff_linter__rules__fastapi__tests__fast-api-non-annotated-dependency_FAST002_0.py.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,4 @@ FAST002 FastAPI dependency without `Annotated`
358358
72 | pass
359359
|
360360
help: Replace with `typing.Annotated`
361+
info: Automatic fix is unavailable because a required parameter would follow an optional parameter. Consider reordering arguments to enable the fix.

crates/ruff_linter/src/rules/fastapi/snapshots/ruff_linter__rules__fastapi__tests__fast-api-non-annotated-dependency_FAST002_0.py_py38.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,4 @@ FAST002 FastAPI dependency without `Annotated`
358358
72 | pass
359359
|
360360
help: Replace with `typing_extensions.Annotated`
361+
info: Automatic fix is unavailable because a required parameter would follow an optional parameter. Consider reordering arguments to enable the fix.

crates/ruff_linter/src/rules/fastapi/snapshots/ruff_linter__rules__fastapi__tests__fast-api-non-annotated-dependency_FAST002_2.py.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ FAST002 FastAPI dependency without `Annotated`
273273
85 | another_optional_param: int = Query(42, description="Another optional"),
274274
|
275275
help: Replace with `typing.Annotated`
276+
info: Automatic fix is unavailable because a required parameter would follow an optional parameter. Consider reordering arguments to enable the fix.
276277

277278
FAST002 [*] FastAPI dependency without `Annotated`
278279
--> FAST002_2.py:85:5

crates/ruff_linter/src/rules/fastapi/snapshots/ruff_linter__rules__fastapi__tests__fast-api-non-annotated-dependency_FAST002_2.py_py38.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ FAST002 FastAPI dependency without `Annotated`
273273
85 | another_optional_param: int = Query(42, description="Another optional"),
274274
|
275275
help: Replace with `typing_extensions.Annotated`
276+
info: Automatic fix is unavailable because a required parameter would follow an optional parameter. Consider reordering arguments to enable the fix.
276277

277278
FAST002 [*] FastAPI dependency without `Annotated`
278279
--> FAST002_2.py:85:5

0 commit comments

Comments
 (0)