我有点沉迷于在VS Code中使用pycodestyle,所以记下
前提
- VS Code已安装
- 内置Python 3.7.3环境
程序
安装pycodestyle和Pep8(Pep8是pycodestyle的旧名称)
1 | pip install pycodestyle pep8 |
使用VS Code打开目标目录,并将以下内容写入
settings.json
1 2 3 4 5 6 | { "python.linting.enabled": true, "python.linting.pylintEnabled": false, "python.linting.pep8Enabled": true, "python.linting.lintOnSave": true } |
设置
规则无效等时,请在顶层目录中创建一个
下面是忽略每行字符限制(少于80个字符)时的配置文件示例。
setup.cfg
1 2 3 4 5 | [pycodestyle] ignore = E501 [pep8] ignore = E501 |
使用上述设置,VS Code将自动执行Lint
要使用
命令执行Lint,请在顶层目录
中执行以下命令
1 2 | $ pycodestyle . ./db_operation.py:127:31: E711 comparison to None should be 'if cond is not None:' |