Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode not autoformatting on save (python - black)

I have the following code in settings.json

{ 
    "editor.formatOnSave": false,
    "[python]": {
        "editor.defaultFormatter": "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?

like image 437
Tlaloc-ES Avatar asked Aug 20 '26 18:08

Tlaloc-ES


1 Answers

"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",

like image 122
MingJie-MSFT Avatar answered Aug 22 '26 09:08

MingJie-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!