简体   繁体   中英

VSCode not autoformatting on save (python - black)

I have the following code in 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.

vscode recognizes pylint errors, but doesn't format the code with the black rules?

"editor.formatOnSave": false,

Change false to 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.

  2. Add the following code to your setting.json :

    "python.formatting.provider": "black",

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM