Question as in the title. Are You using EditorConfig in your projects?
- Yes
- Yes, but not in Elixir projects
- No
- I didnât know about EditorConfig
0 voters
Question as in the title. Are You using EditorConfig in your projects?
0 voters
I marked yes, although I donât use it in all my projects (or even most of them). But I like having it and want to use it in more projects. Even if it is only as documentation about the expected config.
It is more about using it anywhere. I understand that most people will not use it everywhere, because sometimes it doesnât make sense, because internal projects not always need them.
For me mix format
(called automatically on each file save) handles all formatting, so there is no need for such extra plugin in my editor.
I understand that itâs intended for projects with more than one developer, but if I remember correctly every commit may be rejected if specified check fails which is also possible to pair with mix format
task.
Elixir has the formatter, hooks and CI make sure everything is well formatted.
Same for go, python, rust, or anything else the team or community agreed on a formatter to use.
Though for some languages or configstyle files there is no or linter available, there we do use editor config.
For me it is irritating as the editor need to reload edited file after each save, which sometimes screw the undo (I have persistent undo in Vim enabled). Additionally it fires file watchers twice, so sometimes it can cause âwasted cyclesâ when running tests twice after each change.
Additionally mix format
will not work with files that arenât UTF-8. While most editors use that by default it not always can be a case, for example Windows sometimes use UTF-16 which will crash the mix format
:
$ echo 'Ćukasz' | iconv -f UTF-8 -t UTF-16 | mix format -
mix format failed for stdin
** (UnicodeConversionError) invalid encoding starting at <<254, 255, 1, 65, 0, 117, 0, 107, 0, 97, 0, 115, 0, 122, 0, 10>>
(elixir 1.10.0) lib/string.ex:2223: String.to_charlist/1
(elixir 1.10.0) lib/code/formatter.ex:198: Code.Formatter.to_algebra/2
(elixir 1.10.0) lib/code/formatter.ex:236: Code.Formatter.to_algebra!/2
(elixir 1.10.0) lib/code.ex:645: Code.format_string!/2
(mix 1.10.0) lib/mix/tasks/format.ex:418: Mix.Tasks.Format.format_file/2
(elixir 1.10.0) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(elixir 1.10.0) lib/task/supervised.ex:35: Task.Supervised.reply/5
(stdlib 3.10) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
$ echo 'Ćukasz' | iconv -f UTF-8 -t CP1250 | mix format -
mix format failed for stdin
** (UnicodeConversionError) invalid encoding starting at <<163, 117, 107, 97, 115, 122, 10>>
(elixir 1.10.0) lib/string.ex:2223: String.to_charlist/1
(elixir 1.10.0) lib/code/formatter.ex:198: Code.Formatter.to_algebra/2
(elixir 1.10.0) lib/code/formatter.ex:236: Code.Formatter.to_algebra!/2
(elixir 1.10.0) lib/code.ex:645: Code.format_string!/2
(mix 1.10.0) lib/mix/tasks/format.ex:418: Mix.Tasks.Format.format_file/2
(elixir 1.10.0) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(elixir 1.10.0) lib/task/supervised.ex:35: Task.Supervised.reply/5
(stdlib 3.10) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Yes, but it will not manage all files in projects. Erlang files or Makefiles will not be formatted via mix format
. And if you configure tabstop
option then GitHub will also show files in diffs and file display with proper indentation depth.
What is more, some editors (for sure Vim, but I assume that others as well) can display vertical line on the âline length limitâ which is useful to write code âformattedâ already, without the need for running mix format
in the background. None of the editors I know can read .formatter.exs
to do so (however I could easily implement that for Vim if needed).
The for me in EditorConfig is to make it pass before even being sent to the CI, as most of these âfixesâ can be applied automatically by editor (proper indentation characters, indentation width, charsets, etc.). This is also handy for root = true
option for a lot of tools, as this marks the âmainâ directory of the project and such tools can âstopâ when traversing the directory tree in lookup for âroot directoryâ.
Heh ⊠what should I say ⊠I recommend Sublime Text 3
I do not have a tests for each file change as itâs generally bad idea. It may be good for small bugfix, but in normal case (enhancement or new feature) which requires to add and/or modify many files it would cause unnecessary fails.
Itâs why I do not use Windows
at all. They have their own standards. Look that people in France think that French is most important and everyone should know it, but it does not changes anything in typical daily English programming âŠ
Well ⊠Elixir
was created for some purpose ⊠If Erlang
would have syntax
, code, formatter and everything else from Elixir
then Elixir
would not be created.
But seriously ⊠Makefile
is good example, but itâs not like that itâs used in really big percent of projects. Erlang
team could create formatter if they would like to. The better way is to create formatter for each language rather than implement support for all languages in each editor which is obvious waste of time.
As said Makefile
is a different case, but itâs really one file and alone does not gives enough arguments to introduce a generic formatter.
This should be able to work with Elixir
formatter. Of course not many editors know .formatter.exs
, but there is really no need for that. Thatâs why many editors have support for plugins.
Thatâs why I use the LS to format, the editor should send the buffer before save and wait for the formatter to return it and then save that as new buffer. Neither Emacs, nor visual code ever hat a problem with undo that way.
Is utf-16 even accepted by the elixir parser? So far I assumed that utf-8 were required for elixir source files.
I use .editorconfig
files only to keep some basics consistent for text editors that donât know about the formatters. Itâs extremely insufficient with a lot of settings though, so I have a couple changes in rustfmt.toml
and similar for Elixir as well (I use freedom formatter for elixir as I like some settings changed).