Preston
Preston

Reputation: 8187

VSCode not autoformatting on save

Vscode is not formatting my code on save.

My vscode versions are thus:

My settings.json look like this:

{
    "editor.detectIndentation": false,
    "editor.formatOnSave": true,
    "editor.insertSpaces": true,
    "editor.tabSize": 4,
    "python.formatting.autopep8Args": [
        "--max-line-length=120"
    ],
    "python.formatting.provider": "autopep8",
    "python.linting.enabled": true,
    "python.linting.lintOnSave": true,
    "python.linting.pep8Args": [
        "--max-line-length=120"
    ],
    "python.linting.pep8Enabled": true,
    "python.linting.pylintEnabled": false,
    "python.pythonPath": "/home/me/.python_virtualenvs/somepath"
}

Why is autoformatting on save not working?

Additional notes:

Upvotes: 4

Views: 4972

Answers (2)

Saaru Lindestøkke
Saaru Lindestøkke

Reputation: 2544

I ran into a similar problem, but using black as a formatter, using the VScode extension ms-python.black-formatter version v2022.7.13271013.

Besides configuring the settings as described on the extension page, I had to set "editor.formatOnSaveMode": "file".

Upvotes: 1

David
David

Reputation: 56

Try to increase the Format on Save Timeout in Text Editor -> Formatting. For example set it to 2000ms.

Upvotes: 1

Related Questions