2012-04-13 25 views
29

我正在使用pydev,我設置了pylint。 問題在於,即使在註釋中,pylint也會報告警告。我正在尋找禁用任何行內或塊評論內的任何類型的檢查。 此外,我希望遵循camelCase命名約定,而不是我的代碼中的變量和參數的下劃線。 有沒有任何方法來指定這樣一個規則,而不用任何pylint插入我的代碼:禁用評論?可以自定義Pylint錯誤檢查嗎?

+2

請不要使用camelCase。 – 2013-04-22 06:59:24

+4

雖然您的評論是有道理的,但我曾與一個主要由java開發人員組成的團隊合作,爲了提高其可維護性/可接受性,我不得不偏離Pythonic代碼。 – 2013-05-02 14:08:19

+0

在某些情況下,駱駝案件是合理的。例如,當使用PySide或PyQt時。將Qt-ish駱駝案與python下劃線樣式混合看起來會很糟糕。 – 2016-12-26 17:06:21

回答

38

可以使用

pylint --disable=W1234 

全局禁用某一類的警告或通過使用特殊pylint的配置文件

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

樣品配置文件在下面給出:

[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 

查看文檔以上http://www.logilab.org/4736

Pylint現在有專門的網站:http://www.pylint.org/和更新的文檔:http://docs.pylint.org/

+0

很好的答案,但還有更多。如果您希望跨多個項目和更復雜的場景對pylint進行細粒度控制,請參閱我的答案。 http://stackoverflow.com/a/32672068/763269 – 2016-01-18 04:00:54

+1

我在終端上試過'pylint --disable = C0111'並得到'用法:pylint [options] module_or_package'。我錯過了什麼? – 2016-07-30 13:00:19

18

正如cfedermann所說,您可以指定要在〜/ .pylintrc文件中禁用的消息(注意,如果您不想使用內嵌註釋,可以使用「pylint --generate-rcfile」生成存根文件

您還會在生成的文件的[BASIC]部分中看到諸如「method-rgx」,「function-rgx」等選項,您可以根據自己的喜好來支持駝峯風格樣式而不是PEP8強調風格。

3

儘管這是一個老問題,應該提到一個現在可以指定自己own regex for matching with names

那麼你的匹配駱駝案例的正則表達式會是這樣的:

[a-z][a-zA-Z0-9]{2,30}$ 
相關問題