0
0

More than 3 years have passed since last update.

コードスタイルをチェックするツール

Last updated at Posted at 2020-08-25

使うライブラリ

pycodestyle

Features
Plugin architecture: Adding new checks is easy.
Parseable output: Jump to error location in your editor.
Small: Just one Python file, requires only stdlib. You can use just the pycodestyle.py file for this purpose.
Comes with a comprehensive test suite.

flake8

Flake8 is a wrapper around these tools:
PyFlakes
pycodestyle
Ned Batchelder’s McCabe script

pylint

Pylint is a Python static code analysis tool which looks for programming errors, helps enforcing a coding standard, sniffs for code smells and offers simple refactoring

チェックするコード

qiita.py
import pycodestyle
import flake8
import pylint


import os
x = {"adfasd"       , 'adsfasdfasd'}
y         =1

pycodestyle

NEW1.py:6:20: E203 whitespace before ','
NEW1.py:7:2: E221 multiple spaces before operator
NEW1.py:7:12: E225 missing whitespace around operator
NEW1.py:8:1: W391 blank line at end of file

flake8


NEW1.py:1:1: F401 'pycodestyle' imported but unused
NEW1.py:2:1: F401 'flake8' imported but unused
NEW1.py:3:1: F401 'pylint' imported but unused
NEW1.py:5:1: F401 'os' imported but unused
NEW1.py:6:20: E203 whitespace before ','
NEW1.py:7:2: E221 multiple spaces before operator
NEW1.py:7:12: E225 missing whitespace around operator
NEW1.py:8:1: W391 blank line at end of file

pylint

************* Module newww.NEW1
NEW1.py:6:20: C0326: No space allowed before comma
x = {"adfasd"       , 'adsfasdfasd'}
                    ^ (bad-whitespace)
NEW1.py:7:10: C0326: Exactly one space required around assignment
y         =1
          ^ (bad-whitespace)
NEW1.py:8:0: C0305: Trailing newlines (trailing-newlines)
NEW1.py:1:0: C0103: Module name "NEW1" doesn't conform to snake_case naming style (invalid-name)
NEW1.py:1:0: C0114: Missing module docstring (missing-module-docstring)
NEW1.py:6:0: C0103: Constant name "x" doesn't conform to UPPER_CASE naming style (invalid-name)
NEW1.py:7:0: C0103: Constant name "y" doesn't conform to UPPER_CASE naming style (invalid-name)
NEW1.py:1:0: W0611: Unused import pycodestyle (unused-import)
NEW1.py:2:0: W0611: Unused import flake8 (unused-import)
NEW1.py:3:0: W0611: Unused import pylint (unused-import)
NEW1.py:5:0: W0611: Unused import os (unused-import)
NEW1.py:5:0: C0411: standard import "import os" should be placed before "import pycodestyle" (wrong-import-order)

-------------------------------------
Your code has been rated at -10.00/10


まとめ

厳しさ
pylint > flake8 > pycodestyle

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0