Search code examples
angularvisual-studio-codeeditorconfig

Why is vscode removing my spaces?


I have an angular project generated using the angular-cli with the following extensions in my vscode:

Angular Language Service Auto Import Debugger for Chrome EditorConfig for VS Code TSLint

I have a problem where vscode is removing my spaces. For example say I add the following spaces underneath the switch statement. If I don't type a non space character, then within less than a second it will delete my spaces underneath the switch statement. It's very annoying.

enter image description here


Solution

  • I have an .editorconfig file which has the following setting:

    trim_trailing_whitespace = true
    

    I also installed the EditorConfig for VS Code extension. This will cause the annoying behavior of trimming trailing whitespace. To fix this I just have to set this setting to:

    trim_trailing_whitespace = false
    

    Finally it's annoying to manually delete extra trailing whitespace so I can have a linter automatically fix this for me. In my case I'm doing an angular2 development using the angular cli and I just need to run this for it automatically fix my trailing whitespace problems:

    ng lint --fix
    

    I'm assuming that there are going to be similar commands for plain javascript linting and typescript linting.