Skip to content
Advertisement

Formatting on save moves import statment in VS-Code

I am learning flask and building a app based on Corey Schafer’s Youtube tutorials. I’m using VS-Code as my editor of choice.

In tutorial 5 he splits his app into a package structure and when I do it I run into a problem. In my settings I enabled the "editor.formatOnSave": true and the formatter I use is autopep8. Now when I move one of my import statements from the top to the bottom of my file and save, the formatter moves it back to the top. I’m guessing its because of ‘E402 – Fix module level import not at top of file’?

I tried to ignore it with the "python.formatting.autopep8Args": [--ignore=E402] but that did nothing. Maybe here you can only turn of lynting errors and E402 is only a lynting error and its not relevant for the formatting?

I hope you can help me disable or fix it.

Cheers

Advertisement

Answer

Brett Cannon comment:

I don’t know autopep8 well, but that example is mis-formatted as you’re missing quotes around the argument: "python.formatting.autopep8Args": ["--ignore=E402"]

@BrettCannon terrific! That fixed it. Tried so long to fix it that i forgot those quotes and didnt see that they were missing.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement