Python代码检测

静态代码检测

工具:Flake8
安装:

pip install flake8

PyCharm中配置:
在这里插入图片描述
执行代码检查:
在这里插入图片描述
执行结果:
在这里插入图片描述
(代码规范可参考 https://legacy.python.org/dev/peps/pep-0008/
错误代码说明可参考 https://pep8.readthedocs.io/en/latest/intro.html#error-codes)

Git提交代码检查

工具:pre-commit
安装:

pip install pre-commit

建立git hook:
在需要检查的git项目下执行

pre-commit install

添加配置文件:
在git项目根目录下创建*.pre-commit-config.yaml*文件
文件内容结构如下

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v2.3.0
    hooks:
    -   id: check-yaml
    -   id: end-of-file-fixer
    -   id: trailing-whitespace
-   repo: https://github.com/psf/black
    rev: 19.3b0
    hooks:
    -   id: black

(具体参数可参考 https://pre-commit.com/#pre-commit-sample-config)
手动执行检查:

pre-commit run --all-files

自动执行检查:
git执行commit命令时会自动执行检查

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值