From 42e9648da1564bbac9825cc3332864891a1d15f2 Mon Sep 17 00:00:00 2001 From: Gunther Brunner Date: Wed, 20 Jan 2016 23:15:56 +0900 Subject: [PATCH] Use ESLint CLIEngine directly instead of gulp-eslint because it doesn't support caching yet. Added new eslint-cli task with cache. --- .dockerignore | 1 + .gitignore | 1 + gulpfile.js | 38 +++++++++++++++++++++++++++++++++++--- package.json | 1 + 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index 0a70320c..868d0d8a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -11,3 +11,4 @@ res/build/ rethinkdb_data/ temp/ tmp/ +.eslintcache diff --git a/.gitignore b/.gitignore index f8449981..bb123750 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /rethinkdb_data/ /temp/ /tmp/ +.eslintcache diff --git a/gulpfile.js b/gulpfile.js index bafa53a3..a445a06e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,6 +4,7 @@ var gulp = require('gulp') var gutil = require('gulp-util') var jsonlint = require('gulp-jsonlint') var eslint = require('gulp-eslint') +var EslintCLIEngine = require('eslint').CLIEngine var webpack = require('webpack') var webpackConfig = require('./webpack.config').webpack var webpackStatusConfig = require('./res/common/status/webpack.config') @@ -28,13 +29,14 @@ gulp.task('jsonlint', function() { .pipe(jsonlint.reporter()) }) +// Try to use eslint-cli directly instead of eslint-gulp +// since it doesn't support cache yet gulp.task('eslint', function() { return gulp.src([ 'lib/**/*.js' , 'res/**/*.js' , '!res/bower_components/**' , '*.js' - , '!node_modules/**' ]) // eslint() attaches the lint output to the "eslint" property // of the file object so it can be used by other modules. @@ -47,7 +49,33 @@ gulp.task('eslint', function() { .pipe(eslint.failAfterError()) }) -gulp.task('lint', ['jsonlint', 'eslint']) +gulp.task('eslint-cli', function(done) { + var cli = new EslintCLIEngine({ + cache: true + }) + + var report = cli.executeOnFiles([ + 'lib/**/*.js' + , 'res/app/**/*.js' + , 'res/auth/**/*.js' + , 'res/common/**/*.js' + , 'res/test/**/*.js' + , 'res/web_modules/**/*.js' + , '*.js' + ]) + var formatter = cli.getFormatter() + console.log(formatter(report.results)) + + if (report.errorCount > 0) { + done(new gutil.PluginError('eslint-cli', new Error('ESLint error'))) + } + else { + done() + } +}) + + +gulp.task('lint', ['jsonlint', 'eslint-cli']) gulp.task('test', ['lint', 'run:checkversion']) gulp.task('build', ['clean', 'webpack:build']) @@ -222,5 +250,9 @@ gulp.task('translate:pull', function() { }) gulp.task('clean', function(cb) { - del(['./tmp', './res/build'], cb) + del([ + './tmp' + , './res/build' + , '.eslintcache' + ], cb) }) diff --git a/package.json b/package.json index 4bc6af82..6b3e3cf5 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "chai": "^3.4.1", "css-loader": "^0.23.1", "del": "^2.0.1", + "eslint": "^1.10.3", "eslint-loader": "^1.2.0", "event-stream": "^3.3.2", "exports-loader": "^0.6.2",