我们开始使用 pylint 和 flake8。但是,我看到许多人只是添加了一个内联注释来禁用 pylint/flake8 错误/警告。有没有办法忽略这些内联注释并在 pylint 和 flake8 中生成完整的报告?
你可以使用
flake8 --disable-noqa
不知道pylint有没有类似的东西(没能很快找到)
不完全是解决方案,但如果有帮助,您至少可以使
pylint
发出本地禁用检查的警告。鉴于foo.py
:
def foo(l): # noqa: E741 pylint: disable=invalid-name
return l + 1
你可以跑:
pylint --enable locally-disabled foo.py
获得:
************* Module foo
foo.py:1:0: I0011: Locally disabling invalid-name (C0103) (locally-disabled)
foo.py:1:0: C0114: Missing module docstring (missing-module-docstring)
foo.py:1:0: C0104: Disallowed name "foo" (disallowed-name)
foo.py:1:0: C0116: Missing function or method docstring (missing-function-docstring)
foo.py:1:0: C0104: Disallowed name "foo" (disallowed-name)
至少你可以用
I0011
寻找位置。
更新:在评论中,@pierre-sassoulas 写道“启用‘suppressed-message’是 pylint 禁用 noqas 的官方方法”:https://pylint.readthedocs.io/en/latest/user_guide/messages/information/ locally-disabled.html。皮埃尔,谢谢你提到它。
此外,您可能希望启用 https://pylint.readthedocs.io/en/latest/user_guide/messages/information/file-ignored.html,在整个文件被跳过时通知。