インストールと準備
pip install pylint
pylint --generate-rcfile > ~/.pylintrc
~/.pylintrc
を修正してカスタマイズすることができる
例えば
const-rgx=[a-z_][a-z0-9_]{2,30}$
const-name-hint=[a-z_][a-z0-9_]{2,30}$
include-ids=yes
symbols=yes
disable=W0142,C0111
を指定、W0142は **kwargs などの引数のワーニングを出さないようにする設定。
disableの設定をいじって何をチェックするかなど調整することができる。
PyLint メッセージ一覧
出力のフォーマットについて
メッセージタイプ: 行:[オブジェクト:] メッセージ
- 主なメッセージタイプ説明
- (C) convention, コーディング基準まもってなくねぇか?
- (R) refactor, リファクタリングが必要じゃない?
- (W) warning, Python特有の問題かも?
- (E) error, バグがあるかもよ?
使い方例
$ pylint somefile.py
Warning: option include-ids is deprecated and ignored.
Warning: option symbols is deprecated and ignored.
************* Module handlers.account
W: 15, 4: Arguments number differs from overridden method (arguments-differ)
W: 22, 8: Attribute 'ERRORS' defined outside __init__ (attribute-defined-outside-init)
W: 85, 8: No exception type(s) specified (bare-except)
E: 66,19: Class 'User' has no 'objects' member (no-member)
E:100, 8: Bad first argument 'CommonHandler' given to super() (bad-super-call)
E:112,19: Class 'User' has no 'objects' member (no-member)
E:136, 8: Bad first argument 'CommonHandler' given to super() (bad-super-call)
W:160, 8: No exception type(s) specified (bare-except)
E:146,23: Class 'User' has no 'objects' member (no-member)
E:148,19: Class 'User' has no 'DoesNotExist' member (no-member)
E:172, 8: Bad first argument 'CommonHandler' given to super() (bad-super-call)
...
Global evaluation
-----------------
Your code has been rated at 6.90/10 (previous run: 6.43/10, +0.48)
...
みたいな感じで、評価が出る。
前回との差も出してくれるみたい。