Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add .editorconfig file #982

Merged
merged 1 commit into from Dec 22, 2012

Conversation

Projects
None yet
5 participants
Contributor

shama commented Nov 25, 2012

Maybe a good idea to help maintain the code style? http://editorconfig.org

EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. The EditorConfig project consists of a file format for defining coding styles and a collection of text editor plugins that enable editors to read the file format and adhere to defined styles. EditorConfig files are easily readable and they work nicely with version control systems.

A few others that use .editorconfig files:

Owner

markstory commented Nov 25, 2012

Seems reasonable to me. Since its a small opt-in feature I don't see why not to add it.

Member

ADmad commented Nov 25, 2012

The insert_final_newline = true should perhaps only be applied for *.php files not all.

Contributor

shama commented Nov 25, 2012

Updated.

Member

ADmad commented Nov 25, 2012

My suggestion based on reviewing .editorconfig of few projects :)

; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

[*.php]
insert_final_newline = true    

I wonder what would be the implications of having charset = utf-8 for those who use non utf-8 encoding for their app.

Contributor

shama commented Nov 25, 2012

Cool, updated. Left out the charset to just let the editor decide.

Member

deizel commented Nov 26, 2012

I've been using this today and it is working as expected (using the recommended plugin with Sublime Text 2).

I've done some testing, and when opening PHP files (in Windows), line endings are being set to "Unix" (rather than "Windows" as confirmed previously under default settings).

Also, I can see the final new line being appended to PHP files when saving (ie. if I deleted the line and press Ctrl+S, it gets added again) and commits show the "\ No newline at end of file" comment being removed in the diff.

As I sometimes edit the same files in Windows and Linux, I certainly welcome this addition as it will prevent some version control headaches. 👍

However, I am now looking at a diff where I have committed a PHP file and a CTP file, and I can see "\ No newline at end of file" at the end of the CTP file. 👎

While it's great that this configures the editor to match the project (essentially setting ensure_newline_at_eof_on_save to true on this editor), I am left with a "half-configured" editor because of the decision to only ensure newlines on PHP files.

I assume the decision was made in fear of binary files becoming corrupted, however, I would assume that is the editor's responsibility (knowing when ensure_newline_at_eof_on_save applies or not). I'm certainly not planning on using this editor to save any binary files anyway.

My understanding of the Linux mantra is that "lines are delimited by newlines", which implies the last line in a file should end in a newline, even if the file contains binary.

@ADmad So my question is this: Can we set insert_final_newline = true for [*] and assume the text editors that respect this .editorconfig file also know how to treat binary files properly? Am I missing something?

Contributor

shama commented Nov 26, 2012

@deizel Or we could add:

[*.ctp]
insert_final_newline = true
Member

ADmad commented Nov 26, 2012

@deizel I don't have any strong arguments against having insert_final_newline = true for all files. Just wanted to err on side of caution in cause having new line at end of file might cause problems or be not desirable for some file types. If the general consensus is it won't be a problem doing it for all files then so be it.

@shama I added extra rules for .bat files and removing trailing spaces. Have made a git so that you don't have to make commit every time someone proposes a change :) https://gist.github.com/4149897

Contributor

shama commented Nov 26, 2012

@ADmad Thanks! :)

Member

deizel commented Nov 27, 2012

@shama Yes, should probably add that.. though it still leaves some others (eg. .html/js/css/sql to name a few).

@ADmad Nor do I, I just wanted to raise it for discussion. I guess it boils down to a few things:

  • Does * = "All text files" in .editorconfig-land?
  • Do we know if an extra newline cause issues for any text file formats?
  • Do enough other projects use insert_final_newline = true globally (Ruby, jQuery, phabricator, yeoman)?
Owner

markstory commented Nov 28, 2012

I can't think of a text file format that has errors with the final trailing new line. Generally all files in *nix systems expect that last newline to be there, and tools like sed & vim will add them back in without asking.

Member

ADmad commented Nov 28, 2012

@shama shama Add .editorconfig file.
Config file to help define the code style for supported editors and IDEs.
http://editorconfig.org
ff26db5
Contributor

shama commented Dec 2, 2012

Updated commit to @ADmad's gist. Thanks!

Owner

markstory commented Dec 10, 2012

@ADmad are you happy with this now?

Member

ADmad commented Dec 10, 2012

My opinion has changed to "meh" about this 😄 I am ok with whatever is unanimously decided.

Owner

lorenzo commented Dec 22, 2012

This looks good to me

@lorenzo lorenzo added a commit that referenced this pull request Dec 22, 2012

@lorenzo lorenzo Merge pull request #982 from shama/editorconfig
Add .editorconfig file
bd69979

@lorenzo lorenzo merged commit bd69979 into cakephp:master Dec 22, 2012

@shama shama deleted the shama:editorconfig branch Dec 22, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment