Search code examples
editorconfig

EditorConfig: applying rules to multiple, specific folders


Let's say I have a project with the following folders:

/
  /folder1
  /folder2
  /folder3
  /folder4
  /folder5

Question

Is there a way to have my .editorconfig file at root (/) level but only apply the same rules to (all files within) folder1, folder3 and folder5 but not the other two?

What I could do (but doesn't seem ideal)

  • Have one copy of the .editorconfig file within folder1, folder3 and folder5. But duplicating it seems very ugly/inconvenient.
  • Create an .editorconfig within the root folder with all the rules, then another one with just root = true within all the "excluded" folders (folder2 and folder4). It's better, but not ideal because we have to remember to do it on every single folder rules should not be applied to (in reality, there may be dozens of them).

What I would like to (be able to) do

Create an .editorconfig at root level, and list the folders rules should be applied to. I didn't find a way to do something like this:

[/folder1/**]
[/folder3/**]
[/folder5/**]
end_of_line = lf
insert_final_newline = true

Invalid because you cannot combine sections like that.

Or, using the {s1,s2,s3} format:

[{/folder1/**, /folder3/**, /folder5/**}]
end_of_line = lf
insert_final_newline = true

But it doesn't seem to be valid either (only simple file name patterns seem allowed).

Is there any other way to achieve this? I didn't find anything on the docs or elsewhere, but I may have missed something obvious.


Solution

  • It was introduced to EditorConfig Core 0.11.0 in 2013. The way to do it is as follows (Source):

    [{package.json,.travis.yml}]
    indent_style = space
    indent_size = 2
    

    I tested the following configuration in Visual Studio Code and can confirm it works.

    root = true
    
    [{packages/**,plugins/**}]
    indent_size = 8
    

    If this does not work for you, it likely depends on the implementation/client. It's best to make a feature request to support the feature.