Skip to content

Commit

Permalink
Merge pull request #19 from ahoek/feature-js-linter
Browse files Browse the repository at this point in the history
Feature js linter
  • Loading branch information
Arjen-Smit committed Mar 9, 2016
2 parents bf69c09 + d8aab2f commit 177143e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,24 @@ To use the EcmaScript 2015 (ES6) transpiling, add the following dependencies:
npm install babel-preset-es2015 gulp-babel gulp-plumber --save-dev
```

To enable the javascript linter, add eslint:
```bash
npm install gulp-eslint --save-dev
```

Example configuration:
```json
"javascript": {
"items": [
{
"src": [
"bower_components/babel-polyfill/browser-polyfill.js",
"javascript/app.js"
],
"outputname": "app.js",
"dest": "../../web/assets/javascript/",
"options": {},
"es2015": true
"es2015": true,
"lint": true
}
],
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"gulp-babel": "^6.1.2",
"gulp-concat": "^2.6.0",
"gulp-consolidate": "^0.2.0",
"gulp-eslint": "^2.0.0",
"gulp-iconfont": "^6.0.0",
"gulp-if": "^2.0.0",
"gulp-image-data-uri": "^1.2.1",
Expand Down
28 changes: 28 additions & 0 deletions tasks/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

module.exports = function (gulp, config) {
return function () {
/**
* Add linter with configuration to an item
*
* @param {type} result
* @param {type} item
* @returns {unresolved}
*/
var addLinter = function (result, item) {
var eslint = require('gulp-eslint');
var eslintOptions = {
extends: 'eslint:recommended',
envs: ["browser", "jquery", "prototypejs"],
};

if (item.es2015 === true) {
eslintOptions.envs.push("es6");
}

result
.pipe(eslint(eslintOptions))
.pipe(eslint.format())

return result;
};

var sourcemaps = require('gulp-sourcemaps');
var util = require('gulp-util');
Expand All @@ -18,6 +42,10 @@ module.exports = function (gulp, config) {
var result = gulp.src(item.src)
.pipe(sourcemaps.init());

if (item.lint) {
addLinter(result, item);
}

if (item.es2015 === true) {
// Transpile es2015
result
Expand Down

0 comments on commit 177143e

Please sign in to comment.