Repository navigation
[Tools]Add autoflake pre-commit hook to remove unused-imports/var - #47455
Conversation
|
|
原来不将 autoflake 直接添加到 pre-commit 是因为 autoflake 自动删除是有可能导致原本能跑通的代码删除后跑不通的,因此只让 flake8 提示而不自动删除,这样可以选择是加 由于 unused variable 存量没清,所以还不能加进来(大概试了下,应该有 500+ 文件需要清理),这个可以等存量清理后再加上
配置的话貌似 autoflake 有点 bug,无法禁用掉 remove-unused-variables,所以暂时直接在 pre-commit-config 里 args 修改下就好: - repo: https://github.com/PyCQA/autoflake
rev: v1.7.7
hooks:
- id: autoflake
args:
- --in-place
- --remove-all-unused-imports
- --ignore-pass-after-docstring
- --ignore-init-module-imports
- --exclude=python/paddle/fluid/[!t]**,python/paddle/fluid/tra**这里 fluid 下非单测需要 exclude 掉,因为没有清理存量 |
@SigureMo 我按照你上面这样修改,重新commit下? |
嗯嗯,仅修改配置的话可以加一下 |
@SigureMo 这一行的意思是仅仅对 |
|
好的,非常感谢 @SigureMo 同学解答 ✿✿ヽ(°▽°)ノ✿ |
如果加了autoflake8, |
unused variable 是错误码 F841(local variable
autoflake 遵守 |


PR types
New features
PR changes
Others
Describe
What's new?
I found a great tool: autoflake, it has two import features for Paddle development: