pycodestyle
https://github.com/PyCQA/pycodestyle
https://pycodestyle.pycqa.org/en/latest/intro.html
Disclaimer
PEP 8のconsistencyを強調
Error codes
In the default configuration, the checks E121, E123, E126, E133, E226, E241, E242, E704, W503, W504 and W505 are ignored because they are not rules unanimously accepted, and PEP 8 does not enforce them.
W503やW504などはデフォルト設定では無視されている
Please note that if the option --ignore=errors is used, the default configuration will be overridden and ignore only the check(s) you skip.
「--ignore=errorsオプションが使われるならば、デフォルト設定は上書きされ、スキップするよう指定したチェックのみが無視される」
IMO:--ignore=errorsにはデフォルトの追加が必要
The check W503 is mutually exclusive with check W504.
「チェック W503 は チェック W504 と相互に排他的」
👉 pycodestyleにおけるW503とW504の議論
Pythonのソースコードについて種々のチェック
物理行
論理行
AST
compileできるか
実装は1ファイル
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py
_main()
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py#L2626
StyleGuideを初期化し、check_filesメソッドを呼び出す
StyleGuide
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py#L2282
runner属性
__init__では、input_fileメソッド(関数)が代入される
checker属性
__init__では渡ってきたクラス名を指定
デフォルト値はChecker
check_filesメソッド
pathがディレクトリならinput_dir呼び出し
input_dirメソッド
runner呼び出し(input_fileメソッド)
input_fileメソッド
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py#L2345
checker_class属性を初期化
ファイルごとにCheckerが初期化される
Checkerインスタンスのcheck_allメソッドを呼び出す
Checker
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py#L1828
__init__
_physical_checks
_logical_checks
check_allメソッド
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py#L2073
generate_tokenメソッドでトークンを取り出す(lines属性)
check_logical
Python 論理行
check_physical
generate_tokenメソッド
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py#L2007
tokengen = tokenize.generate_tokens(self.readline)
Python tokenize
readlineはCheckerのメソッド
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py#L1891
Get the next line from the input buffer.
maybe_check_physicalしてからtokenをyield
check_logical
https://github.com/PyCQA/pycodestyle/blob/2.11.0/pycodestyle.py#L1960
build_tokens_lineメソッド
Checkerの_logical_checksの1つ1つに対してrun_checkメソッドを走らせる
check_physical