[英]VSCode not autoformatting on save (python - black)
I have the following code in settings.json我在 settings.json 中有以下代码
{
"editor.formatOnSave": false,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.linting.pylintArgs": [
"--rcfile=${workspaceFolder}/.pylintrc"
],
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
}
I have installed the following extensions:我已经安装了以下扩展:
"ms-python.pylint"
"ms-python.black-formatter"
I have a.venv in the workspace with black and pylint installed.我在工作区中安装了黑色和 pylint 的 a.venv。
vscode recognizes pylint errors, but doesn't format the code with the black rules? vscode 识别 pylint 错误,但不使用黑色规则格式化代码?
"editor.formatOnSave": false, “editor.formatOnSave”:假,
Change false to true .将false更改为true 。 And delete the following code:并删除以下代码:
"[python]": { "editor.defaultFormatter": "ms-python.black-formatter", "editor.formatOnSave": true },
Run the command pip install black
in your terminal.在终端中运行命令pip install black
。
Add the following code to your setting.json
:将以下代码添加到您的设置中setting.json
:
"python.formatting.provider": "black", “python.formatting.provider”:“黑色”,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.