.editorconfig does not work for /.vscode/launch.json

I have .editorconfig configured like this:

root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.{go,json}]
indent_style = tab
indent_size = 4

GitHub displays 4 indent size correctly for /main.go file, but /.vscode/launch.json file is displayed wrong with 8 indent size.

/.editorconfig:
There was a link for:
github.com/rafrafek/go-dns-lookup/blob/1469f335dce993f464d349b9d8ea07278d531270/.editorconfig
but there are some link limitations.

/main.go (click link and see correct 4 size indent):
https://github.com/rafrafek/go-dns-lookup/blob/1469f335dce993f464d349b9d8ea07278d531270/main.go

/.vscode/launch.json (click link and see wrong 8 size indent):
https://github.com/rafrafek/go-dns-lookup/blob/1469f335dce993f464d349b9d8ea07278d531270/.vscode/launch.json

1 Like

This might depend either on the EditorConfig package you’re using, since packages might vary slightly in their features implementation, e.g. some EditorConfig packages might skip dot folders’ contents by default — in this case, you might try enforcing an explicit file pattern and see it work —, or it might depend on the fact that the JSON file was already using 8 spaces indentation.

E.g. in Sublime Text, the EditorConfig package only enforces indentations according to .editorconfig on new files, whereas for old files auto-detection of indentation takes over. In these cases, you need to manually fix the indentation once. All other EC features are enforced at save time.

I’m not sure how the VSCode package works, but it might be worth checking if it behaves like in ST, in that case, once you know the problem you can quickly fix it.

I am using GitHub. This post is about viewing file in GitHub. Both files are indented using tab characters. Is this bug in GitHub or my config is wrong?

The EditorConfig key indent_size = 4 doesn’t guarantee that tabs will be shown with that size, since that’s up to end users and not a violation of code style conventions. Why the GH WebUI is representing the tab sizes in the two files with different indentations is another matter, and I have no clue — it might just be due to the syntax highlighter. But I’ve checked both files on the WebUI, and they are using Tab indentations, which is correct.

The goal of EditorConfig is to enforce code-style consistency across multiple machines, OSs and editors. How an end user decided to represent a Tab is not a violation of this.

Also the proper key to enforce tab widths is tab_width, maybe adding that would allow you more control:

https://editorconfig-specification.readthedocs.io/#id7

tab_width — Set to a whole number defining the number of columns used to represent a tab character. This defaults to the value of indent_size and should not usually need to be specified.

You might want to explicitly set tab_width, since you don’t know if GH previewer is using some default EditorConfig settings for known files extensions.

Thank you for your reply.

It looks like GitHub ignores indent for files in directories starting with dot . such as .vscode even if .editorconfig is explicitly added to it.

Can I somehow report this behavior to GitHub developers team?

I’ve created new branch with some additional files to test this behavior:
https://github.com/rafrafek/go-dns-lookup/tree/gh-test

It’s quite possible; as mentioned earlier some EC implementations have some default settings that ignore dot folders. I just don’t know which library or tools GH uses.

Have you tried adding an explicit rule like this:

[.vscode/*.json]
indent_style = tab
indent_size = 4
tab_size = 4

This post should be enough. When someone from the GH staff reads this he/she’ll report it to the right place or address you to where to report this if needed.

It would be nice if the code in the GH WebUI would be rendered 100% according to the .editorconfig settings. Even though tab width settings are not as strict as space indentations, in many languages this value controls that comments alignments are shown as intended by the original author, which might affect readability of multiline comments.

Hello,

I can confirm it works:

root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab
indent_size = 4

[.vscode/*.json]
indent_style = tab
indent_size = 4