diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..b2f8382 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,16 @@ +{ + "parser": "babel-eslint", + "rules": { + "strict": 0, + "quotes": [2, "single"] + }, + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "env": { + "browser": true, + "node": true, + "es6": true + } +} diff --git a/gulpfile.js b/gulpfile.js index 6d5b728..d456290 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,11 +2,26 @@ var gulp = require('gulp'); var babelify = require('babelify'); var uglify = require('gulp-uglify'); +var eslint = require('gulp-eslint'); var rename = require('gulp-rename'); var browserify = require('browserify'); var source = require('vinyl-source-stream'); -gulp.task('compile', function() { +// Lint using eslint +gulp.task('lint', function() { + return gulp.src([ + '**/*.js', + '!dist/**', + '!coverage/**', + '!node_modules/**' + ]) + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failAfterError()); +}); + +// Compile ES6 +gulp.task('compile', ['lint'], function() { return browserify({ entries: './src/H.js', debug: true }) .transform(babelify) .bundle() @@ -14,14 +29,15 @@ gulp.task('compile', function() { .pipe(gulp.dest('dist')); }); +// Uglify gulp.task('uglify', ['compile'], function() { - gulp.src('dist/h.js') + return gulp.src('dist/h.js') .pipe(rename({suffix: '.min'})) .pipe(uglify()) .pipe(gulp.dest('dist')); }); -gulp.task('default', ['compile', 'uglify']); +gulp.task('default', ['lint', 'compile', 'uglify']); gulp.task('watch', function() { gulp.watch('./src/**/*.js', ['default']); diff --git a/package.json b/package.json index 27a20ec..3d2fd3d 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,14 @@ "handlebars": "^4.*" }, "devDependencies": { + "babel-eslint": "^5.0.0", "babel-preset-es2015": "^6.5.0", "babelify": "^7.2.0", "browserify": "^13.0.0", "browserify-istanbul": "^0.2.1", + "eslint": "^2.2.0", "gulp": "^3.9.1", + "gulp-eslint": "^2.0.0", "gulp-rename": "^1.2.2", "gulp-uglify": "^1.5.2", "isparta": "^4.0.0",