refactor(gulp): Dry out linting task

This commit is contained in:
Blade Barringer
2015-11-20 07:56:59 -06:00
parent 776faddb34
commit a6fb5790e5

View File

@@ -1,42 +1,21 @@
import gulp from 'gulp'; import gulp from 'gulp';
import eslint from 'gulp-eslint'; import eslint from 'gulp-eslint';
// TODO lint client const SERVER_FILES = [
// TDOO separate linting cong between
// TODO lint gulp tasks, tests, ...?
// TODO what about prefer-const rule?
// TODO remove estraverse dependency once https://github.com/adametry/gulp-eslint/issues/117 sorted out
gulp.task('lint:server', () => {
return gulp
.src([
'./website/src/**/api-v3/**/*.js', './website/src/**/api-v3/**/*.js',
// Comment these out in develop, uncomment them in api-v3 // Comment these out in develop, uncomment them in api-v3
// './website/src/models/user.js', // './website/src/models/user.js',
// './website/src/server.js' // './website/src/server.js'
]) ];
.pipe(eslint()) const COMMON_FILES = [
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint:common', () => {
return gulp
.src([
'./common/script/**/*.js', './common/script/**/*.js',
// @TODO remove these negations as the files are converted over. // @TODO remove these negations as the files are converted over.
'!./common/script/index.js', '!./common/script/index.js',
'!./common/script/content/index.js', '!./common/script/content/index.js',
'!./common/script/src/**/*.js', '!./common/script/src/**/*.js',
'!./common/script/public/**/*.js', '!./common/script/public/**/*.js',
]) ];
.pipe(eslint()) const TEST_FILES = [
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint:tests', () => {
return gulp
.src([
'./test/**/*.js', './test/**/*.js',
// @TODO remove these negations as the test files are cleaned up. // @TODO remove these negations as the test files are cleaned up.
'!./test/api-legacy/**/*', '!./test/api-legacy/**/*',
@@ -46,8 +25,31 @@ gulp.task('lint:tests', () => {
'!./test/e2e/**/*', '!./test/e2e/**/*',
'!./test/server_side/**/*', '!./test/server_side/**/*',
'!./test/spec/**/*', '!./test/spec/**/*',
]) ];
.pipe(eslint({
let linter = (src, options) => {
return gulp
.src(src)
.pipe(eslint(options))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
// TODO lint client
// TDOO separate linting cong between
// TODO lint gulp tasks, tests, ...?
// TODO what about prefer-const rule?
// TODO remove estraverse dependency once https://github.com/adametry/gulp-eslint/issues/117 sorted out
gulp.task('lint:server', () => {
return linter(SERVER_FILES);
});
gulp.task('lint:common', () => {
return linter(COMMON_FILES);
});
gulp.task('lint:tests', () => {
let options = {
rules: { rules: {
'max-nested-callbacks': 0, 'max-nested-callbacks': 0,
'no-unused-expressions': 0, 'no-unused-expressions': 0,
@@ -61,17 +63,17 @@ gulp.task('lint:tests', () => {
'sinon': true, 'sinon': true,
}, },
plugins: [ 'mocha' ], plugins: [ 'mocha' ],
})) };
.pipe(eslint.format())
.pipe(eslint.failAfterError()); return linter(TEST_FILES, options);
}); });
gulp.task('lint', ['lint:server', 'lint:common', 'lint:tests']); gulp.task('lint', ['lint:server', 'lint:common', 'lint:tests']);
gulp.task('lint:watch', () => { gulp.task('lint:watch', () => {
gulp.watch([ gulp.watch([
'./website/src/**/*.js', SERVER_FILES,
'./common/script/**/*.js', COMMON_FILES,
'./test/**/*.js', TEST_FILES,
], ['lint']); ], ['lint']);
}); });