Skip to content

Instantly share code, notes, and snippets.

@kitsuyui
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitsuyui/262320e27f47d0b33a83 to your computer and use it in GitHub Desktop.
Save kitsuyui/262320e27f47d0b33a83 to your computer and use it in GitHub Desktop.
Python の Lint (文法チェッカ) まとめ - flake8 + hacking を使う - ref: http://qiita.com/kitsuyui/items/5ab4608003a29ff7689f
$ autoflake -i --remove-all-unused-imports --remove-unused-variables main.py
$ pip search flake8
$ autopep8 -i main.py
main.py:3: local variable 'x' is assigned to but never used
main.py:3: local variable 'x' is assigned to but never used
$ pip install pyformat
$ pip install isort
main.py:3:1: H306 imports not in alphabetical order (sys, os)
$ pip install flake8-pep257
flake8 ⊃ pep8
flake8 ⊃ pyflakes
flake8 + flake8-pep257 ⊃ pep257
flake8 + flake8-import-order ⊃ import-order
$ flake8 main.py
main.py:2:1: F401 'sys' imported but unused
main.py:3:1: F401 'os' imported but unused
main.py:4:1: E302 expected 2 blank lines, found 0
main.py:5:5: F841 local variable 'x' is assigned to but never used
main.py:9:5: E303 too many blank lines (2)
main.py:10:14: E271 multiple spaces after keyword
$ flake8 main.py
main.py:2:1: F401 'sys' imported but unused
main.py:3:1: F401 'os' imported but unused
main.py:3:1: H306 imports not in alphabetical order (sys, os)
main.py:4:1: E302 expected 2 blank lines, found 0
main.py:5:5: F841 local variable 'x' is assigned to but never used
main.py:9:5: E303 too many blank lines (2)
main.py:10:14: E271 multiple spaces after keyword
$ pip install hacking flake8-import-order flake8-pep257
$ isort -rc main.py
import sys # 余分な import
import os
def fib():
x = 0 # 使ってない変数
a, b = 1, 1
while True:
yield a # 余分なスペース
a, b = b, a + b
if __name__ == '__main__':
for i, num in enumerate(fib()):
print(num)
if i >= 9:
break
import sys
import os
def fib():
x = 0 # 使ってない変数
a, b = 1, 1
while True:
yield a # 余分なスペース
a, b = b, a + b
if __name__ == '__main__':
for i, num in enumerate(fib()):
print(num)
if i >= 9:
break
$ pep8 main.py
main.py:4:1: E302 expected 2 blank lines, found 0
main.py:9:5: E303 too many blank lines (2)
main.py:10:14: E271 multiple spaces after keyword
$ pyflakes main.py
main.py:2: 'sys' imported but unused
main.py:3: 'os' imported but unused
main.py:5: local variable 'x' is assigned to but never used
$ flake8 [対象]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment