简体   繁体   English

VSCode 在保存时不自动格式化(python - 黑色)

[英]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 },
  1. Run the command pip install black in your terminal.在终端中运行命令pip install black

  2. 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.

相关问题 带有黑色的Python VSCode formatOnSave在WSL中不起作用 - Python VSCode formatOnSave with black not working in WSL Lenna压缩保存所有黑色python - Lenna compression save all black python Python VSCode 中的项目:如何保存和恢复完整的 VSCode 环境配置? - Python Project in VSCode: How to save and restore full VSCode environment configuration? 如何在Python中将plot另存为黑白png文件 - How to save a plot as a black and white png file in Python Visual Studio Code> Python > 保存时不运行黑色格式 - Visual Studio Code> Python > Black formatting does not run on save 如何在 VSCode 中使用 yapf(或 black) - How to use yapf (or black) in VSCode VSCode Python 保存时在打印时添加额外的空间 - VSCode Python adding extra space after % on print when save 如何为 VSCode Jupyter 笔记本保存默认的 python env - How to save a default python env for VSCode Jupyter Notebooks Python 黑色格式化程序与 VSCode 中的规则 flake8 W503 冲突 - Python black formatter conflict with rule flake8 W503 in VSCode 在 VSCode 中用黑色格式化 python 会导致 arrays 垂直扩展,有什么办法可以压缩它们? - Formatting python with Black in VSCode is causing arrays to expand vertically, any way to compress them?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM