下記の記事ではJavaScriptの静的構文チェック環境をVimに作りました。
今回は Python の静的構文チェック環境をVimに作ります。
インストール
PyLint
当たり前ですがPythonが入ってないとだめです1. Python3 インストール
下記に記載しているPythonインストール手順を実行
2. PyLintをpipでインストール
# pip3.6 install pylint
Syntastic(scrooloose/syntastic)
下記のSynatasticのインストールを参考静的構文チェック
こんな感じになりましたPython3だとprintの構文がエラーになってますね。。修正せねば

警告の一部を除外し非表示にさせる
結構警告が出るのですが、こちらとしては無視しているものも多いので、除外させたいと思いますまずテンプレートを作ります
pylint --generate-rcfile > ~/.config/pylintrc
テンプレートを利用して除外するコードを記述します
# 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".
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
locally-enabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
deprecated-operator-function,
deprecated-urllib-function,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
comprehension-escapeメッセージ一覧は下記にあります
http://pylint-messages.wikidot.com/all-codes
上記の disable には上記のコード(C0111など)をカンマ区切りで記載すればよいようです
コーディング規約(PEP8)
下記にPylintで実装されているPythonのコーディング規約がありますhttps://www.python.org/dev/peps/pep-0008
簡単に例が紹介されているサイト
http://msdl.cs.mcgill.ca/people/shahla/misc/PythonConventions.pdf
コメント