问题
Following is from pylint docs:
--ignore=<file>
Add <file or directory> to the black list. It should be a base name, not a path. You may set this option multiple times. [current: %default]
Yet I'm not having luck getting the directory part work.
I have directory called migrations, which has django-south migration files. As I enter --ignore=migrations it still keeps giving me the errors/warnings in files inside migrations directory.
Could it be that --ignore is not working for directories?
If I could even use regexp to match the ignored files it would work, since django-south files are all named 0001_something, 0002_something...
Since I could not get the ignore by directory to work I have resorted to simply putting # pylint: disable-msg-cat=WCREFI on top of each migration file, which ignores all pylint errors, warnings and infos.
回答1:
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
回答2:
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.
回答3:
Although this is an old question it showed up at the top of the list when we were searching stack overflow so i am posting our solution here in the hopes that it might be useful to someone else.
To ignore subdirectories under a directory tree named 3rdparty, we added the following ignore-patterns entry to the [MASTER] entry in .pylintrc.
# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
# Ignore all .py files under the 3rdparty subdirectory.
ignore-patterns=**/3rdparty/**/*.py
This fixed the problem for pylint-1.7.1.
We were originally confused by the "base names" clause in the comments. Apparently it does accept paths with wildcards. At least it did for us. Your mileage may vary.
回答4:
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.
回答5:
You can then use Bash expansion to your advantage:
--ignore=migrations/{0000..1000}_something
来源:https://stackoverflow.com/questions/2503717/pylint-ignore-by-directory