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...
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.
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”.
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.
You can set your formatting options through the menus Tools > Options > Text Editor > Python > Formatting and its nested tabs.
The line argument for black is wrong, it should be
--line-length=120
according to https://stackoverflow.com/a/58048911/4435175.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With