ractivejs/ractive — pull request #666 by Rich-Harris (2014-05-04 17:05:56+00:00)
Title: Coding style

This is intended to start a discussion more than anything else.

Now that there's a few of us with write access to Ractive repos, I think it's probably worth agreeing on a style guide. I won't bother going into *why* style guides are valuable; I assume we're all basically in agreement that they are, but will likely have differing opinions as to the details.

Personally, I like [Idiomatic.js](https://github.com/rwaldron/idiomatic.js/), and the code I've written mostly hews to that guide. Some of its guidelines aren't totally uncontroversial - for example it recommends more whitespace than most developers typically use - but it seems to be pretty well thought through and widely used.

As an experiment I added [grunt-jscs-checker](https://github.com/gustavohenke/grunt-jscs-checker/) to the repo along with a bunch of rules that more or less follow Idiomatic. Which means that in this branch you can do...

```
grunt jscs
```

...and you'll get a list of 'errors' it identifies. I started going through the errors to get a sense of how much pain this would add; it's a bit of a headache to do all in one go (some stuff can be find+replaced, a lot can't) but I don't think it would be overly burdensome to ensure that new code adhered to whatever jscs config we agreed upon.

So as I see it there are a few questions worth coming to a consensus on:

* Which style guide do we like?
* How rigidly should it be enforced? Should style violations fail the build?
* Is jscs (in the form of grunt-jscs-checker) the best tool to use?
* Is it worth experimenting with automatic code beautifiers, or should sticking to the style guide be done consciously? If automatic, are there any tools up to the task?

My votes:

* Idiomatic
* Should *probably* fail the build. If it's an automated thing that we've agreed upon, it saves us passive-aggressively editing each others' code :-)
* jscs seems pretty good, though possibly a bit inflexible on some of the finer points
* Not sure

Some of this stuff is no-brainer territory, I think - for example disallowing trailing whitespace. (My editor is set up to strip trailing whitespace when files are saved, so if you've seen commits of yours amended later to remove trailing whitespace, it's Sublime, not me being OCD!)