以下是来自pylint的文档:
--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]
Run Code Online (Sandbox Code Playgroud)
然而,我没有运气让目录部分工作.
我有一个名为migrations的目录,它有django-south迁移文件.当我输入--ignore = migrations时,它仍然会在迁移目录中的文件中向我提供错误/警告.
难道这--ignore不适用于目录吗?
如果我甚至可以使用regexp来匹配被忽略的文件,那么django-south文件都被命名为0001_something,0002_something ...
由于我无法通过目录来忽略工作,我只是简单地放在# pylint: disable-msg-cat=WCREFI每个迁移文件的顶部,忽略所有的pylint错误,警告和信息.
mar*_*eed 25
添加:
[MASTER]
ignore=migrations
Run Code Online (Sandbox Code Playgroud)
我的.pylintrc适用于pylint 0.25.我的问题是PyDev,它似乎不尊重我的设置.我认为这是因为它正在运行pylint per-file,我认为它绕过'ignore'检查 - 无论是模块/目录还是文件.从PyDev调用pylint看起来像:
/path/to/site-packages/pylint/lint.py --include-ids=y /path/to/project/migrations/0018_migration.py
Run Code Online (Sandbox Code Playgroud)
小智 15
添加到Fabien 的答案中,--ignore-paths语法如下所示。
ignore-paths=^src/experiments/.*$,
^src/ingredients/.*$,
^src/scripts/.*$,
^src/tests/.*$
Run Code Online (Sandbox Code Playgroud)
如果您想在您的 中配置它pyproject.toml,配置将如下所示:
[tool.pylint.MASTER]
ignore-paths = '^src/experiments/.*$'
Run Code Online (Sandbox Code Playgroud)
https://github.com/PyCQA/pylint/issues/2686#issuecomment-864585778
max*_*max 10
您不能提供路径,只能提供目录的"basename".例如,使用--ignore=lib而不是--ignore-=appengine-toolkit/gaetk/lib.
问题是你会忽略所有名为的目录lib.
小智 8
截至目前,--ignore不在目录上工作(GitHub 上有一个未解决的问题,Ignore 子句不忽略目录 #2686)。
事实证明,只针对黑名单测试了文件名,而不是整个路径。(正如在同一个拉取请求中所指出的:geajack 的评论)
该选项--ignore-patterns有同样的问题,但在我检查时尝试修复它(添加ignore-paths以匹配完整路径 #3266)
在您的情况下,现在最好的解决方案是使用正则表达式来匹配您想要的文件模式,这也是我的情况。由于我不太精通正则表达式,因此我使用了我推荐的Regex101。
尽管这是一个古老的问题,但是当我们搜索堆栈溢出时,它出现在列表的顶部,因此我在此处发布我们的解决方案,希望它可能对其他人有用。
要忽略名为的目录树下的子目录3rdparty,我们将以下ignore-patterns条目添加到中的[MASTER]条目中.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
Run Code Online (Sandbox Code Playgroud)
这解决了pylint-1.7.1的问题。
最初,我们对注释中的“基本名称”子句感到困惑。显然,它确实接受带有通配符的路径。至少它对我们有用。你的旅费可能会改变。