Add linting to grunt test job

* Add grunt-jscs and .jscsrc (lint trailing whitespaces and indentation length)
* Cleanup .jshintrc (use globals instead of deprecated predefs)
* Add Gruntfile.js and *.json linting to npm test

N.B. This does not lint the whole src/ directory during grunt test but
this should definitely be our goal. Please try to de-lint any js files
you touch during development using a texteditor that support linting
(Sublime Text 3 and SublimeLinter 3 with jshint/jscs plugins work great)
This commit is contained in:
Tankred Hase 2016-01-30 17:45:01 +07:00
parent a49b5ce1c5
commit 5f55c7ab20
4 changed files with 58 additions and 41 deletions

4
.jscsrc Normal file
View File

@ -0,0 +1,4 @@
{
"disallowTrailingWhitespace": true,
"validateIndentation": 2
}

View File

@ -1,39 +1,34 @@
{ {
"indent": 2, "strict": true,
"strict": true, "globalstrict": true,
"globalstrict": true, "node": true,
"node": true, "browser": true,
"browser": true, "nonew": true,
"nonew": true, "curly": true,
"curly": true, "eqeqeq": true,
"eqeqeq": true, "immed": true,
"immed": true, "newcap": true,
"newcap": true, "regexp": true,
"regexp": true, "evil": true,
"evil": true, "eqnull": true,
"eqnull": true, "expr": true,
"expr": true, "undef": true,
"trailing": true, "unused": true,
"undef": true,
"unused": true,
"predef": [ "globals": {
"console", "console": true,
"Promise", "Promise": true,
"importScripts", "importScripts": true,
"process", "process": true,
"Event", "Event": true,
"self", "self": true,
"describe", "describe": true,
"it", "it": true,
"sinon", "sinon": true,
"mocha", "mocha": true,
"before", "before": true,
"beforeEach", "beforeEach": true,
"after", "after": true,
"afterEach" "afterEach": true
], }
"globals": {
}
} }

View File

@ -1,10 +1,13 @@
'use strict';
module.exports = function(grunt) { module.exports = function(grunt) {
var version = grunt.option('release'); var version = grunt.option('release');
var fs = require('fs'); var fs = require('fs');
var browser_capabilities;
if (process.env.SELENIUM_BROWSER_CAPABILITIES != undefined) { if (process.env.SELENIUM_BROWSER_CAPABILITIES !== undefined) {
var browser_capabilities = JSON.parse(process.env.SELENIUM_BROWSER_CAPABILITIES); browser_capabilities = JSON.parse(process.env.SELENIUM_BROWSER_CAPABILITIES);
} }
// Project configuration. // Project configuration.
@ -102,7 +105,20 @@ module.exports = function(grunt) {
} }
}, },
jshint: { jshint: {
all: ['src/**/*.js'] src: ['src/**/*.js'],
build: ['Gruntfile.js', '*.json'],
options: {
jshintrc: '.jshintrc'
}
},
jscs: {
src: ['src/**/*.js'],
build: ['Gruntfile.js'],
options: {
config: ".jscsrc",
esnext: false, // If you use ES6 http://jscs.info/overview.html#esnext
verbose: true, // If you need output with rule names http://jscs.info/overview.html#verbose
}
}, },
jsdoc: { jsdoc: {
dist: { dist: {
@ -189,6 +205,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-text-replace'); grunt.loadNpmTasks('grunt-text-replace');
grunt.loadNpmTasks('grunt-jsbeautifier'); grunt.loadNpmTasks('grunt-jsbeautifier');
grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-jsdoc'); grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.loadNpmTasks('grunt-mocha-istanbul');
grunt.loadNpmTasks('grunt-mocha-test'); grunt.loadNpmTasks('grunt-mocha-test');
@ -242,12 +259,12 @@ module.exports = function(grunt) {
if (err) { if (err) {
return done(err); return done(err);
} }
done(); done();
}); });
}); });
// Test/Dev tasks // Test/Dev tasks
grunt.registerTask('test', ['copy:zlib', 'mochaTest']); grunt.registerTask('test', ['jshint:build', 'jscs:build', 'copy:zlib', 'mochaTest']);
grunt.registerTask('coverage', ['copy:zlib', 'mocha_istanbul:coverage']); grunt.registerTask('coverage', ['copy:zlib', 'mocha_istanbul:coverage']);
grunt.registerTask('coveralls', ['copy:zlib', 'mocha_istanbul:coveralls']); grunt.registerTask('coveralls', ['copy:zlib', 'mocha_istanbul:coveralls']);
grunt.registerTask('saucelabs', ['default', 'copy:browsertest', 'connect', 'saucelabs-mocha']); grunt.registerTask('saucelabs', ['default', 'copy:browsertest', 'connect', 'saucelabs-mocha']);

View File

@ -42,6 +42,7 @@
"grunt-contrib-jshint": "~0.12.0", "grunt-contrib-jshint": "~0.12.0",
"grunt-contrib-uglify": "~0.11.0", "grunt-contrib-uglify": "~0.11.0",
"grunt-jsbeautifier": "~0.2.10", "grunt-jsbeautifier": "~0.2.10",
"grunt-jscs": "^2.7.0",
"grunt-jsdoc": "~1.1.0", "grunt-jsdoc": "~1.1.0",
"grunt-mocha-istanbul": "^3.0.1", "grunt-mocha-istanbul": "^3.0.1",
"grunt-mocha-test": "~0.12.7", "grunt-mocha-test": "~0.12.7",