psf/black

Formatting does not occur when file autosaved

Closed this issue · 2 comments

Describe the bug

To Reproduce

Load a python script in VSCode.
Ensure auto save is toggled on.
Make a change to the script where the formatting is such that Black would correct.
Observe file content gets autosaved but the Black formatting is not applied.
Save with Ctrl-S
Observe that the formatting is applied.

Expected behavior

I would expect that when the file gets autosaved, the Black formatting would be applied.

  • Black's version: 2024.2.0
  • OS and Python version: Win 11 Enterprise 22H2 22621.4169

Is editor.formatOnSave enabled in the vscode settings? see vscode settings for python docs.

TL;DR; settings.json should contain the following:

  "[python]": {
    "editor.formatOnSave": true
    "editor.defaultFormatter": "ms-python.black-formatter"
  }

asfourco is helpful

Do also note that https://github.com/psf/black does not maintain a VSCode plugin, so if there were an issue this isn't the right repository to report it in