I would like to use pylint to check my code but I am only interested in error and warning levels. Is there a way to do that in command line or in pylintrc?
I am not interested in filtering given issues (like listing all messages in MESSAGE CONTROL), I just want pylint to ignore all convention and refactor messages.
Note: I don't think that's a duplicate of Using Pylint to display error and warnings
This may be done by adding # pylint: disable=some-message,another-one at the desired block level or at the end of the desired line of code.
If you are getting the dreaded no-member error, there is a possibility that either: pylint found a bug in your code. You're launching pylint without the dependencies installed in its environment. pylint would need to lint a C extension module and is refraining to do so.
Pylint analyses your code without actually running it. It checks for errors, enforces a coding standard, looks for code smells, and can make suggestions about how the code could be refactored. Pylint can infer actual values from your code using its internal code representation (astroid).
Use the -d
/ --disable
option to turn off the "C" and "R" message classes (convention and refactor):
-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"
Without the disable
option (6 convention, 1 refactor, 2 warning, 1 error):
$ 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)
After using the disable
option (0 convention, 0 refactor, 2 warning, 1 error):
$ 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)
To set this option in pylintrc
:
disable=R,C
> 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)
This was tested with Python v3.8 and Pylint v2.11.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With