-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LOG015 to detect use of the root logger #96
Conversation
Fixes #87 |
Please add a changelog note. |
As a complementary check, I'd suggest expanding |
I think that depends on whether
So idk if we should recommend it? Or maybe this is just a case of the online docs being subpar and there being 0 risk that it gets deprecated or anything in the future. If wanting the root logger is bad 99% of the time then outlawing ~all ways of accessing it and requiring Of course also an option to add a separate opt-in check for |
done! ✔️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gonna fix up and merge this now, some review with changes that I will apply.
fb107c1
to
a2e6515
Compare
) or ( | ||
isinstance(node.func, ast.Name) | ||
and node.func.id in logger_methods | ||
and self._from_imports.get(node.func.id) == "logging" | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expanded the check to include constructs like from logging import info
because it was easy, though I don't think there will be much use of that pattern
] | ||
|
||
|
||
run_ignore_log015 = partial(run, ignore=("LOG015",)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I preferred an alias function rather than adding a base class. No need for inheritance here.
def test_root_call_alias(self): | ||
results = run( | ||
"""\ | ||
import logging as loglog | ||
loglog.info(...) | ||
""" | ||
) | ||
assert results == [ | ||
(2, 0, "LOG015 avoid logging calls on the root logger"), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split this test in two, the second part being test_logger_call
. Tests should cover only one thing, so they can fail atomically.
Released in 1.6.0. Great work, thank you! |
Thank you for thorough review & cleanup! |
The implementation of the check itself is super simple. But unsurprisingly it gives errors on tons of the examples on the other test checks. I first resolved it in
TestLOG003
by actually adding the errors, but as you can see in the first commit that's not really tenable - so I instead added a way to ignore errors when running tests.None of the
TestLOG009
cases givesLOG015
since it only checks the calls inlogger_methods
. I don't think it's worth being that thorough though, but would be straightforward to extend the check.It also remains a decision point on whether this check should be enabled by default or not, if you want me to make it ignored by default I can implement that as well.