python - Pylint 仅显示警告和错误

标签 python pylint

我想使用 pylint 来检查我的代码,但我只对错误和警告级别感兴趣。有没有办法在命令行或 pylintrc 中做到这一点?

我对过滤给定问题(例如在 MESSAGE CONTROL 中列出所有消息)不感兴趣,我只想让 pylint 忽略 所有 约定并重构消息。

注意:我认为这不是 Using Pylint to display error and warnings 的重复项。

最佳答案

使用 -d/--disable 选项关闭“C”和“R”消息类(约定和重构):

-d <msg ids>, --disable=<msg ids>
                    Disable the message, report, category or checker with
                    the given id(s). You can either give multiple
                    identifiers separated by comma (,) or put this option
                    multiple times (only on the command line, not in the
                    configuration file where it should appear only
                    once).You can also use "--disable=all" to disable
                    everything first and then reenable specific checks.
                    For example, if you want to run only the similarities
                    checker, you can use "--disable=all
                    --enable=similarities". If you want to run only the
                    classes checker, but have no Warning level messages
                    displayed, use"--disable=all --enable=classes
                    --disable=W"

没有 disable 选项(6 个约定,1 个重构,2 个警告,1 个错误):

$ pylint x.py
C:  1, 0: Missing module docstring (missing-docstring)
C:  3, 0: Missing function docstring (missing-docstring)
R:  3, 0: Too many statements (775/50) (too-many-statements)
W:780,15: Redefining name 'path' from outer scope (line 796) (redefined-outer-name)
C:780, 0: Invalid function name "getSection" (invalid-name)
C:780, 0: Empty function docstring (empty-docstring)
C:782,23: Invalid variable name "inPath" (invalid-name)
W:785, 4: Statement seems to have no effect (pointless-statement)
E:785, 4: Undefined variable 'something' (undefined-variable)
C:796, 4: Invalid constant name "path" (invalid-name)

使用 disable 选项后(0 个约定,0 个重构,2 个警告,1 个错误):

$ pylint --disable=R,C x.py
W:780,15: Redefining name 'path' from outer scope (line 796) (redefined-outer-name)
W:785, 4: Statement seems to have no effect (pointless-statement)
E:785, 4: Undefined variable 'something' (undefined-variable)

pylintrc中设置这个选项:

disable=R,C

关于python - Pylint 仅显示警告和错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31907762/

相关文章:

python - 如何使用 URL 正则表达式来匹配 Django 中帖子的确切日期?

python - Python 中的 __weakref__ 到底是什么?

python - 在命令行中 cap.isOpened() 时返回状态

python - 处理 PyLint 不一致返回语句的警告

visual-studio-code - 如何更改VS Code用于 Lint 的.pylintrc文件?

python - 从包中导入并运行子包

python - 无法运行 Enthought python

python - 在 Django 中使用 Pylint

python - 开始使用 Pylint for Jython (jython2.5.1)

python - 带有列 Pandas 的正则表达式