
EditorConfig: Consistent coding styles across various editors and IDEs - homarp
https://editorconfig.org/
======
petetnt
These days I vastly prefer autoformatters, only run at precommit stage myself.
Instead of having to adapt to different styles everytime and getting
distracted by stylistic changes mid-coding (eg. on save), I can just rely that
the styles are eventually consistent and code ahead. It takes some time
getting used to, but it’s super refreshing.

~~~
skoskie
Ok, help me understand this. I’m on #TeamTab which puts me at odds with most
coding standards. I usually work solo, so I don’t care, but every time I do
let someone else edit a file, the commit shows every line has changed because
their editor converts my indents.

Are you saying there’s a tool that will let me work with (superior) tabs but
have standards compliant commits?

I’ve tried doing this in my .gitconfig with limited success. It didn’t work
consistently.

~~~
chrisweekly
The real-world choice is not (tabs) || (spaces), it's (tabs && spaces) ||
(spaces). Which is why spaces is the objectively superior choice.

~~~
seabird
In any project I've worked on that has used tabs for indentation, I've found
no need to combine tabs and spaces. I've never been anywhere that enforces
neurotic alignment standards, and if such guidelines aren't part of your
workflow, I don't know why anyone would consciously inflict spaces upon
themselves or their team. Some editors handle them like shit, and formatting
fuckups always find their way in unless you're using an autoformatter.

The only arguments I hear for spaces are alignment (I don't have time to give
a shit about such minor aesthetic preferences) and forcing other people to see
code a certain way (I really don't understand why I would want to force my
editing preferences on others). I don't think either one of them justifies the
annoyance of spaces.

~~~
chrisweekly
Huh? You say "[I wouldn't] force my editing preferences on others", yet you
want to insist on inserting invisible whitespace characters into shared source
code. That seems inconsistent to me.

~~~
saagarjha
That's a disingenuous misinterpretation of the comment. There's a clear
difference between "I'd like code to be indented", which is widely agreed upon
to be a good idea, and "you _need_ to see my code indented with four
characters because I hardcoded this into my source code", which is personal
preference.

