For example, when I open a file in Atom that contains CRLF line endings, it changes them to LF based on my editorconfig settings, but I'm not sure if this is the correct behaviour.
Could you please clarify in the documentation whether settings should be applied when opening files or when saving them?
IMHO it should only apply settings when saving a file, as you may just open a file to read it with no intention of making any changes.
I guess it's a bit tricky with the end_of_line setting, because if you start editing, it would insert LFs into a file with CRLFs, and you'd have mixed line endings until the file was saved.
The FAQ entry is not really clear about these settings.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
As the name of this EditorConfig project implies, it changes your editor's settings on file open or tab switch. This means any new lines you add will have the correct line endings, but technically, it shouldn't have to do any kind of transformation to the actual file on file open or file save, because it could inadvertently change the whole file into the configured line endings, which isn't always the desired outcome, especially where file diffs are concerned.
@jedmao So am I right in saying that the implementation in atom-editorconfig is incorrect? It should not be doing any full-file transformations?
My "opinion" has evolved into this mindset about how an EditorConfig plugin should be implemented; however, I have made implementations years ago that violated what I now believe. I know there has definitely been some blurry lines about how a plugin should be supporting EditorConfig and we could definitely benefit from some clarification here, which is probably why atom-editorconfig works the way it does (not a lot of guidance).
That said, yes, I do believe the atom-editorconfig plugin is incorrect in its implementation, but only because there hasn't really been any guidance. I, however, do not make the rules. This is a community and these are my own opinions. I'd be curious to hear what other members of the EditorConfig organization feel about this as well.
If I was to provide rules for plugin authors I would say:
Changes editor settings on file open:
Transforms file on file save:
Truly, if EditorConfig only tampered with editor settings as a single responsibility, we wouldn't even have file-save transformations, but this is where we are.
I agree 100%. I would add that, if one or more of the latter 3 options can be supported via an editor setting (some editors support "save actions"), then that should be the preferred implementation method.
Could we ping some other members for their opinion, or should we just wait for that input?
It would be extremely nice to publish a guide for plugin developers that clarified all of this. I agree with you that save actions should be the preferred method for supported editors.
@treyhunner @xuhdev what do you think?
This Wiki page (linked on the bottom of the homepage) is the best we have right now.
@jedmao I agree with your assessment of the "on open" and "on save" settings. Those are ideals/suggestions though since a brand new file doesn't yet have a name or location in some editors.
Feel free to edit/extend that wiki page or suggest something better. 👍
@treyhunner I think that document is great. Just need to add a section with some specifics (after Christmas). :)
For some unknown reason, I've been blocked by @sindresorhus, so I'm unable to submit an issue to atom-editorconfig.
This is what I was going to submit:
Title: The plug-in should not change files when they are opened
Please refer to https://github.com/editorconfig/editorconfig/issues/248.
It should only change editor settings, and *possibly* make changes on file *save*.
Correcting this may also resolve #56, #59, https://github.com/TypeStrong/atom-typescript/issues/731, and others that I'm not aware of.
Please feel free to submit this on my behalf.