Run pylint plugin on specific file names only?

Viewed 62

I created a pylint plugin. I want just this plugin to only run on modules that have a very specific name. For example, only run the following UniqueReturnChecker if the file is named checkme.py

class UniqueReturnChecker(BaseChecker):
    __implements__ = IAstroidChecker

    name = 'unique-returns'
    priority = -1

    def visit_return(self, node: nodes.Return) -> None:
        pass

    - - - snipped - - -

How can I accomplish this?

1 Answers

I ended up doing the following which is working great:

class UniqueReturnChecker(BaseChecker):
    __implements__ = IAstroidChecker

    name = 'unique-returns'
    priority = -1

    def visit_return(self, node: nodes.Return) -> None:
        import pathlib
        if pathlib.PurePath(node.root().file).name == 'checkme.py':
            # do the check

    - - - snipped - - -
Related