From 43a2220298e497a9cdc4fc233550f61a61ca611e Mon Sep 17 00:00:00 2001 From: Aileen Nowak Date: Mon, 3 Oct 2016 10:30:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0=20=20Gulp=20lint=20task=20(#7458)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #7427 Adds a `gulp lint` task, as well as subtasks `gulp jshint`, `gulp jscs` and `gulp json` which can be started independently. --- gulpfile.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 +++++ 2 files changed, 67 insertions(+) diff --git a/gulpfile.js b/gulpfile.js index cba29e4d57..7a39ac540d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,6 +2,9 @@ var gulp = require('gulp'), livereload = require('gulp-livereload'), nodemon = require('gulp-nodemon'), gutil = require('gulp-util'), + jscs = require('gulp-jscs'), + jshint = require('gulp-jshint'), + jsonlint = require('gulp-jsonlint'), chalk = require('chalk'), runSequence = require('run-sequence').use(gulp), argv = require('minimist')(process.argv.slice(2)), @@ -451,6 +454,65 @@ gulp.task('setup', function (cb) { } }); +gulp.task('jscs', function () { + return gulp.src( + [ + '*.js', + '!config*.js', + 'core/*.js', + 'core/server/**/*.js', + 'core/test/**/*.js', + '!core/test/coverage/**', + '!core/shared/vendor/**/*.js' + ]) + .pipe(jscs('.jscsrc')) + .pipe(jscs.reporter()) + .pipe(jscs.reporter('failImmediately')); +}); + +gulp.task('jshint', function () { + return gulp.src( + [ + '*.js', + '!config*.js', + 'core/*.js', + 'core/server/**/*.js', + 'core/test/**/*.js', + '!core/test/coverage/**', + '!core/shared/vendor/**/*.js' + ]) + .pipe(jshint('.jshintrc')) + .pipe(jshint.reporter('jshint-stylish')) + .pipe(jshint.reporter('fail')); +}); + +gulp.task('json', function () { + return gulp.src( + [ + '*.json', + 'core/*.json', + 'core/server/**/*.json', + 'core/test/**/*.json', + '!core/test/utils/fixtures/import/zips/**/*.json', + '!core/test/coverage/**', + '!core/shared/vendor/**/*.json' + ]) + .pipe(jsonlint()) + .pipe(jsonlint.reporter()); +}); + +gulp.task('lint', function (cb) { + console.info(chalk.cyan('Starting linting and code style checker 🎨 ...')); + runSequence(['jscs', 'jshint', 'json'], function (err) { + if (err) { + swallowError(err, false); + } else { + console.info(chalk.green('No code or style errors ✅')); + cb(); + } + }); +}); + // Default task at the moment is development. // TODO: As soon as we have a production build task, we should // check the current environment and use the production build as diff --git a/package.json b/package.json index e91fa0bd8e..5a1e9402a5 100644 --- a/package.json +++ b/package.json @@ -101,10 +101,15 @@ "grunt-update-submodules": "0.4.1", "gulp": "3.9.1", "gulp-git-submodule": "1.0.1", + "gulp-jscs": "4.0.0", + "gulp-jshint": "2.0.1", + "gulp-jsonlint": "1.1.2", "gulp-livereload": "3.8.1", "gulp-nodemon": "2.1.0", "gulp-util": "3.0.7", "istanbul": "0.4.5", + "jshint": "2.9.3", + "jshint-stylish": "2.2.1", "matchdep": "1.0.1", "minimist": "1.2.0", "mocha": "3.1.0",