Back to Python#Development

See Also PEP 8VS Code Python Linting

Flake8

Flake8 is a wrapper around these tools:

1. Quickstart

https://pypi.org/project/flake8/

conda install flake8
flake8 path/to/code/to/check.py
flake8 --ignore E24,W504 path/to/code/

1.1. Configuring Flake8

http://flake8.pycqa.org/en/latest/user/configuration.html

~/.flake8

[flake8]
# it's not a bug that we aren't using all of hacking, ignore:
# F812: list comprehension redefines ...
# H101: Use TODO(NAME)
# H202: assertRaises Exception too broad
# H233: Python 3.x incompatible use of print operator
# H301: one import per line
# H306: imports not in alphabetical order (time, os)
# H401: docstring should not start with a space
# H403: multi line docstrings should end on a new line
# H404: multi line docstring should start without a leading new line
# H405: multi line docstring summary not separated with an empty line
# H501: Do not use self.__dict__ for string formatting
ignore = F812,H101,H202,H233,H301,H306,H401,H403,H404,H405,H501

2. VS Code Linting with Flake8

{
    "python.pythonPath": "/Users/liyan/miniconda/envs/py37/bin/python",
    "python.envFile": "${workspaceFolder}/dev.env",
    "python.terminal.executeInFileDir": true, //在脚本目录下执行
    "python.terminal.activateEnvironment": true,
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.flake8Path": "/Users/liyan/miniconda/bin/flake8",
    "python.linting.flake8Args": [
        "--ignore=E303,E501",
        "--verbose"
    ],
    "python.formatting.provider": "autopep8", //Specify the automatic formatting format to pep8
    "editor.formatOnSave": true,
}

3. Reference