1

I am trying to write simple pylint plugin but getting following error any input.

__init__py

"""
Register all plugin
"""
#!/usr/bin/env python


    from .check_os_walk import check_os_walk
    
    def register(linter):
        """
        entry point for pylint
        :param linter: linter obj
        :return:
        """
        linter.register_checker(CheckOswalk(linter))

check_os_walk.py

#!/usr/bin/env python
import astroid
from pylint.checkers import BaseChecker, utils
from pylint.interfaces import IAstroidChecker


class CheckOswalk(BaseChecker):
    __implements__ = (IAstroidChecker,)

    name = 'no-need-to-call-os-walk'

    msg = {'R100': ('please avoid using os.walk',
                       'os.walk_used',
                       'os.walk use unless it is needed and prefer os.scandir in python3')}

    def visit_name(self, node):
        print(node.parent)
        self.add_message('os.walk_used', node)

dir_traversal.py """ Traverse directory """

#!/usr/bin/env python
import os


def main():
    """
    print directory
    :return:
    """
    cwd = os.getcwd()
    for root, dirs, files in os.walk(cwd, topdown=False):
        for name in files:
            print(os.path.join(root, name))
        for name in dirs:
            print(os.path.join(root, name))


if __name__ == "__main__":
    main()

command venv/bin/pylint --load-plugins=$PWD/'init.py' dir_traversal.py

Error:

venv/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 613, in load_plugin_configuration
    self.add_message("bad-plugin-value", args=(modname, e), line=0)
  File "venv/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 1527, in add_message
    end_col_offset,
  File "venv/lib/python3.6/site-packages/pylint/lint/pylinter.py", line 1456, in _add_one_message
    self.stats.increase_single_module_message_count(self.current_name, msg_cat, 1)
  File "venv/lib/python3.6/site-packages/pylint/utils/linterstats.py", line 296, in increase_single_module_message_count
    self.by_module[modname][type_name] += increase
KeyError: None
user765443
  • 1,856
  • 7
  • 31
  • 56
  • I am having a similar issue. Did you solve your problem? Could use your advice. – akalanka Mar 23 '22 at 17:02
  • Could you please compose an answer with how you modified your code to make it work. All I could do was to copy the custom checker to pylint's checker dir. In my case, I have the register function in the same file of the checker class – akalanka Mar 25 '22 at 15:27

1 Answers1

0

In your __init__.py, CheckOswalk is not defined. It does not crash because it seems the register function is never called either.

Pierre.Sassoulas
  • 3,733
  • 3
  • 33
  • 48