Skip to content

New rule: fast-api-unused-path-parameter #12632

@Matthieu-LAURENT39

Description

@Matthieu-LAURENT39

Keywords: fastapi, path parameters

Hello, i've been using ruff for a while and i'm really loving it.
I saw that recently some FastAPI rules have been added, and i would like to suggest a new one, fast-api-unused-path-parameter.
It's pretty simple, it verifies that when defining a route that takes in path parameters, the function has matching arguments.

For example, the following code would trigger the rule, as we define a path parameter named "thing_id", but the function doesn't have an argument named "thing_id":

from fastapi import FastAPI

app = FastAPI()

@app.get("/things/{thing_id}")
async def read_thing(id: int, query: str = None):
    return {"thing_id": id, "query": query}

Also of note is that it should ignore any characters after a : in the path parameter name, so this wouldn't trigger the rule:

...

@app.get("/place/{my_path:path}")
def read_path(my_path):
    ...

If this rule is a good fit for ruff, i'd love to make a PR to implement it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions