edx/edx-platform — pull request #3272 by valera-rozuvan (2014-04-08 22:20:29+00:00)
Title: Introducing JSHint.

**Description**

I want to propose the following guidelines to all future JavaScript code changes.

1.) All authors that write and submit JavaScript code (as a pull request, or a separate commit) should run JSHint against the code. The configuration file `.jshintrc` (to be used by all developers) will be placed in the `edx-platfoirm` root. When `jshint` runs, it first checks for `.jshintrc` file in the same directory as the source file, and then travels up the source tree, until it either finds a `.jshintrc` file or (if no `.jshintrc` file is found) uses built-in defaults. Our aim that all developers run JSHint with a standard configuration file, and that there are no hard-errors (see NOTE at the end) reported by JSHint.

2.) When in doubt about JSHint errors/warnings - use the latest JSHint from http://www.jshint.com/install/ .

3.) All new JavaScript files should use the following template:

(function (globalVar1, globalVar2, ...) {
'use strict';
// Your code goes here. In this code you can use globalVar1 etc.
// and not get an "used before defined" JSHint error. Also, being
// explicit about what is global and what is a good way to go!
}).call(this, window.fullNameGlobalVar1, window.fullNameGlobalVar2, ...);

4.) All existing JavaScript files that are modified should be updated so that they pass against JSHint using the edx-platform `.jshintrc` file, and rewritten to use the wrapper anonymous function template from above.

**NOTE**: I believe that only JSHint warnings should be disregarded of the type "unused variable", when that unused variable is a function parameter that can't be removed. For example:

(function ($) {
'use strict';

var test = ['a', 'b', 'c'];

$.each(test, function (index, value) {
console.log(value);
});
}).call(this, window.jQuery);

In this case JSHint will give a warning about `index` not being used. It is safe to disregard these kind of warning.

**Special thanks** to @jmclaus for providing his original `.jshintrc` file! It was modified a bit.

**Motivation**

Often, JShint will catch silly errors right in the editor. You will see that you have coded something wrong without having to start up Studio or LMS and checking your changes in the browser. We all know the pain of waiting for the system to start up only to find that you have let a little JavaScript syntax error slip by.

Also, for a long time we are without a JavaScript standard and guidelines. I think with the introduction of JSHint, JavaScript code in edX will start to be formalized and standardized.

**Reviewers**

I want to hear the thoughts about this PR from all JavaScript developer at edX who are interested in improving the quality of JavaScript code at edX. Especially from:

- @singingwolfboy
- @cahrens
- @polesye
- @jmclaus