Skip to content
Merged

ESlint #1993

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"gulp-plumber": "^1.1.0",
"gulp-util": "^3.0.7",
"jit-grunt": "~0.10.0",
"jscs": "^3.0.3",
"lazypipe": "^1.0.1",
"merge-stream": "^1.0.0",
"minimatch": "^3.0.0",
Expand Down
69 changes: 38 additions & 31 deletions src/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export class Generator extends Base {
constructor(...args) {
super(...args);

this.env.alias('angular-fullstack', 'afs');
this.env.alias('afs', 'angular-fullstack');

this.argument('name', { type: String, required: false });

this.option('skip-install', {
Expand All @@ -30,6 +27,12 @@ export class Generator extends Base {
defaults: false
});

this.option('skip-config', {
desc: 'Always use existing .yo-rc.json',
type: Boolean,
defaults: false
});

this.option('app-suffix', {
desc: 'Allow a custom suffix to be added to the module name',
type: String,
Expand Down Expand Up @@ -79,34 +82,38 @@ export class Generator extends Base {
checkForConfig: function() {
var existingFilters = this.config.get('filters');

if(existingFilters) {
return this.prompt([{
type: 'confirm',
name: 'skipConfig',
message: 'Existing .yo-rc configuration found, would you like to use it?',
default: true,
}]).then(answers => {
this.skipConfig = answers.skipConfig;

if(this.skipConfig) {
insight.track('skipConfig', 'true');
this.filters = existingFilters;

this.scriptExt = this.filters.ts ? 'ts' : 'js';
this.templateExt = this.filters.jade ? 'jade' : 'html';
this.styleExt = this.filters.sass ? 'scss' :
this.filters.less ? 'less' :
this.filters.stylus ? 'styl' :
'css';
} else {
insight.track('skipConfig', 'false');
this.filters = {};
this.forceConfig = true;
this.config.set('filters', this.filters);
this.config.forceSave();
}
});
}
if(!existingFilters) return;

let promise = this.options['skip-config']
? Promise.resolve({skipConfig: true})
: this.prompt([{
type: 'confirm',
name: 'skipConfig',
message: 'Existing .yo-rc configuration found, would you like to use it?',
default: true,
}]);

promise.then(answers => {
this.skipConfig = answers.skipConfig;

if(this.skipConfig) {
insight.track('skipConfig', 'true');
this.filters = existingFilters;

this.scriptExt = this.filters.ts ? 'ts' : 'js';
this.templateExt = this.filters.jade ? 'jade' : 'html';
this.styleExt = this.filters.sass ? 'scss' :
this.filters.less ? 'less' :
this.filters.stylus ? 'styl' :
'css';
} else {
insight.track('skipConfig', 'false');
this.filters = {};
this.forceConfig = true;
this.config.set('filters', this.filters);
this.config.forceSave();
}
});
}
};
}
Expand Down
81 changes: 16 additions & 65 deletions src/test/endpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import Promise from 'bluebird';
import helpers from 'yeoman-test';
import assert from 'yeoman-assert';
import minimatch from 'minimatch';
import Checker from 'jscs';
const jscs = new Checker();
jscs.registerDefaultRules();
import * as getExpectedFiles from './get-expected-files';
import {
copyAsync,
Expand Down Expand Up @@ -71,50 +68,28 @@ function runEndpointGen(name, opt={}) {
});
}

let jshintCmd = path.join(TEST_DIR, '/fixtures/node_modules/.bin/jshint');
let eslintCmd = path.join(TEST_DIR, '/fixtures/node_modules/.bin/eslint');
function testFile(command, _path) {
_path = path.normalize(_path);
return fs.accessAsync(_path, fs.R_OK).then(() => {
return runCmd(`${command} ${_path}`);
});
}

function jshintDir(dir, name, folder) {
function eslintDir(dir, name, folder) {
if(!folder) folder = name;
let endpointDir = path.join(dir, 'server/api', folder);

let regFiles = fs.readdirAsync(endpointDir)
.then(files => files.filter(file => minimatch(file, '**/!(*.spec|*.mock|*.integration).js', {dot: true})))
.map(file => testFile(jshintCmd, path.join('./server/api/', folder, file)));
.map(file => testFile(eslintCmd, path.join('./server/api/', folder, file)));

let specFiles = fs.readdirAsync(endpointDir)
.then(files => files.filter(file => minimatch(file, '**/+(*.spec|*.mock|*.integration).js', {dot: true})))
.map(file => testFile(`${jshintCmd} --config server/.jshintrc-spec`, path.join('./server/api/', folder, file)));
.map(file => testFile(`${eslintCmd} --env node,es6,mocha --global sinon,expect`, path.join('./server/api/', folder, file)));

return Promise.all([regFiles, specFiles]);
}
function jscsDir(dir, name, folder) {
if(!folder) folder = name;
let endpointDir = path.join(dir, 'server/api', folder);

return fs.readdirAsync(endpointDir).then(files => {
return Promise.map(files, file => {
return fs.readFileAsync(path.join('server/api', folder, file), 'utf8').then(data => {
let results = jscs.checkString(data)
let errors = results.getErrorList();
if(errors.length === 0) {
return Promise.resolve();
} else {
errors.forEach(error => {
var colorizeOutput = true;
console.log(results.explainError(error, colorizeOutput) + '\n');
});
return Promise.reject();
}
});
});
});
}

var config;
var genDir;
Expand All @@ -124,10 +99,6 @@ describe('angular-fullstack:endpoint', function() {
return Promise.all([
runGen(defaultOptions).then(_dir => {
genDir = _dir;

return fs.readFileAsync(path.join(genDir, '.jscsrc'), 'utf8').then(data => {
jscs.configure(JSON.parse(data));
});
}),
readJSON(path.join(TEST_DIR, 'fixtures/.yo-rc.json')).then(_config => {
_config['generator-angular-fullstack'].insertRoutes = false;
Expand All @@ -146,9 +117,8 @@ describe('angular-fullstack:endpoint', function() {
dir = _dir;

return Promise.all([
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec'),
copyAsync(path.join(genDir, '/.jscsrc'), './.jscsrc')
copyAsync(path.join(genDir, '/.eslintrc'), './.eslintrc'),
copyAsync(path.join(genDir, '/server/.eslintrc'), './server/.eslintrc')
]);
});
});
Expand All @@ -157,12 +127,8 @@ describe('angular-fullstack:endpoint', function() {
assert.file(getExpectedFiles.endpoint('foo'));
});

it('should pass jscs', function() {
return jscsDir(dir, 'foo').should.be.fulfilled();
});

it('should pass lint', function() {
return jshintDir(dir, 'foo').should.be.fulfilled();
return eslintDir(dir, 'foo').should.be.fulfilled();
});
});

Expand All @@ -173,9 +139,8 @@ describe('angular-fullstack:endpoint', function() {
dir = _dir;

return Promise.all([
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec'),
copyAsync(path.join(genDir, '/.jscsrc'), './.jscsrc')
copyAsync(path.join(genDir, '/.eslintrc'), './.eslintrc'),
copyAsync(path.join(genDir, '/server/.eslintrc'), './server/.eslintrc')
]);
});
});
Expand All @@ -184,12 +149,8 @@ describe('angular-fullstack:endpoint', function() {
assert.file(getExpectedFiles.endpoint('Foo'));
});

it('should pass jscs', function() {
return jscsDir(dir, 'Foo').should.be.fulfilled();
});

it('should pass lint', function() {
return jshintDir(dir, 'Foo').should.be.fulfilled();
return eslintDir(dir, 'Foo').should.be.fulfilled();
});
});

Expand All @@ -200,9 +161,8 @@ describe('angular-fullstack:endpoint', function() {
dir = _dir;

return Promise.all([
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec'),
copyAsync(path.join(genDir, '/.jscsrc'), './.jscsrc')
copyAsync(path.join(genDir, '/.eslintrc'), './.eslintrc'),
copyAsync(path.join(genDir, '/server/.eslintrc'), './server/.eslintrc')
]);
});
});
Expand All @@ -211,12 +171,8 @@ describe('angular-fullstack:endpoint', function() {
assert.file(getExpectedFiles.endpoint('bar', 'foo/bar'));
});

