Editorconfig is a way to solve the old
tabs vs spaces debate, and more. It allows to express and enforce a minimal style guide across the majority of development platforms. This becomes especially important as soon as collaborative project work enters the picture.
Let’s look at an example editorconfig configuration file:
# https://editorconfig.org root = true [*] charset = utf-8 end_of_line = lf indent_size = 4 indent_style = space insert_final_newline = true trim_trailing_whitespace = true
It defines that for all files matching the pattern
* the following rules should apply. It defines the charset, line ending character, indentation size, indentation style, whether or not a and only one new line should be inserted at the of the file and whether or not trailing whitespaces at the end of files should be trimmed. With the exception of the indent size and style these rules are hardly controversial. Concerning indent size and style, the rust book talks about it at the very beginning here, suggesting indent size 4 and spaces.
Generally editorconfig is flexible, all rules can be specified and overwritten for patterns, using it privately and professionally for several years, I have yet to run into problems with it. The only issue is if the individuals editing platform requires a plugin and the person doesn’t know about it and or didn’t care to install it. Yet if the file is completely ignored the situation is like before and for those that know about it or have their development platform pick it up automatically it helps avoid unnecessary issues.
Creating this file as part of default cargo projects, both binary and library, has many advantages as described above. Yet there are also downsides. More generated files can increase the knowledge burden, and the chosen defaults could conflict with the individuals preference. However with the rust book explicitly stating an opinionated default, I think the upsides out way the downsides here.
Personally, every time I create a new rust project I find myself whishing it had created a editorconfig file, and then manually copying it from one of my other projects. Further this could be an opportunity to a apply a text recommendation to major parts of the rust ecosystem, given that rust tries to avoid the C++ nightmare of there are 13 different subtly different ways of doing the same thing. With this there could be one way to express a minimal style guide for the rust community, and even potentially lint against it.
Another idea would be to require it if the crate is published. That way only projects with intend of being shared require this file and the downsides it brings, yet I’d prefer introducing this file ecosystem wide, because adopting it afterwards is more hassle than if the project started with it from the beginning.
I am curious to get some feedback about this.