Skip to content

Commit 9b1a132

Browse files
committed
integreted ESlint into gulp
1 parent 770f122 commit 9b1a132

File tree

4 files changed

+866
-10
lines changed

4 files changed

+866
-10
lines changed

components/controllers/list.controller.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'NodeJS',
1212
'AngularJS',
1313
'GulpJS',
14+
'ESlint',
1415
'jQuery',
1516
'lodash',
1617
'Bootstrap',

gulpfile.js

+45-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,36 @@
1111
*
1212
*/
1313
var gulp = require('gulp');
14+
var eslint = require('gulp-eslint');
1415
var browserSync = require('browser-sync');
1516
var reload = browserSync.reload;
1617
var $ = require('gulp-load-plugins')();
1718
var del = require('del');
1819
var runSequence = require('run-sequence');
1920

21+
var jsConfig = {
22+
extends: 'eslint:recommended',
23+
rules: {
24+
'quotes': [1, 'single'],
25+
'curly': [1, 'multi-line'],
26+
'no-extra-parens': 1,
27+
'key-spacing': [1, {
28+
'beforeColon': false,
29+
'afterColon': true,
30+
'mode': 'strict'
31+
}],
32+
'no-multi-spaces': 1,
33+
'dot-location': [1, 'property'],
34+
'max-len': [1, { 'code': 80, 'tabWidth': 2 }],
35+
'no-trailing-spaces': 1,
36+
'indent': [1, 'tab'],
37+
'no-empty-function': 2,
38+
'eol-last': [2, 'always'],
39+
'semi': [2, 'always'],
40+
'no-multiple-empty-lines': 2
41+
}
42+
};
43+
2044

2145
// optimize images
2246
gulp.task('images', function() {
@@ -238,6 +262,22 @@ gulp.task('css:size', function() {
238262
}));
239263
});
240264

265+
// lint javascript
266+
gulp.task('js:lint', function() {
267+
// eslint-disable-next-line
268+
return gulp.src(['app/**/*.js', 'components/**/*.js', 'js/**/*.js', '!js/nonangular/*'])
269+
.pipe(eslint(jsConfig))
270+
.pipe(eslint.format());
271+
});
272+
// build lint javascript
273+
gulp.task('js:lint-build', function() {
274+
// eslint-disable-next-line
275+
return gulp.src(['app/**/*.js', 'components/**/*.js', 'js/**/*.js', '!js/nonangular/*'])
276+
.pipe(eslint(jsConfig))
277+
.pipe(eslint.format())
278+
.pipe(eslint.failAfterError());
279+
});
280+
241281

242282
/////////////////////////////////////////////
243283
///////// GULP COMMANDS /////////
@@ -256,15 +296,15 @@ gulp.task('server', function(done) {
256296
// default task to be run with `gulp` command
257297
// this default task will run BrowserSync & then use Gulp to watch files.
258298
// when a file is changed, an event is emitted to BrowserSync with the filepath.
259-
gulp.task('default', ['browser-sync', 'html:size', 'src:js:size', 'minify-css'], function() {
299+
gulp.task('default', ['browser-sync', 'html:size', 'src:js:size', 'minify-css', 'js:lint'], function() {
260300
gulp.watch('styles/*.css', function(file) {
261301
if (file.type === "changed") {
262302
reload(file.path);
263303
}
264304
});
265305
gulp.watch(['*.html', 'components/**/*.html', 'views/**/*.html'], ['bs-reload', 'html:size']);
266-
gulp.watch(['app/**/*.js', 'components/**/*.js', 'js/**/*.js'], ['bs-reload', 'src:js:size']);
267-
gulp.watch(['./styles/**/*.css'], ['minify-css']);
306+
gulp.watch(['app/**/*.js', 'components/**/*.js', 'js/**/*.js'], ['bs-reload', 'src:js:size', 'js:lint']);
307+
gulp.watch(['./styles/**/*.css'], ['bs-reload', 'minify-css']);
268308
});
269309

270310
/**
@@ -281,6 +321,7 @@ gulp.task('default', ['browser-sync', 'html:size', 'src:js:size', 'minify-css'],
281321
*/
282322
gulp.task('build', function(callback) {
283323
runSequence(
324+
'js:lint-build',
284325
'clean:build',
285326
'images',
286327
'templates',
@@ -296,6 +337,7 @@ gulp.task('build', function(callback) {
296337
// start webserver from _build folder to check how it will look in production
297338
gulp.task('server-build', function(callback) {
298339
runSequence(
340+
'js:lint-build',
299341
'clean:build',
300342
'images',
301343
'templates',

0 commit comments

Comments
 (0)