pylint ignore by directory

后端 未结 7 1459
南旧
南旧 2020-12-20 11:04

Following is from pylint docs:

--ignore=
    Add  to the black list. It should be a base name, not a path. You may set t         


        
相关标签:
7条回答
  • 2020-12-20 11:15

    You can not give a path but only the "basename" of the directory. E.g. use --ignore=lib instead of --ignore-=appengine-toolkit/gaetk/lib.

    Problem is you will ignore all directories named lib.

    0 讨论(0)
  • 2020-12-20 11:16

    As of right now, --ignore is not working on directories. (There's an open issue on https://github.com/PyCQA/pylint/issues/2686)

    Turns out that only the file name, and not the whole path is tested against the black list. (As pointed in the same pull request: https://github.com/PyCQA/pylint/issues/2686#issuecomment-453450455)

    The option --ignore-patterns has the same problem, but there was an attempt to fix it when I checked. (https://github.com/PyCQA/pylint/pull/3266)

    In your case, the best solution right now would be to use a regular expression to match the patterns you want in your files, which was also my case. As I am not really well-versed in regex, so I used https://regex101.com, which I recommend.

    0 讨论(0)
  • 2020-12-20 11:24

    You can then use Bash expansion to your advantage:

    --ignore=migrations/{0000..1000}_something
    
    0 讨论(0)
  • 2020-12-20 11:29

    it seems you need to do some monkey patch reference, which works for me with pylint version 2.5.3. Just don't know why pylint doesn't have a fix for ignoring paths.

    init-hook=
        sys.path.append(os.getcwd());
        from pylint_ignore import PylintIgnorePaths;
        PylintIgnorePaths('my/thirdparty/subdir', 'my/other/badcode')
    

    then create pylint_ignore.py:

    from pylint.utils import utils
    
    
    class PylintIgnorePaths:
        def __init__(self, *paths):
            self.paths = paths
            self.original_expand_modules = utils.expand_modules
            utils.expand_modules = self.patched_expand
    
        def patched_expand(self, *args, **kwargs):
            result, errors = self.original_expand_modules(*args, **kwargs)
    
            def keep_item(item):
                if any(1 for path in self.paths if item['path'].startswith(path)):
                    return False
    
                return True
    
            result = list(filter(keep_item, result))
    
            return result, errors
    
    0 讨论(0)
  • 2020-12-20 11:38

    Actually with pylint 2.3.1 there is an open issue.

    If you set a directory into the ignore options, it won't ignore it.

    0 讨论(0)
  • 2020-12-20 11:41

    Adding:

    [MASTER]
    ignore=migrations
    

    To my .pylintrc works with pylint 0.25. My problems are with PyDev which (it seems) is not respecting my settings. This is due, I think, to the fact that it's running pylint per-file, which I think bypasses 'ignore' checks - whether for modules/directories or files. The calls to pylint from PyDev look like:

    /path/to/site-packages/pylint/lint.py --include-ids=y /path/to/project/migrations/0018_migration.py
    
    0 讨论(0)
提交回复
热议问题