Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code> Python > Black formatting does not run on save

Although I seem to have configured both linitng and formatting properly, the linting runs but the black formatting does not.

    "python.linting.flake8Enabled": true,
    "python.linting.flake8Args": [
        "--max-line-length=110"
    ],
    "python.linting.lintOnSave": true,
    "python.formatting.provider": "black",
    "python.formatting.blackPath": "/usr/local/bin/black",
    "python.formatting.blackArgs": [
        "--line-length",
        "110"
    ],
    "editor.formatOnSave": true,

I have checked, that black is properly configured and I can run the formatting from the command-line without issues.

But when saved in the IDE, black does not format the file. It also does not complain, there are no error-messages that pop up and nothing showing up in the logs. It just does not run the formatting at all.

I am running this insisde a docker-container using remote-editing: not sure, if this makes a difference.

The black-version is:

black>=19.3b0

and the vscode-version is 1.36.1.

Thx for any help, as right now I am pretty clueless, why the black-formatting does not run...

like image 422
Stefan Frank Avatar asked Jul 15 '19 12:07

Stefan Frank


People also ask

Why is VSCode not formatting on save?

To automatically format the file on save, In Visual Studio Code, press Control + Shift + P or Command + Shift + P (Mac) to open the command palette and type setting and then select Preferences: Open User Settings option. Search for format on save setting and check the checkbox.

How do I use black Python format in VSCode?

Go to settings in your VS-Code typing “Ctrl + ,” or clicking at the gear on the bottom left and selecting “Settings [Ctrl+,]” option. Type “format on save” at the search bar on top of the Settings tab and check the box. Search for “python formatting provider” and select “black”.

How do I enable format in save VS code?

Enable/Disable Format On SaveOpen up VSCode Command Palette by pressing Ctrl + Shift + P. Search and select Open Settings (UI). Just start typing and it will auto-fill. Once there's a match, you can hit enter immediately, or manually click on the right option.

How do I change the format of a VSCode in Python?

You can set your formatting options through the menus Tools > Options > Text Editor > Python > Formatting and its nested tabs.


1 Answers

The line argument for black is wrong, it should be

--line-length=120

according to https://stackoverflow.com/a/58048911/4435175.

like image 174
Vega Avatar answered Oct 02 '22 19:10

Vega