-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…12638) This adds the `fast-api-unused-path-parameter` lint rule, as described in #12632. I'm still pretty new to rust, so the code can probably be improved, feel free to tell me if there's any changes i should make. Also, i needed to add the `add_parameter` edit function, not sure if it was in the scope of the PR or if i should've made another one.
- Loading branch information
1 parent
80efb86
commit f121f8b
Showing
9 changed files
with
751 additions
and
1 deletion.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
crates/ruff_linter/resources/test/fixtures/fastapi/FAST003.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
from fastapi import FastAPI | ||
|
||
app = FastAPI() | ||
|
||
|
||
# Errors | ||
@app.get("/things/{thing_id}") | ||
async def read_thing(query: str): | ||
return {"query": query} | ||
|
||
|
||
@app.get("/books/isbn-{isbn}") | ||
async def read_thing(): | ||
... | ||
|
||
|
||
@app.get("/things/{thing_id:path}") | ||
async def read_thing(query: str): | ||
return {"query": query} | ||
|
||
|
||
@app.get("/things/{thing_id : path}") | ||
async def read_thing(query: str): | ||
return {"query": query} | ||
|
||
|
||
@app.get("/books/{author}/{title}") | ||
async def read_thing(author: str): | ||
return {"author": author} | ||
|
||
|
||
@app.get("/books/{author_name}/{title}") | ||
async def read_thing(): | ||
... | ||
|
||
|
||
@app.get("/books/{author}/{title}") | ||
async def read_thing(author: str, title: str, /): | ||
return {"author": author, "title": title} | ||
|
||
|
||
@app.get("/books/{author}/{title}/{page}") | ||
async def read_thing( | ||
author: str, | ||
query: str, | ||
): ... | ||
|
||
|
||
@app.get("/books/{author}/{title}") | ||
async def read_thing(): | ||
... | ||
|
||
|
||
@app.get("/books/{author}/{title}") | ||
async def read_thing(*, author: str): | ||
... | ||
|
||
|
||
@app.get("/books/{author}/{title}") | ||
async def read_thing(hello, /, *, author: str): | ||
... | ||
|
||
|
||
@app.get("/things/{thing_id}") | ||
async def read_thing( | ||
query: str, | ||
): | ||
return {"query": query} | ||
|
||
|
||
@app.get("/things/{thing_id}") | ||
async def read_thing( | ||
query: str = "default", | ||
): | ||
return {"query": query} | ||
|
||
|
||
@app.get("/things/{thing_id}") | ||
async def read_thing( | ||
*, query: str = "default", | ||
): | ||
return {"query": query} | ||
|
||
|
||
# OK | ||
@app.get("/things/{thing_id}") | ||
async def read_thing(thing_id: int, query: str): | ||
return {"thing_id": thing_id, "query": query} | ||
|
||
|
||
@app.get("/books/isbn-{isbn}") | ||
async def read_thing(isbn: str): | ||
return {"isbn": isbn} | ||
|
||
|
||
@app.get("/things/{thing_id:path}") | ||
async def read_thing(thing_id: str, query: str): | ||
return {"thing_id": thing_id, "query": query} | ||
|
||
|
||
@app.get("/things/{thing_id : path}") | ||
async def read_thing(thing_id: str, query: str): | ||
return {"thing_id": thing_id, "query": query} | ||
|
||
|
||
@app.get("/books/{author}/{title}") | ||
async def read_thing(author: str, title: str): | ||
return {"author": author, "title": title} | ||
|
||
|
||
@app.get("/books/{author}/{title}") | ||
async def read_thing(*, author: str, title: str): | ||
return {"author": author, "title": title} | ||
|
||
|
||
@app.get("/books/{author}/{title:path}") | ||
async def read_thing(*, author: str, title: str): | ||
return {"author": author, "title": title} | ||
|
||
|
||
# Ignored | ||
@app.get("/things/{thing-id}") | ||
async def read_thing(query: str): | ||
return {"query": query} | ||
|
||
|
||
@app.get("/things/{thing_id!r}") | ||
async def read_thing(query: str): | ||
return {"query": query} | ||
|
||
|
||
@app.get("/things/{thing_id=}") | ||
async def read_thing(query: str): | ||
return {"query": query} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.