我正在使用pydev,我設置了pylint。 問題在於,即使在註釋中,pylint也會報告警告。我正在尋找禁用任何行內或塊評論內的任何類型的檢查。 此外,我希望遵循camelCase命名約定,而不是我的代碼中的變量和參數的下劃線。 有沒有任何方法來指定這樣一個規則,而不用任何pylint插入我的代碼:禁用評論?可以自定義Pylint錯誤檢查嗎?
回答
可以使用
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/。
很好的答案,但還有更多。如果您希望跨多個項目和更復雜的場景對pylint進行細粒度控制,請參閱我的答案。 http://stackoverflow.com/a/32672068/763269 – 2016-01-18 04:00:54
我在終端上試過'pylint --disable = C0111'並得到'用法:pylint [options] module_or_package'。我錯過了什麼? – 2016-07-30 13:00:19
正如cfedermann所說,您可以指定要在〜/ .pylintrc文件中禁用的消息(注意,如果您不想使用內嵌註釋,可以使用「pylint --generate-rcfile」生成存根文件
您還會在生成的文件的[BASIC]部分中看到諸如「method-rgx」,「function-rgx」等選項,您可以根據自己的喜好來支持駝峯風格樣式而不是PEP8強調風格。
儘管這是一個老問題,應該提到一個現在可以指定自己own regex for matching with names。
那麼你的匹配駱駝案例的正則表達式會是這樣的:
[a-z][a-zA-Z0-9]{2,30}$
- 1. Unity - 使用自定義檢查器時可以訪問OnValidate()嗎?
- 2. 我可以教ReSharper自定義空檢查嗎?
- 3. 使用Observable.ajax.post可以捕捉'正確/自定義'錯誤嗎?
- 4. 你可以自定義一個mysql_error重複錯誤消息嗎?
- 5. Heroku:可以關閉自定義錯誤頁面嗎?
- 6. 我可以自定義傑克遜錯誤信息嗎?
- 7. 您可以通過編程關閉自定義錯誤嗎?
- 8. pylint與自定義rcfile和錯誤只標誌
- 9. 在WinDbg中定義自定義錯誤檢查代碼
- 10. 是否可以對特定的錯誤代碼進行pylint?
- 11. mssql_query可以檢測插入錯誤嗎?
- 12. 我可以在WCF中繼承FaultException以拋出自定義錯誤嗎?
- 13. 可以將404以外的HTTP錯誤用於自定義登錄頁面嗎?
- 14. 自定義DataProvider類可以暴露自定義模板嗎?
- 15. 可以自定義相機固件嗎?
- 16. C#中的NotifyIcon.ShowBalloonTip可以自定義嗎?
- 17. 我可以自定義Google Map嗎?
- 18. CodeIgniter可以路由自定義URL嗎?
- 19. 可以自定義Google +1圖標嗎?
- 20. 我可以自定義標題嗎?
- 21. 我可以自定義UIDatePicker嗎?
- 22. ListPreference - 可以自定義項目嗎?
- 23. 可以在位置指令下指定自定義HTTP錯誤500嗎?
- 24. 銀線條自定義安全檢查顯示自定義錯誤消息
- 25. 檢查驗證與ID和指定自定義錯誤
- 26. 如何使自定義listView可檢查?
- 27. 我可以爲ThreadPool.QueueUserWorkItem定義頻率檢查嗎?
- 28. 我可以檢查預編譯中定義的宏嗎?
- 29. PHP語法錯誤,有人可以幫我檢查一下嗎?
- 30. 未定義指數錯誤檢查
請不要使用camelCase。 – 2013-04-22 06:59:24
雖然您的評論是有道理的,但我曾與一個主要由java開發人員組成的團隊合作,爲了提高其可維護性/可接受性,我不得不偏離Pythonic代碼。 – 2013-05-02 14:08:19
在某些情況下,駱駝案件是合理的。例如,當使用PySide或PyQt時。將Qt-ish駱駝案與python下劃線樣式混合看起來會很糟糕。 – 2016-12-26 17:06:21