Reputation: 8187
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:
python -m autopep8 --max-line-length 120 --in-place --aggressive --aggressive my_dirty_code.py
Formatting with autopep8
in the taskbar on saveUpvotes: 4
Views: 4972
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
Reputation: 56
Try to increase the Format on Save Timeout
in Text Editor -> Formatting
.
For example set it to 2000ms.
Upvotes: 1