AcklenAvenue/DatosAbiertos — pull request #59 by alejandro (2013-10-15 20:19:14+00:00)
Title: [wip] Code JSHint'd

The fact that JavaScript can be written in so many differents ways leads to code with a huge complexity, and in this case with many contributors merge conflict will happen if people prefer: tabs vs spaces, double vs single quotes, etc. So, I wanted to start running JSHint over the server code to define some "code standards" to write JavaScript in DatosAbiertos:

TL;DR

- Prefer single quotes *always*
- `'use strict';` in _every_ file
- Use config.js to store settings stuff (no more `var dbPort =`, ...)
- Removed unnecesary semicolons (`function(){};`)
- comparison agains true, false, null, should be avoided

BTW this is totally open for debate, any thoughts?

## Long Version:
Since we are using Node as backend, JavaScript needs to be standarized in one way or other:

- single quotes are prefered:

var q = require('q');
console.log('this is a msg');

- Lines of code no longer than 100 rows, if you are using sublime open "Preferences->Settings -
User" and add:

"rulers": [ 80, 100]

- long string concatenation should be avoided (optional):

// bad
var number = 10;
var obj = { id: 13};
var longString = 'this is a huge string with ' + number + ' and and object: ' + obj.id;

- function's declaration don't need semicolons at the end of the statement:

function myFn(){

}; // <- not needed, JSHint will complain: "unnecesary semicolon"

- comparation against `true`, `false`, and `null` should be avoided:

// bad

if (stuff == true) {}
if (stuff !== null){}

// good (same as above)

if (stuff){}

Other stuff you should find useful working with Node:

- `console.log` behaves like `fmt!` in other languages, so instead of doing:

console.log('this is a number: ' + number + ' and this is my name:' + name);

You can do:

console.log('this is a number %d and this is my name %s', number, name);

Cheers.