Use ESLint CLIEngine directly instead of gulp-eslint because it doesn't support caching yet.

Added new eslint-cli task with cache.
This commit is contained in:
Gunther Brunner
2016-01-20 23:15:56 +09:00
parent 6d46132b63
commit 42e9648da1
4 changed files with 38 additions and 3 deletions

View File

@@ -11,3 +11,4 @@ res/build/
rethinkdb_data/ rethinkdb_data/
temp/ temp/
tmp/ tmp/
.eslintcache

1
.gitignore vendored
View File

@@ -10,3 +10,4 @@
/rethinkdb_data/ /rethinkdb_data/
/temp/ /temp/
/tmp/ /tmp/
.eslintcache

View File

@@ -4,6 +4,7 @@ var gulp = require('gulp')
var gutil = require('gulp-util') var gutil = require('gulp-util')
var jsonlint = require('gulp-jsonlint') var jsonlint = require('gulp-jsonlint')
var eslint = require('gulp-eslint') var eslint = require('gulp-eslint')
var EslintCLIEngine = require('eslint').CLIEngine
var webpack = require('webpack') var webpack = require('webpack')
var webpackConfig = require('./webpack.config').webpack var webpackConfig = require('./webpack.config').webpack
var webpackStatusConfig = require('./res/common/status/webpack.config') var webpackStatusConfig = require('./res/common/status/webpack.config')
@@ -28,13 +29,14 @@ gulp.task('jsonlint', function() {
.pipe(jsonlint.reporter()) .pipe(jsonlint.reporter())
}) })
// Try to use eslint-cli directly instead of eslint-gulp
// since it doesn't support cache yet
gulp.task('eslint', function() { gulp.task('eslint', function() {
return gulp.src([ return gulp.src([
'lib/**/*.js' 'lib/**/*.js'
, 'res/**/*.js' , 'res/**/*.js'
, '!res/bower_components/**' , '!res/bower_components/**'
, '*.js' , '*.js'
, '!node_modules/**'
]) ])
// eslint() attaches the lint output to the "eslint" property // eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules. // of the file object so it can be used by other modules.
@@ -47,7 +49,33 @@ gulp.task('eslint', function() {
.pipe(eslint.failAfterError()) .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('test', ['lint', 'run:checkversion'])
gulp.task('build', ['clean', 'webpack:build']) gulp.task('build', ['clean', 'webpack:build'])
@@ -222,5 +250,9 @@ gulp.task('translate:pull', function() {
}) })
gulp.task('clean', function(cb) { gulp.task('clean', function(cb) {
del(['./tmp', './res/build'], cb) del([
'./tmp'
, './res/build'
, '.eslintcache'
], cb)
}) })

View File

@@ -89,6 +89,7 @@
"chai": "^3.4.1", "chai": "^3.4.1",
"css-loader": "^0.23.1", "css-loader": "^0.23.1",
"del": "^2.0.1", "del": "^2.0.1",
"eslint": "^1.10.3",
"eslint-loader": "^1.2.0", "eslint-loader": "^1.2.0",
"event-stream": "^3.3.2", "event-stream": "^3.3.2",
"exports-loader": "^0.6.2", "exports-loader": "^0.6.2",