Skip to content

Commit

Permalink
Simplify eslint config (move it out of gulpfile)
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Dec 25, 2016
1 parent e671614 commit 702799f
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 99 deletions.
55 changes: 28 additions & 27 deletions generators/eslint/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
'use strict';
var Generator = require('yeoman-generator');
var extend = require('lodash').merge;
var rootPkg = require('../../package.json');

module.exports = Generator.extend({
constructor: function () {
Generator.apply(this, arguments);
module.exports = class extends Generator {
constructor(args, options) {
super(args, options);

this.option('generateInto', {
type: String,
required: false,
defaults: '',
default: '',
desc: 'Relocate the location of the generated files.'
});

this.option('es2015', {
required: false,
defaults: false,
default: false,
desc: 'Allow ES2015 syntax'
});
},

writing: function () {
var pkg = this.fs.readJSON(this.destinationPath(this.options.generateInto, 'package.json'), {});
}

var eslintConfig = {
extends: 'xo-space',
env: {
mocha: true
writing() {
var pkgJson = {
devDependencies: {
eslint: rootPkg.devDependencies.eslint,
'eslint-config-xo-space': rootPkg.devDependencies['eslint-config-xo-space']
},
eslintConfig: {
extends: 'xo-space',
env: {
mocha: true
}
},
scripts: {
pretest: 'eslint **/*.js --fix'
}
};
var devDep = {
eslint: '^3.1.1',
'eslint-config-xo-space': '^0.15.0'
};

if (this.options.es2015) {
devDep['babel-eslint'] = '^6.1.2';
devDep['eslint-plugin-babel'] = '^3.3.0';
pkgJson.devDependencies['babel-eslint'] = rootPkg.devDependencies['babel-eslint'];
pkgJson.devDependencies['eslint-plugin-babel'] = rootPkg.devDependencies['eslint-plugin-babel'];
}

extend(pkg, {
devDependencies: devDep,
eslintConfig: eslintConfig
});

this.fs.writeJSON(this.destinationPath(this.options.generateInto, 'package.json'), pkg);
this.fs.extendJSON(
this.destinationPath(this.options.generateInto, 'package.json'),
pkgJson
);
}
});
};
3 changes: 1 addition & 2 deletions generators/gulp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ module.exports = Generator.extend({
extend(pkg, {
devDependencies: {
gulp: '3.9.1',
'gulp-eslint': '^3.0.1',
'gulp-exclude-gitignore': '^1.0.0',
'gulp-istanbul': '^1.1.1',
'gulp-line-ending-corrector': '^1.0.1',
Expand Down Expand Up @@ -82,7 +81,7 @@ module.exports = Generator.extend({
},

gulpfile: function () {
var tasks = ['static', 'test'];
var tasks = ['test'];
var prepublishTasks = [];

if (this.options.coveralls) {
Expand Down
9 changes: 0 additions & 9 deletions generators/gulp/templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<% } -%>
var path = require('path');
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
Expand All @@ -24,14 +23,6 @@ var isparta = require('isparta');
require('babel-register');
<% } -%>

gulp.task('static', function () {
return gulp.src('**/*.js')
.pipe(excludeGitignore())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('pre-test', function () {
return gulp.src('<%- projectRoot %>')
.pipe(excludeGitignore())
Expand Down
11 changes: 1 addition & 10 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
'use strict';
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var plumber = require('gulp-plumber');

gulp.task('static', function () {
return gulp.src(['**/*.js', '!**/templates/**'])
.pipe(excludeGitignore())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('pre-test', function () {
return gulp.src(['**/*.js', '!**/templates/**'])
.pipe(excludeGitignore())
Expand Down Expand Up @@ -42,4 +33,4 @@ gulp.task('watch', function () {
gulp.watch(['**/*.js', 'test/**'], ['test']);
});

gulp.task('default', ['static', 'test']);
gulp.task('default', ['test']);
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"author": "Yeoman team",
"repository": "yeoman/generator-node",
"scripts": {
"pretest": "eslint **/*.js --fix",
"test": "gulp",
"prepublish": "nsp"
},
Expand All @@ -28,11 +29,12 @@
"yeoman-generator": "^1.0.1"
},
"devDependencies": {
"babel-eslint": "^7.1.1",
"eslint": "^3.8.1",
"eslint-config-xo": "^0.17.0",
"eslint-config-xo-space": "^0.15.0",
"eslint-plugin-babel": "^4.0.0",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-exclude-gitignore": "^1.0.0",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^3.0.1",
Expand Down
68 changes: 32 additions & 36 deletions test/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,43 @@ var assert = require('yeoman-assert');
var helpers = require('yeoman-test');

describe('node:eslint', function () {
before(function () {
return helpers.run(path.join(__dirname, '../generators/eslint'));
});

it('fill package.json', function () {
assert.fileContent('package.json', /"eslint-config-xo-space":/);
assert.jsonFileContent('package.json', {
eslintConfig: {
extends: 'xo-space',
env: {
mocha: true
}
}
});
return helpers.run(path.join(__dirname, '../generators/eslint'))
.then(function () {
assert.fileContent('package.json', /"eslint-config-xo-space":/);
assert.jsonFileContent('package.json', {
eslintConfig: {
extends: 'xo-space',
env: {
mocha: true
}
},
scripts: {
pretest: 'eslint **/*.js --fix'
}
});
});
});

describe('--es2015', function () {
before(function () {
return helpers.run(path.join(__dirname, '../generators/eslint'))
.withOptions({es2015: true});
});

it('fill package.json for ES2015', function () {
assert.fileContent('package.json', /"babel-eslint":/);
assert.fileContent('package.json', /"eslint-plugin-babel":/);
});
it('fill package.json for ES2015', function () {
return helpers.run(path.join(__dirname, '../generators/eslint'))
.withOptions({es2015: true})
.then(function () {
assert.fileContent('package.json', /"babel-eslint":/);
assert.fileContent('package.json', /"eslint-plugin-babel":/);
});
});

describe('--generate-into', function () {
before(function () {
return helpers.run(path.join(__dirname, '../generators/eslint'))
.withOptions({generateInto: 'other/'});
});

it('fill env .eslintrc with generate-into option', function () {
assert.fileContent('other/package.json', /"eslint-config-xo-space":/);
assert.jsonFileContent('other/package.json', {
eslintConfig: {
extends: 'xo-space'
}
it('respect generateInto option as the root of the scaffolding', function () {
return helpers.run(path.join(__dirname, '../generators/eslint'))
.withOptions({generateInto: 'other/'})
.then(function () {
assert.fileContent('other/package.json', /"eslint-config-xo-space":/);
assert.jsonFileContent('other/package.json', {
eslintConfig: {
extends: 'xo-space'
}
});
});
});
});
});
2 changes: 0 additions & 2 deletions test/gulp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('node:gulp', function () {

assert.fileContent('gulpfile.js', 'gulp.task(\'coveralls\'');
assert.fileContent('gulpfile.js', 'gulp.task(\'test\'');
assert.fileContent('gulpfile.js', 'gulp.task(\'static\'');

assert.fileContent('package.json', 'gulp');
assert.fileContent('package.json', 'gulp-coveralls');
Expand Down Expand Up @@ -116,7 +115,6 @@ describe('node:gulp', function () {

assert.fileContent('other/gulpfile.js', 'gulp.task(\'coveralls\'');
assert.fileContent('other/gulpfile.js', 'gulp.task(\'test\'');
assert.fileContent('other/gulpfile.js', 'gulp.task(\'static\'');

assert.fileContent('other/package.json', 'gulp');
assert.fileContent('other/package.json', 'gulp-coveralls');
Expand Down

0 comments on commit 702799f

Please sign in to comment.