mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
refactor(gulp): Dry out linting task
This commit is contained in:
@@ -1,42 +1,21 @@
|
||||
import gulp from 'gulp';
|
||||
import eslint from 'gulp-eslint';
|
||||
|
||||
// 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([
|
||||
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'
|
||||
])
|
||||
.pipe(eslint())
|
||||
.pipe(eslint.format())
|
||||
.pipe(eslint.failAfterError());
|
||||
});
|
||||
|
||||
gulp.task('lint:common', () => {
|
||||
return gulp
|
||||
.src([
|
||||
];
|
||||
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',
|
||||
])
|
||||
.pipe(eslint())
|
||||
.pipe(eslint.format())
|
||||
.pipe(eslint.failAfterError());
|
||||
});
|
||||
|
||||
gulp.task('lint:tests', () => {
|
||||
return gulp
|
||||
.src([
|
||||
];
|
||||
const TEST_FILES = [
|
||||
'./test/**/*.js',
|
||||
// @TODO remove these negations as the test files are cleaned up.
|
||||
'!./test/api-legacy/**/*',
|
||||
@@ -46,8 +25,31 @@ gulp.task('lint:tests', () => {
|
||||
'!./test/e2e/**/*',
|
||||
'!./test/server_side/**/*',
|
||||
'!./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: {
|
||||
'max-nested-callbacks': 0,
|
||||
'no-unused-expressions': 0,
|
||||
@@ -61,17 +63,17 @@ gulp.task('lint:tests', () => {
|
||||
'sinon': true,
|
||||
},
|
||||
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:watch', () => {
|
||||
gulp.watch([
|
||||
'./website/src/**/*.js',
|
||||
'./common/script/**/*.js',
|
||||
'./test/**/*.js',
|
||||
SERVER_FILES,
|
||||
COMMON_FILES,
|
||||
TEST_FILES,
|
||||
], ['lint']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user