Pylint仅显示警告和错误

joe*_*tde 32 python pylint

我想使用pylint来检查我的代码,但我只对错误和警告级别感兴趣.有没有办法在命令行或pylintrc中执行此操作?

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

注意:我不认为这是使用Pylint显示错误和警告的重复

Ste*_*lla 43

使用-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"
Run Code Online (Sandbox Code Playgroud)

没有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)
Run Code Online (Sandbox Code Playgroud)

使用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)
Run Code Online (Sandbox Code Playgroud)

要在pylintrc以下位置设置此选项:

disable=R,C
Run Code Online (Sandbox Code Playgroud)


the*_*max 8

> python -m pylint --errors-only script_to_validate.py
No config file found, using default configuration
************* Module script_to_validate
E:  7,10: Module 'cv2' has no 'imread' member (no-member)
E:  8,15: Module 'cv2' has no 'threshold' member (no-member)
Run Code Online (Sandbox Code Playgroud)

我的设置是Python2.7.6 32位和pylint 1.6.4