------
smt88
My frustration with editorconfig files is that they don't have nearly enough
breadth of config options to create close-to-identical setups for everyone on
the team. The options are shallow compared to all the ways a modern formatter
(like WebStorm's) can differ between users.

It seems like CLI tools built for a specific language are the best solution as
of now.

------
wincent
At my job we use tabs, but elsewhere I've always used spaces. Rather than
installing yet another plug-in, I use a Vim autocmd that checks to see whether
I'm in a company repo, and if I am, it applies some overrides.

Links:

\- Autocmd that runs on relevant filetypes:
[https://github.com/wincent/wincent/blob/db33e22c1/roles/dotf...](https://github.com/wincent/wincent/blob/db33e22c1/roles/dotfiles/files/.vim/plugin/autocmds.vim#L61)

\- Function that detects a work repo:
[https://github.com/wincent/wincent/blob/db33e22c1/roles/dotf...](https://github.com/wincent/wincent/blob/db33e22c1/roles/dotfiles/files/.vim/autoload/wincent/liferay.vim#L5-L26)

\- Function that finds nearest Git directory:
[https://github.com/wincent/wincent/blob/db33e22c1/roles/dotf...](https://github.com/wincent/wincent/blob/db33e22c1/roles/dotfiles/files/.vim/autoload/wincent/git.vim#L1-L15)

\- Function that applies overrides:
[https://github.com/wincent/wincent/blob/db33e22c1/roles/dotf...](https://github.com/wincent/wincent/blob/db33e22c1/roles/dotfiles/files/.vim/autoload/wincent/autocmds.vim#L182-L202)

(Disclaimer: like most things in my dotfiles repo, overengineering level 99.)

~~~
mruts
Am I the only who thinks that vimscript is truly awful and much inferior to
Elisp?

~~~
TeMPOraL
As much as I like Elisp - does this matter in this context?

~~~
mruts
I guess not. Just a thought I suppose.

------
Jonanin
Previous discussions:

[https://news.ycombinator.com/item?id=14816427](https://news.ycombinator.com/item?id=14816427)

[https://news.ycombinator.com/item?id=8462825](https://news.ycombinator.com/item?id=8462825)

[https://news.ycombinator.com/item?id=10531788](https://news.ycombinator.com/item?id=10531788)

------
jchook
EditorConfig should be called CodeConformity.

The project doesn’t actually aim to provide consistent editor config. They
only want to control code formatting.

The maintainers refuse to implement certain configs on principle, such as soft
wrap.

------
joseph8th
I added an .editorconfig to every project at work. As lead it's my perogative
to enforce standards. Personally I'm not super picky. If it's not mangled I
have no opinion on formatting or editor choice of any dev on the team,
_except_ : tab inserts spaces, no auto-formatting an entire file allowed, and
the editor must be editorconfig compatible.

~~~
sergiotapia
Nah formatters are a must. If a standard isnt automatically enforced, its not
enforced period.

Mix format

Go fmt

Prettier

Etc

~~~
kemitchell
Linters in CI enforce standards. I’ll admit it’s not as nice an experience as
automatic formatting on every dev machine. But it’s how things have been done
for a long time, including recently, in JavaScript, before prettier took off.

------
fluxsauce
EditorConfig is fantastic. I've used it for years now across client projects,
internal work, and even in educational content that I've authored.

It honestly doesn't do a lot, but what it does do is standardize on things
that are easily agreed upon like line endings and tab style / width. It leaves
language specific options to purpose built linters.

~~~
smt88
But if the language-based linter is also an automatic formatter, what's the
benefit of editorconfig?

All mainstream languages have good formatters these days that go much deeper
and understand the language.

~~~
guhidalg
Isn’t the advantage that EditorConfig allows you to choose a style over the
style enforced by the language? For new languages and markup files this isn’t
a problem because they may have developed a style guide in conjunction with
the language but older languages don’t have that benefit.

~~~
smt88
Possibly, but I don't work with any teams that use any languages that don't
have their own formatters, so I don't even know which languages are still
missing one.

The languages they're using are C#, TypeScript, JavaScript, Go, Python, and
Ruby.

------
hashhar
Golang has solves this problem amazingly well. I only focus on writing code.
Everything else gofmt takes care of. The best part is that since all Golang
code is formatted the same way its quite easy to see if something is messed up
simply by the code structure.

------
nikeee
Do languages other than C# support formatter/convention configuration via
EditorConfig? Or is C# going some other way here?

Ref: [https://docs.microsoft.com/en-
us/visualstudio/ide/editorconf...](https://docs.microsoft.com/en-
us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017)

~~~
DaiPlusPlus
It’s not a language feature but an editor feature. Editors often have built-in
syntax-aware linters and refornatters that support additional rules you can
put inside editorconfig files.

Visual Studio has built-in support for editorconfig and also supplies
C#-specific formatting rules, hence why the web-page you linked-to exists.

~~~
mattnewport
I was looking at this just the other day not realizing it was something other
than just a Microsoft thing. There didn't seem to be anything to deal with
auto wrapping long lines by breaking them in sensible ways which is one of my
favorite things about clang-format for C++. ReSharper does it for C# but
doesn't do a very good job in my experience and ReSharper has such abysmal
performance in Visual Studio that I've had to turn it off despite it having
some useful features. The ability to smart wrap lines is something I haven't
found a substitute for yet for C#.

~~~
DaiPlusPlus
I use a 40-inch 4K monitor running at 96dpi so I have evolved past the need to
wrap long lines. Lines that are “too long” simply don’t exist!

~~~
mattnewport
I use a 43" 4K monitor as my main monitor and a 27" 1440p in portrait as my
secondary. I typically have the Unity editor on my main monitor though and C#
code on the secondary and in that arrangement with the font at a size I find
comfortable I still need to wrap at around 120 columns. The other arrangement
I sometimes use is two side by side windows on the 4K monitor and even that
still has a width limit.

C# is pretty bad in this regard compared to C++ because the standard
formatting rules of indenting namespaces and the fact that there are no free
functions wastes a lot of the left hand side most of the time.

------
zck
I added EditorConfig to a project recently, and was super disappointed with
the scarcity of things I could actually configure. I thought there would be
many, many config settings. But I was wrong -- there are only eight
([https://github.com/editorconfig/editorconfig/wiki/EditorConf...](https://github.com/editorconfig/editorconfig/wiki/EditorConfig-
Properties)), with one of them listed as " Supported By A Limited Number of
Editors", and the editor I was using (Intellij) is listed as supporting it,
but does not.

I wanted to configure a lot of things, like "braces at the end of the line,
not a new line by itself", or "always use braces, even in a single-statement
branch", or even "one space after 'if' before the paren".

None of these are configurable with EditorConfig. It's pretty disappointing.

~~~
vmasto
IntelliJ supports editorconfig just fine.

I'm not sure why you were disappointed, editorconfig does not advertise the
features you mentioned. For more involved autoformatting you need some kind of
tool like gofmt or Prettier for JavaScript.

~~~
zck
> IntelliJ supports editorconfig just fine.

When I set the line length config setting, and then have intellij autoformat a
file, it doesn't break lines at that length.

> I'm not sure why you were disappointed, editorconfig does not advertise the
> features you mentioned. For more involved autoformatting you need some kind
> of tool like gofmt or Prettier for JavaScript.

The elevator pitch for EditorConfig, as taken from the first sentence of its
website, is "EditorConfig helps maintain consistent coding styles for multiple
developers working on the same project across various editors and IDEs." The
things I want I consider coding styles.

------
runeb
IMO there should be two configurations for code style. One for files and one
for presentation. That way any coder can view and edit files to their own
preferences.

~~~
ken
It's almost like plain text (with primitive ASCII art arrows and such) isn't a
great user interface, even for developers! We should come up with some way of
separating the Model and View... :-)

~~~
the8472
We have not even exhausted the possibilities of augmented text. IntelliJ at
least annotates callee argument names and inferred types. For rust people are
tinkering on borrowchecker region analysis annotations.

I'm sure there's more that could be done.

~~~
ysleepy
JetBrains MPS is such an example:
[https://www.jetbrains.com/mps/](https://www.jetbrains.com/mps/)

------
Sir_Cmpwn
Added support for this to git.sr.ht a while ago. It's used to set your
preferred tab width and to show a ruler at the max line limit (which default
to 8 and 80 columns respectively if you don't have an editorconfig file).

------
egypturnash
I really love the hand-drawn versions of all the icons for the editors this
works with! They add a nice note of playfulness to the whole thing.

------
eibrahim
This is really old, so I am curious why is it on HN front page? Am I missing
something here?

~~~
tyrust
People occasionally repost content on forums. Usually it's because the OP
hasn't seen it before and thought it would be good to share. As long as it's
not excessive it can show a new bunch of people something they might not have
seen before.

e.g. I've been on HN for a few years and have never heard of this.

~~~
eibrahim
Cool. I thought there was a new features or release. It’s a great tool. I use
it VIM and VSCode

------
z3t4
The editor can detect all of these for each file. If the editor doesn't, it
probably don't support editorconfig either.

~~~
daxelrod
Editorconfig’s main benefit for me is the case when a contributor adds new
files.

~~~
z3t4
The settings can be derived from other files in the repo

~~~
daxelrod
Do you know of an editor plugin that does this reliably? I’ve tried a few in
vim that end up being more trouble than they’re worth.

The hurestics can get tricky, especially when different file types have
different kinds of indentation (got Makefiles in your otherwise two-space
indented project?) or in projects that include vendored dependencies.

~~~
z3t4
I dont know of such a plugin. But Im working on a editor that doesn't allow
you to edit indentation. The trickiest part is for the editor to know which
parts of the file it should touch when you for example insert a code block
bracket. And should the diff in SCM now include the whole block, or just the
lines where you inserted { and }. And also languages like Python where white
space matters.

------
mruts
How can you release something like this with no emacs or vim support?

~~~
kemitchell
There is both Emacs and Vim support. Scroll down to "Download a Plugin".

~~~
mruts
Fair enough. I suck.

------
0db532a0
Call me a despot, but I am of the opinion that everyone should use the same
development environment in a given team. That means same editor, same style
and same OS. People might complain in the beginning if they have to change
from another environment, but that will be short-lived, and the cost will be
minimal compared to the otherwise continuing wankery and bickering over each
developer’s subjective opinions on code style and editor. Why? The manager
says so. It’s so simple at that point.

~~~
ginko
I agree with you if that editor is Emacs and the OS is Linux.

~~~
hobofan
> Linux

Linux is not a OS, it's a kernel. You would also have to force all developers
onto the same distribution.

~~~
johnmaguire2013
Yes, Gentoo.

