Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Pylint error checking be customized?

I am using pydev where I have set up pylint. The problem is that even inside the comments, pylint reports warnings. I was looking to disable any sort of checking inside any line or a block comment. Also, I wish to follow camelCase naming convention instead of underscores for variables and arguments in my code. Is there any way to specify such a rule without inserting my code with any pylint: disable comments?

like image 639
Sumit Bisht Avatar asked Apr 13 '12 10:04

Sumit Bisht


People also ask

How do you ignore specific Pylint errors?

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.

What does Pylint check for?

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).

What are Pylint errors?

Pylint has a standard format to its output. When there is a syntax error, it will not show a code rating. Depending on your version of Pylint, you may or may not see the first line informing you what . pylintrc configuration file you're using. This allows you to verify that you're using the one you intended to.

How do I skip a Pylint check?

you can ignore it by adding a comment in the format # pylint: disable=[problem-code] at the end of the line where [problem-code] is the value inside pylint(...) in the pylint message – for example, abstract-class-instantiated for the problem report listed above.


2 Answers

You can globally disable warnings of a certain class using

pylint --disable=W1234 

or by using a special PyLint configuration file

pylint --rcfile=/path/to/config.file 

A sample config file is given below:

[MESSAGES CONTROL] # C0111 Missing docstring  # I0011 Warning locally suppressed using disable-msg # I0012 Warning locally suppressed using disable-msg # W0704 Except doesn't do anything Used when an except clause does nothing but "pass" and there is no "else" clause # W0142 Used * or * magic* Used when a function or method is called using *args or **kwargs to dispatch arguments. # W0212 Access to a protected member %s of a client class # W0232 Class has no __init__ method Used when a class has no __init__ method, neither its parent classes. # W0613 Unused argument %r Used when a function or method argument is not used. # W0702 No exception's type specified Used when an except clause doesn't specify exceptions type to catch. # R0201 Method could be a function # W0614 Unused import XYZ from wildcard import # R0914 Too many local variables # R0912 Too many branches # R0915 Too many statements # R0913 Too many arguments # R0904 Too many public methods disable=C0111,I0011,I0012,W0704,W0142,W0212,W0232,W0613,W0702,R0201,W0614,R0914,R0912,R0915,R0913,R0904,R0801 

See the documentation over at Pylint's dedicated site.

like image 50
cfedermann Avatar answered Sep 22 '22 00:09

cfedermann


As said by cfedermann, you can specify messages to be disabled in a ~/.pylintrc file (notice you can generate a stub file using pylint --generate-rcfile if you don't want to use inline comments.

You'll also see in the generated file, in the [BASIC] section, options like "method-rgx", "function-rgx", etc. which you can configure as you like to support camel cases style rather than pep8 underscore style.

like image 31
sthenault Avatar answered Sep 26 '22 00:09

sthenault