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,77 +1,79 @@
import gulp from 'gulp'; import gulp from 'gulp';
import eslint from 'gulp-eslint'; import eslint from 'gulp-eslint';
const SERVER_FILES = [
'./website/src/**/api-v3/**/*.js',
// Comment these out in develop, uncomment them in api-v3
// './website/src/models/user.js',
// './website/src/server.js'
];
const COMMON_FILES = [
'./common/script/**/*.js',
// @TODO remove these negations as the files are converted over.
'!./common/script/index.js',
'!./common/script/content/index.js',
'!./common/script/src/**/*.js',
'!./common/script/public/**/*.js',
];
const TEST_FILES = [
'./test/**/*.js',
// @TODO remove these negations as the test files are cleaned up.
'!./test/api-legacy/**/*',
'!./test/api/**/*',
'!./test/common/simulations/**/*',
'!./test/content/**/*',
'!./test/e2e/**/*',
'!./test/server_side/**/*',
'!./test/spec/**/*',
];
let linter = (src, options) => {
return gulp
.src(src)
.pipe(eslint(options))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
// TODO lint client // TODO lint client
// TDOO separate linting cong between // TDOO separate linting cong between
// TODO lint gulp tasks, tests, ...? // TODO lint gulp tasks, tests, ...?
// TODO what about prefer-const rule? // TODO what about prefer-const rule?
// TODO remove estraverse dependency once https://github.com/adametry/gulp-eslint/issues/117 sorted out // TODO remove estraverse dependency once https://github.com/adametry/gulp-eslint/issues/117 sorted out
gulp.task('lint:server', () => { gulp.task('lint:server', () => {
return gulp return linter(SERVER_FILES);
.src([
'./website/src/**/api-v3/**/*.js',
// Comment these out in develop, uncomment them in api-v3
// './website/src/models/user.js',
// './website/src/server.js'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}); });
gulp.task('lint:common', () => { gulp.task('lint:common', () => {
return gulp return linter(COMMON_FILES);
.src([
'./common/script/**/*.js',
// @TODO remove these negations as the files are converted over.
'!./common/script/index.js',
'!./common/script/content/index.js',
'!./common/script/src/**/*.js',
'!./common/script/public/**/*.js',
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}); });
gulp.task('lint:tests', () => { gulp.task('lint:tests', () => {
return gulp let options = {
.src([ rules: {
'./test/**/*.js', 'max-nested-callbacks': 0,
// @TODO remove these negations as the test files are cleaned up. 'no-unused-expressions': 0,
'!./test/api-legacy/**/*', 'mocha/no-exclusive-tests': 2,
'!./test/api/**/*', 'mocha/no-global-tests': 2,
'!./test/common/simulations/**/*', 'mocha/handle-done-callback': 2,
'!./test/content/**/*', },
'!./test/e2e/**/*', globals: {
'!./test/server_side/**/*', 'expect': true,
'!./test/spec/**/*', '_': true,
]) 'sinon': true,
.pipe(eslint({ },
rules: { plugins: [ 'mocha' ],
'max-nested-callbacks': 0, };
'no-unused-expressions': 0,
'mocha/no-exclusive-tests': 2, return linter(TEST_FILES, options);
'mocha/no-global-tests': 2,
'mocha/handle-done-callback': 2,
},
globals: {
'expect': true,
'_': true,
'sinon': true,
},
plugins: [ 'mocha' ],
}))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}); });
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']);
}); });