astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.23k stars 1.04k forks source link

[Feature Request] User-Defined Deprecations? #12693

Open alanhdu opened 1 month ago

alanhdu commented 1 month ago

This is probably a big feature request (and apologies if it has already been asked about), but I am wondering whether there are plans for ruff to allow user-defined / config-defied lint rules?

In particular, I have some internal codebase functions that are deprecated and would like people to move off of. I can certainly try to write a custom CI rule for this, but it'd be super nice if I could somehow configure ruff to detect this (since it's already integrated into our CI).

I admit I haven't fully thought through what this would look like in practice. I'd love a world where I can specify in my toml file something like:

[ruff.deprecated]
rule1 = { function="my.code.deprecated_function", message="This function is deprecated", replacement="some.other.function", safe=False}

Is something like this feasible?

(There's a more general question about a plugin interface -- our codebase is big enough that having custom lint rules is useful, but it's not OSS so upstreaming changes to ruff probably isn't worthwhile and forking ruff to add our own rules seems undesirable).

AlexWaygood commented 1 month ago

Hi, thanks for the feature request! My instinct is that we should probably fold this into the broader discussion in https://github.com/astral-sh/ruff/issues/283, which discusses design principles for plugins/user-specific lints.

MichaReiser commented 1 month ago

I do like the idea and I see generic rules as a first step towards a customizable Ruff that doesn't require plugin support.

This request is similar to https://github.com/astral-sh/ruff/issues/10131. Would Ruff's banned-api work for your use case?