Description
Question
Hi! First: Thanks for supporting and maintaining such a great ecosystem!
My question: I'm trying to make a simple checker around some custom formatting in log strings. I have followed every tutorial I can find from within the last few years, and naturally looked at the guide in the documentation.
However, I am finding that the register
function, described as the way to get your checker actually loaded into pylint, simply is not being called. The module is being loaded, for sure — I can see breakpoints in the top level of the module being hit, but not in the register
function itself. I've tried setting the --load-plugins
argument, I've tried using the load_plugins
setting in pylintrc.
Is there an additional step or constraint missing in the implementation of custom checkers from the docs? Or am I simply making a mistake?
Below is the code for my absolute bare-bones first attempt.
Stored in testchecker.py
:
from astroid import nodes
from pylint.checkers import BaseChecker
breakpoint() # HIT!
class SimpleCheck(BaseChecker):
"""Simple"""
name = "simple-test-check"
msgs = {
"W6900": ("Test", "test-check", "Just a test")
}
options = ( ("fake-option", {
"default": False,
"type": "yn", # EDIT: bool here was not allowed
"metavar": "<y or n>",
"help": "Some fake option"}
),
)
def visit_import(self, _: nodes.Import) -> None:
breakpoint() # NOT HIT!
def register(linter):
breakpoint() # NOT HIT!
linter.register_checker(SimpleCheck(linter))
My file I am linting, lintme.py
:
"""MODULE DOCSTRING"""
import logging
logger = logging.getLogger(__name__)
logger.info("hello world")
Both files are in the same directory, in which I execute:
pylint --load-plugins=testchecker lintme.py
$ pylint --version
pylint 2.14.5
astroid 2.11.7
Python 3.10.4 (main, May 19 2022, 08:51:27) [Clang 13.1.6 (clang-1316.0.21.2.5)]
$ uname -a
Darwin OVO4941L.ovoenergy.local 21.6.0 Darwin Kernel Version 21.6.0: Sat Jun 18 17:07:25 PDT 2022; root:xnu-8020.140.41~1/RELEASE_X86_64 x86_64
Thanks again!
Documentation for future user
I expect the guide to creating a custom checker to contain everything needed to do so, and to have a section highlighting common and easy mistakes (I'm assuming I have made such a mistake)
Additional context
I have searched stack overflow and pre-existing issues on this repo, and not found anyone reporting this.
There is https://stackoverflow.com/questions/71590677/cant-load-custom-pylint-module, but they report getting an error about not finding the module, then succeeding by placing the module in the pylint source. This is not what I am experiencing.