diff --git a/tasks/gulp-eslint.js b/tasks/gulp-eslint.js index 6875f27d4c..83930556c7 100644 --- a/tasks/gulp-eslint.js +++ b/tasks/gulp-eslint.js @@ -1,77 +1,79 @@ import gulp from 'gulp'; 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 // 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', - // 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()); + return linter(SERVER_FILES); }); gulp.task('lint:common', () => { - return gulp - .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()); + return linter(COMMON_FILES); }); gulp.task('lint:tests', () => { - return gulp - .src([ - './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/**/*', - ]) - .pipe(eslint({ - rules: { - 'max-nested-callbacks': 0, - 'no-unused-expressions': 0, - 'mocha/no-exclusive-tests': 2, - 'mocha/no-global-tests': 2, - 'mocha/handle-done-callback': 2, - }, - globals: { - 'expect': true, - '_': true, - 'sinon': true, - }, - plugins: [ 'mocha' ], - })) - .pipe(eslint.format()) - .pipe(eslint.failAfterError()); + let options = { + rules: { + 'max-nested-callbacks': 0, + 'no-unused-expressions': 0, + 'mocha/no-exclusive-tests': 2, + 'mocha/no-global-tests': 2, + 'mocha/handle-done-callback': 2, + }, + globals: { + 'expect': true, + '_': true, + 'sinon': true, + }, + plugins: [ 'mocha' ], + }; + + return linter(TEST_FILES, options); }); gulp.task('lint', ['lint:server', 'lint:common', 'lint:tests']); gulp.task('lint:watch', () => { gulp.watch([ - './website/src/**/*.js', - './common/script/**/*.js', - './test/**/*.js', + SERVER_FILES, + COMMON_FILES, + TEST_FILES, ], ['lint']); });