diff --git a/.gitignore b/.gitignore index debce4dd2..516970e91 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build/ tags .DS_Store Makefile +node_modules/ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 000000000..f7daa6924 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,19 @@ +{ + // Environments + "browser": true, + "devel": true, + "es5": true, + "worker": true, + + // Enforcing + + // Relaxing + "boss": true, + "funcscope": true, + "globalstrict": true, + "loopfunc": true, + "maxerr": 1000, + "nonstandard": true, + "sub": true, + "validthis": true +} diff --git a/make.js b/make.js index 9a96f796e..bcba694bf 100644 --- a/make.js +++ b/make.js @@ -971,6 +971,29 @@ target.lint = function() { crlfchecker.checkIfCrlfIsPresent(LINT_FILES); }; +// +// make jshint +// +target.jshint = function() { + cd(ROOT_DIR); + echo(); + echo('### Linting JS files (this can take a while!)'); + + var LINT_FILES = [//'make.js', + //'external/builder/*.js', + //'external/crlfchecker/*.js', + 'src/', + //'web/*.js', + //'test/*.js', + //'test/unit/*.js', + //'extensions/firefox/*.js', + //'extensions/firefox/components/*.js', + //'extensions/chrome/*.js' + ]; + + exec('jshint --reporter test/reporter.js ' + LINT_FILES.join(' ')); +}; + // // make clean // diff --git a/test/reporter.js b/test/reporter.js new file mode 100644 index 000000000..a203d1c65 --- /dev/null +++ b/test/reporter.js @@ -0,0 +1,28 @@ +"use strict"; + +module.exports = { + reporter: function (res) { + var len = 0; + var str = ""; + + res.forEach(function (r) { + var file = r.file; + var err = r.error; + + switch(err.code) { + case 'W004': // variable is already defined + case 'W018': // confusing use of ! + break; + default: + len++; + str += file + ": line " + err.line + ", col " + + err.character + ", " + err.reason + "\n"; + } + }); + + if (str) { + process.stdout.write(str + "\n" + len + " error" + + ((len === 1) ? "" : "s") + "\n"); + } + } +};