Search code examples
javascriptc#typescriptvisual-studio-codeeditorconfig

VSCode .editorconfig cannot apply settings to C# code


I am trying to apply some settings e.g. trim_trailing_whitespace for C# code as well as js part in VSCode by using the following settings:

# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
trim_trailing_whitespace = true; // it is working for TypeScript and JavaScript, not C#

[*.md]
max_line_length = off
trim_trailing_whitespace = true

[*.cs]
trim_trailing_whitespace = true; // I add this to make it work for C#

But it does not work for C# code. Is it not possible to make it work in C#? I just try to test it for trim_trailing_whitespace but not working for C# while working TypeScript and JavaScript. Here is some info related to that:

https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019


Solution

  • Change trim_trailing_whitespace for C # to this "files.trimTrailingWhitespace"

    and Make sure you are working on these steps:

  • Open Visual Studio Code User Settings (menu FilePreferencesSettingsUser Settings tab).
  • Click the icon in the top-right part of the window. This will open a document.
  • Add a new "files.trimTrailingWhitespace": true setting to the User Settings document if it's not already there. This is so you aren't editing the Default Setting directly, but instead adding to it.
  • Save the User Settings file.

  • ref:
    https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.text.editor.trimtrailingwhitespace?view=visualstudiosdk-2019