在VS代码中的settings.json文件下,black设置为Python:
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.linting.mypyEnabled": true,
"python.linting.lintOnSave": true,
"python.formatting.blackArgs": [
"--line-length",
"120"
],
"python.formatting.autopep8Args": [
"--max-line-length",
"120",
"--in-place"
],
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--max-line-length",
"120",
"--ignore=E501",
]Black在格式化Python代码方面做得非常出色,但不幸的是,black没有纠正任何flake8错误。因此,在VS代码中保存Flake8文件时,不会修复像Expected 2 blank lines, found 0 (E302)这样的.py错误。
幸运的是,如果您运行Flake8,这些autopep8 --in-place <your_python_script.py>错误是可以修复的,但是显然这是很烦人的,因为它需要额外的手动步骤。
因此,自然的问题是:如何使black和autopep8 --in-place都能够在保存任何.py文件时运行和触发?
我的理解是VS代码有一个设置python.formatting.provider,您可以将其设置为black、autopep8或yapf等,但它只接受一个格式提供程序,而不是两个。
如何配置VS代码,以便在保存这些文件时将多个格式化程序应用于Python文件?
或者,是否有一种方法可以在保存Python文件时触发autopep8 --in-place (除了黑色格式化程序)?
发布于 2022-05-03 06:55:26
注意,在使用黑色时,您需要使用黑色的推荐设置
max-line-length = 88
extend-ignore = E203https://stackoverflow.com/questions/72094171
复制相似问题