EditorConfig
editorconfig.org
editorconfig.org
What a neat trick I had no idea. Been renaming those files on the cli all this time.
On a related note: Why has it gone the way that I must look at code your way. Is there no chance of decoupling the presentation with logic like the web has long preached us (not saying that worked). Tabs to spaces shouldn't be some messy commit regardless of your preference on the matter.
Anyway, nice project. I understand your search preferences up from the project root not down from my preferences because it's controlling other people's coding standards.
PS: Whooop on the Windows trick! So useful.
But yes, having a syntax tree would solve this problem quite nicely.
(But to make it work universally you have to decide on a representation of this syntax tree to be able to represent it in plain text files to make it work with all the editors and IDEs that don't support that syntax tree stuff... And then we're back to .editorconfig, aren't we?)
A VCS for syntax trees means you need the One True Data Format(tm) for syntax trees in any language. Finding consensus on formatting per project is easier than unifying all syntax tree representations globally.
(Aside: I built a cool proof of concept for what I think is the most useful "smart middle ground" here, which is to use syntax highlighting lexers (tokenizers) for a useful effect in creating smart character-based diffs. Syntax highlighting lexers are designed for intermediate code and with output as ordinary character diffs you don't have to bikeshed a universal token stream format. The tokenized diffs were cleaner and faster than the equivalent non-tokenized character diff. https://github.com/WorldMaker/tokdiff if anyone wants to play with it.)
http://news.squeak.org/2008/08/15/all-new-monticello-2/
I had no idea there was such a new rewrite (2008), but then I keep forgetting that DVCS are rather new (as in popular, free-software DVCS are pretty new - git is just over 10 years).
[1] http://www.colorforth.com/cf.htm [It would appear that the on-disk representation is rather simple and straight forward, but you're only supposed to use a ColorForth aware editor (eg: ColorForth)]
Are you saying git is not popular, is not free software, or something else?
It would be rad if an editor like Sublime or Atom understood columns and displayed code that way without needing to reindent everything in the file every time you add a longer key.
[1] http://nickgravgaard.com/elastic-tabstops/ [2] https://discuss.atom.io/t/elastic-tabstops/16/23
body {
font-size: 16px;
margin-bottom: 100px;
padding-top: 40px;
color: rgb(100, 100, 100);
background-color: rgb( 90, 255, 3);
} body {
width: 400px;
margin: 20px;
position: absolute;
bottom: 0;
right: 0;
background: #ccc;
}[0]: https://github.com/isaacs/github/issues/170#issuecomment-137...
Now I'm crazy sensitive to whitespace and formatting discrepancies that show up in .js or .css files from different environments. It seems like EditorConfig has a shot at improving this, particularly since GitHub supports it.
Next step, strict linters/formatters for all languages.
Edit: Based on other comments pointing to the Javascript standard style project, I found this to auto format .js files in Sublime Text:
[0] http://vimdoc.sourceforge.net/htmldoc/options.html#%27modeli...
[0] http://www.gnu.org/software/emacs/manual/html_node/emacs/Spe...
pd: the last thing I want as a developer is a developer on Windows overriding my OSX keyboard shortcuts (or viceversa).
Anyway, for JavaScript there's the standard[1] and semistandard[2] projects. They are different from other style guides because they're standalone applications that would fail your tests if your files do not adhere to the standard (if set up correctly). Think of them as unconfigurable linters.
[1] https://github.com/feross/standard [2] https://github.com/Flet/semistandard
Then have some hooks in place that will run code through standard again in a pre-commit hook, and then PR's on GitHub are also ran through standard.
charset
indent_style
indent_size
tab_width
end_of_line
trim_trailing_whitespace
insert_final_newline
These are all sensible things to enforce (with the exception of tab_width, which is actually a display preference). Subjectively, other things are mostly flexible.For charset, this needs to be defined since charsets share byte encodings:
http://www.fileformat.info/info/charset/UTF-8/list.htm
http://www.fileformat.info/info/charset/US-ASCII/list.htm
Same goes for new line at the end of the file, how do you know ALL files of this type are meant to end with a new line or not?
Inference doesn't completely solve the problem that editorconfig solves. That said, if you don't want editorconfig then don't use it. If you're working on a project that uses editorconfig, feel free to ignore it - as long as you adhere to the code style of that project. editorconfig is simply a tool to help you adhere to a project code guidelines.
> Crucially, what about new files?
vim-sleuth handles this one by looking at similar files in the same directory (or the rest of the tree, if it doesn't find any.) > For charset, [...]
Almost all code bases use UTF-8 without BOM, which also happens to be the default encoding in most editors. > Same goes for new line at the end of the file,
> how do you know ALL files of this type are meant
> to end with a new line [...] ?
POSIX wants the newline.I get your point though. I used to use editorconfig myself, but it didn't really do anything for me. IMHO linters/formatters do a much better job.
Linters and formatters are great for enforcing code styles but they tend to be per language and require more configuration, shy of ripping off an existing spec.
If you don't want to go the whole hog and only need some basic constraints then editorconfig is easy to throw into a repo root.
Does anyone on HN have suggestions for code style guides with cross IDE support? Ideally I would like something similar to Google's code style guidelines with settings to import into IntelliJ and Eclipse for Java, html/css, sass, JavaScript, maybe even frameworks such angular. The Google guidelines only appear to have IDE settings for Java (in this list).