EditorConfig for VS Code not working

HtmlCssVisual Studio-CodeEditorconfig

Html Problem Overview


I use VS Code as editor. We have a .editorconfig file with format configs within. We all use in our editors the extenion EditorConfig to format our HTML and CSS general. I have installed the extension EditorConfig for VS Code from here: https://github.com/editorconfig/editorconfig-vscode

Our .editorconfig file looks like this:

# This is the top-most .editorconfig file (do not search in parent directories)
root = true

### All files
[*]
# Force charset utf-8
charset = utf-8
# Indentation
indent_style = tab
indent_size = 4
# line breaks and whitespace
insert_final_newline = true
trim_trailing_whitespace = true
# end_of_line = lf

### Frontend files
[*.{css,scss,less,js,json,ts,sass,php,html,hbs,mustache,phtml,html.twig}]

### Markdown
[*.md]
indent_style = space
indent_size = 4
trim_trailing_whitespace = false

### YAML
[*.yml]
indent_style = space
indent_size = 2

### Specific files
[{package,bower}.json]
indent_style = space
indent_size = 2

I can't find any keyboard shortcut, setting or else. How to get my extension do the stuff from the .editorconfig file?

Html Solutions


Solution 1 - Html

MY OWN SOLUTION:

The problem I had was, that I added the extension editorconfig to my vscode, but didn't install the npm package for it. So it's not enough, to add the extension only to your vscode, you have also to install the package, so it could run.

I installed the npm package global like this: npm install -g editorconfig

After that I added the extension and enabled it. Now it works perfect.

Here is the link to the required npm package: https://www.npmjs.com/package/editorconfig

Here is the link to the required extenion for your vscode: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig

Solution 2 - Html

In addition all of the above I also needed to turn on the Editor Format on Save option.

{
   "editor.formatOnSave": true
}

Solution 3 - Html

I got the error "Extension EditorConfig cannot format ..." (at the bottom of the IDE, disappearing after some seconds).

Changing the preferences (ctrl+, , search for format and set the Editor:DefaultFormatter to None (instead of EditorConfig)) solved the problem for me (and yes, funny enough, this indeed did enable the usage of the .editorconfig - not any other formatting rules)

Codium: 1.60.2 with EditorConfig: v0.16.6

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionwebta.st.icView Question on Stackoverflow
Solution 1 - Htmlwebta.st.icView Answer on Stackoverflow
Solution 2 - HtmlJordon DavidsonView Answer on Stackoverflow
Solution 3 - Htmldr0iView Answer on Stackoverflow