Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto format flake8 linting errors in VSCode

I'm using the flake8 linter for Python and I have many code formats issues like blank line contains whitespace flake8(W293)

I'm trying to auto fix these linting issues. I have these settings:

    "python.linting.enabled": true,
    "python.linting.flake8Enabled": true,
    "python.linting.lintOnSave": true,
    "python.linting.flake8Args": [
        "--ignore=E501",
    ],
    "editor.formatOnSave": true

I'm using the default autopep8 formater but it seems that it does nothing. Nothing happens when I save the file or run the command Format Document.

Is there any way to auto fix these linting errors?

like image 920
nrofis Avatar asked Jan 27 '26 07:01

nrofis


2 Answers

I would suggest using a formatter, black for instance, to fix the issues detected by your linter.

If so, pip install it and add this to your settings.json:

"python.formatting.provider": "black"

Then, pressing Alt+ShifT+F or Ctrl+S should trigger the formatting of your script.

like image 84
Laurent Avatar answered Jan 29 '26 21:01

Laurent


It should be:

 "python.linting.flake8Args": ["--ignore=W293"],

And you can switch the formatting to yapf or black.

If you insist on autopep8, you can add this in the settings.json:

"python.formatting.autopep8Args": ["--select=W293"],
like image 27
Steven-MSFT Avatar answered Jan 29 '26 21:01

Steven-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!