astral-sh / ruff

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

Make logger object name patterns configurable #12613

Open lpulley opened 1 month ago

lpulley commented 1 month ago

Currently, Ruff uses some hard-coded name "patterns" to determine whether a module-local object might be a logger (for the purposes of e.g. flake8-logging-format G rules).

https://github.com/astral-sh/ruff/blob/fc16d8d04d86aa94a8aac14bbb87089b64d443a1/crates/ruff_python_semantic/src/analyze/logging.rs#L60-L74

We've found that we have some loggers called _LOG which aren't matched, and I was disappointed to find that these aren't configurable. Maybe this should be a setting list of regular expressions or globs or something like that?

lpulley commented 1 month ago

I suppose, at the very least, it would be nice to add starts_with("_log") and starts_with("_LOG"), but that seems like a band-aid.

MichaReiser commented 1 month ago

This makes sense to me, at least short-term. The long term goal is to use type inference to detect if a variable is a logger