it('should pass jscs', function() {
return jscsDir(dir, 'foo', 'foo/bar').should.be.fulfilled();
});

it('should pass lint', function() {
return jshintDir(dir, 'foo', 'foo/bar').should.be.fulfilled();
return eslintDir(dir, 'foo', 'foo/bar').should.be.fulfilled();
});
});

Expand All @@ -227,9 +183,8 @@ describe('angular-fullstack:endpoint', function() {
dir = _dir;

return Promise.all([
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec'),
copyAsync(path.join(genDir, '/.jscsrc'), './.jscsrc')
copyAsync(path.join(genDir, '/.eslintrc'), './.eslintrc'),
copyAsync(path.join(genDir, '/server/.eslintrc'), './server/.eslintrc')
]);
});
});
Expand All @@ -238,12 +193,8 @@ describe('angular-fullstack:endpoint', function() {
assert.file(getExpectedFiles.endpoint('foo-bar'));
});

it('should pass jscs', function() {
return jscsDir(dir, 'foo-bar').should.be.fulfilled();
});

it('should pass lint', function() {
return jshintDir(dir, 'foo-bar').should.be.fulfilled();
return eslintDir(dir, 'foo-bar').should.be.fulfilled();
});
});
});
7 changes: 3 additions & 4 deletions src/test/get-expected-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ export function app(options) {
'client/components/navbar/navbar.component.' + script,
'client/components/util/util.module.' + script,
'client/components/util/util.service.' + script,
'server/.jshintrc',
'server/.jshintrc-spec',
'server/.eslintrc',
'server/app.js',
'server/index.js',
'server/routes.js',
Expand All @@ -92,10 +91,10 @@ export function app(options) {
'.babelrc',
'.buildignore',
'.editorconfig',
'.eslintrc',
'.gitattributes',
'.gitignore',
'.travis.yml',
'.jscsrc',
'.yo-rc.json',
'gulpfile.babel.js',
'package.json',
Expand All @@ -121,7 +120,7 @@ export function app(options) {
]);
} else {
files = files.concat([
'client/.jshintrc'
'client/.eslintrc'
]);
}

Expand Down
Loading