From 5f55c7ab20d60d9358364a0b494f1e36a9fa0453 Mon Sep 17 00:00:00 2001 From: Tankred Hase Date: Sat, 30 Jan 2016 17:45:01 +0700 Subject: [PATCH] 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) --- .jscsrc | 4 ++++ .jshintrc | 67 ++++++++++++++++++++++++---------------------------- Gruntfile.js | 27 +++++++++++++++++---- package.json | 1 + 4 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 .jscsrc diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 00000000..7d15b2b9 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,4 @@ +{ + "disallowTrailingWhitespace": true, + "validateIndentation": 2 +} \ No newline at end of file diff --git a/.jshintrc b/.jshintrc index de1188fd..f01e0f03 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,39 +1,34 @@ { - "indent": 2, - "strict": true, - "globalstrict": true, - "node": true, - "browser": true, - "nonew": true, - "curly": true, - "eqeqeq": true, - "immed": true, - "newcap": true, - "regexp": true, - "evil": true, - "eqnull": true, - "expr": true, - "trailing": true, - "undef": true, - "unused": true, + "strict": true, + "globalstrict": true, + "node": true, + "browser": true, + "nonew": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "newcap": true, + "regexp": true, + "evil": true, + "eqnull": true, + "expr": true, + "undef": true, + "unused": true, - "predef": [ - "console", - "Promise", - "importScripts", - "process", - "Event", - "self", - "describe", - "it", - "sinon", - "mocha", - "before", - "beforeEach", - "after", - "afterEach" - ], - - "globals": { - } + "globals": { + "console": true, + "Promise": true, + "importScripts": true, + "process": true, + "Event": true, + "self": true, + "describe": true, + "it": true, + "sinon": true, + "mocha": true, + "before": true, + "beforeEach": true, + "after": true, + "afterEach": true + } } \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 123c3734..1f37c3f1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,10 +1,13 @@ +'use strict'; + module.exports = function(grunt) { var version = grunt.option('release'); var fs = require('fs'); + var browser_capabilities; - if (process.env.SELENIUM_BROWSER_CAPABILITIES != undefined) { - var browser_capabilities = JSON.parse(process.env.SELENIUM_BROWSER_CAPABILITIES); + if (process.env.SELENIUM_BROWSER_CAPABILITIES !== undefined) { + browser_capabilities = JSON.parse(process.env.SELENIUM_BROWSER_CAPABILITIES); } // Project configuration. @@ -102,7 +105,20 @@ module.exports = function(grunt) { } }, 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: { dist: { @@ -189,6 +205,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-text-replace'); grunt.loadNpmTasks('grunt-jsbeautifier'); grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-jscs'); grunt.loadNpmTasks('grunt-jsdoc'); grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.loadNpmTasks('grunt-mocha-test'); @@ -242,12 +259,12 @@ module.exports = function(grunt) { if (err) { return done(err); } - done(); + done(); }); }); // 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('coveralls', ['copy:zlib', 'mocha_istanbul:coveralls']); grunt.registerTask('saucelabs', ['default', 'copy:browsertest', 'connect', 'saucelabs-mocha']); diff --git a/package.json b/package.json index 7731dcc3..f292d6a6 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "grunt-contrib-jshint": "~0.12.0", "grunt-contrib-uglify": "~0.11.0", "grunt-jsbeautifier": "~0.2.10", + "grunt-jscs": "^2.7.0", "grunt-jsdoc": "~1.1.0", "grunt-mocha-istanbul": "^3.0.1", "grunt-mocha-test": "~0.12.7",