Skip to content

Commit dd485cb

Browse files
authored
Merge pull request #1993 from angular-fullstack/eslint
ESlint
2 parents 1958a2a + b7f022a commit dd485cb

31 files changed

+589
-513
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
"gulp-plumber": "^1.1.0",
7575
"gulp-util": "^3.0.7",
7676
"jit-grunt": "~0.10.0",
77-
"jscs": "^3.0.3",
7877
"lazypipe": "^1.0.1",
7978
"merge-stream": "^1.0.0",
8079
"minimatch": "^3.0.0",

src/generators/app/index.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export class Generator extends Base {
1919
constructor(...args) {
2020
super(...args);
2121

22-
this.env.alias('angular-fullstack', 'afs');
23-
this.env.alias('afs', 'angular-fullstack');
24-
2522
this.argument('name', { type: String, required: false });
2623

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

30+
this.option('skip-config', {
31+
desc: 'Always use existing .yo-rc.json',
32+
type: Boolean,
33+
defaults: false
34+
});
35+
3336
this.option('app-suffix', {
3437
desc: 'Allow a custom suffix to be added to the module name',
3538
type: String,
@@ -79,34 +82,38 @@ export class Generator extends Base {
7982
checkForConfig: function() {
8083
var existingFilters = this.config.get('filters');
8184

82-
if(existingFilters) {
83-
return this.prompt([{
84-
type: 'confirm',
85-
name: 'skipConfig',
86-
message: 'Existing .yo-rc configuration found, would you like to use it?',
87-
default: true,
88-
}]).then(answers => {
89-
this.skipConfig = answers.skipConfig;
90-
91-
if(this.skipConfig) {
92-
insight.track('skipConfig', 'true');
93-
this.filters = existingFilters;
94-
95-
this.scriptExt = this.filters.ts ? 'ts' : 'js';
96-
this.templateExt = this.filters.jade ? 'jade' : 'html';
97-
this.styleExt = this.filters.sass ? 'scss' :
98-
this.filters.less ? 'less' :
99-
this.filters.stylus ? 'styl' :
100-
'css';
101-
} else {
102-
insight.track('skipConfig', 'false');
103-
this.filters = {};
104-
this.forceConfig = true;
105-
this.config.set('filters', this.filters);
106-
this.config.forceSave();
107-
}
108-
});
109-
}
85+
if(!existingFilters) return;
86+
87+
let promise = this.options['skip-config']
88+
? Promise.resolve({skipConfig: true})
89+
: this.prompt([{
90+
type: 'confirm',
91+
name: 'skipConfig',
92+
message: 'Existing .yo-rc configuration found, would you like to use it?',
93+
default: true,
94+
}]);
95+
96+
promise.then(answers => {
97+
this.skipConfig = answers.skipConfig;
98+
99+
if(this.skipConfig) {
100+
insight.track('skipConfig', 'true');
101+
this.filters = existingFilters;
102+
103+
this.scriptExt = this.filters.ts ? 'ts' : 'js';
104+
this.templateExt = this.filters.jade ? 'jade' : 'html';
105+
this.styleExt = this.filters.sass ? 'scss' :
106+
this.filters.less ? 'less' :
107+
this.filters.stylus ? 'styl' :
108+
'css';
109+
} else {
110+
insight.track('skipConfig', 'false');
111+
this.filters = {};
112+
this.forceConfig = true;
113+
this.config.set('filters', this.filters);
114+
this.config.forceSave();
115+
}
116+
});
110117
}
111118
};
112119
}

src/test/endpoint.test.js

Lines changed: 16 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import Promise from 'bluebird';
66
import helpers from 'yeoman-test';
77
import assert from 'yeoman-assert';
88
import minimatch from 'minimatch';
9-
import Checker from 'jscs';
10-
const jscs = new Checker();
11-
jscs.registerDefaultRules();
129
import * as getExpectedFiles from './get-expected-files';
1310
import {
1411
copyAsync,
@@ -71,50 +68,28 @@ function runEndpointGen(name, opt={}) {
7168
});
7269
}
7370

74-
let jshintCmd = path.join(TEST_DIR, '/fixtures/node_modules/.bin/jshint');
71+
let eslintCmd = path.join(TEST_DIR, '/fixtures/node_modules/.bin/eslint');
7572
function testFile(command, _path) {
7673
_path = path.normalize(_path);
7774
return fs.accessAsync(_path, fs.R_OK).then(() => {
7875
return runCmd(`${command} ${_path}`);
7976
});
8077
}
8178

82-
function jshintDir(dir, name, folder) {
79+
function eslintDir(dir, name, folder) {
8380
if(!folder) folder = name;
8481
let endpointDir = path.join(dir, 'server/api', folder);
8582

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

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

9491
return Promise.all([regFiles, specFiles]);
9592
}
96-
function jscsDir(dir, name, folder) {
97-
if(!folder) folder = name;
98-
let endpointDir = path.join(dir, 'server/api', folder);
99-
100-
return fs.readdirAsync(endpointDir).then(files => {
101-
return Promise.map(files, file => {
102-
return fs.readFileAsync(path.join('server/api', folder, file), 'utf8').then(data => {
103-
let results = jscs.checkString(data)
104-
let errors = results.getErrorList();
105-
if(errors.length === 0) {
106-
return Promise.resolve();
107-
} else {
108-
errors.forEach(error => {
109-
var colorizeOutput = true;
110-
console.log(results.explainError(error, colorizeOutput) + '\n');
111-
});
112-
return Promise.reject();
113-
}
114-
});
115-
});
116-
});
117-
}
11893

11994
var config;
12095
var genDir;
@@ -124,10 +99,6 @@ describe('angular-fullstack:endpoint', function() {
12499
return Promise.all([
125100
runGen(defaultOptions).then(_dir => {
126101
genDir = _dir;
127-
128-
return fs.readFileAsync(path.join(genDir, '.jscsrc'), 'utf8').then(data => {
129-
jscs.configure(JSON.parse(data));
130-
});
131102
}),
132103
readJSON(path.join(TEST_DIR, 'fixtures/.yo-rc.json')).then(_config => {
133104
_config['generator-angular-fullstack'].insertRoutes = false;
@@ -146,9 +117,8 @@ describe('angular-fullstack:endpoint', function() {
146117
dir = _dir;
147118

148119
return Promise.all([
149-
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
150-
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec'),
151-
copyAsync(path.join(genDir, '/.jscsrc'), './.jscsrc')
120+
copyAsync(path.join(genDir, '/.eslintrc'), './.eslintrc'),
121+
copyAsync(path.join(genDir, '/server/.eslintrc'), './server/.eslintrc')
152122
]);
153123
});
154124
});
@@ -157,12 +127,8 @@ describe('angular-fullstack:endpoint', function() {
157127
assert.file(getExpectedFiles.endpoint('foo'));
158128
});
159129

160-
it('should pass jscs', function() {
161-
return jscsDir(dir, 'foo').should.be.fulfilled();
162-
});
163-
164130
it('should pass lint', function() {
165-
return jshintDir(dir, 'foo').should.be.fulfilled();
131+
return eslintDir(dir, 'foo').should.be.fulfilled();
166132
});
167133
});
168134

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

175141
return Promise.all([
176-
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
177-
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec'),
178-
copyAsync(path.join(genDir, '/.jscsrc'), './.jscsrc')
142+
copyAsync(path.join(genDir, '/.eslintrc'), './.eslintrc'),
143+
copyAsync(path.join(genDir, '/server/.eslintrc'), './server/.eslintrc')
179144
]);
180145
});
181146
});
@@ -184,12 +149,8 @@ describe('angular-fullstack:endpoint', function() {
184149
assert.file(getExpectedFiles.endpoint('Foo'));
185150
});
186151

187-
it('should pass jscs', function() {
188-
return jscsDir(dir, 'Foo').should.be.fulfilled();
189-
});
190-
191152
it('should pass lint', function() {
192-
return jshintDir(dir, 'Foo').should.be.fulfilled();
153+
return eslintDir(dir, 'Foo').should.be.fulfilled();
193154
});
194155
});
195156

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

202163
return Promise.all([
203-
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
204-
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec'),
205-
copyAsync(path.join(genDir, '/.jscsrc'), './.jscsrc')
164+
copyAsync(path.join(genDir, '/.eslintrc'), './.eslintrc'),
165+
copyAsync(path.join(genDir, '/server/.eslintrc'), './server/.eslintrc')
206166
]);
207167
});
208168
});
@@ -211,12 +171,8 @@ describe('angular-fullstack:endpoint', function() {
211171
assert.file(getExpectedFiles.endpoint('bar', 'foo/bar'));
212172
});
213173

214-
it('should pass jscs', function() {
215-
return jscsDir(dir, 'foo', 'foo/bar').should.be.fulfilled();
216-
});
217-
218174
it('should pass lint', function() {
219-
return jshintDir(dir, 'foo', 'foo/bar').should.be.fulfilled();
175+
return eslintDir(dir, 'foo', 'foo/bar').should.be.fulfilled();
220176
});
221177
});
222178

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

229185
return Promise.all([
230-
copyAsync(path.join(genDir, '/server/.jshintrc'), './server/.jshintrc'),
231-
copyAsync(path.join(genDir, '/server/.jshintrc-spec'), './server/.jshintrc-spec'),
232-
copyAsync(path.join(genDir, '/.jscsrc'), './.jscsrc')
186+
copyAsync(path.join(genDir, '/.eslintrc'), './.eslintrc'),
187+
copyAsync(path.join(genDir, '/server/.eslintrc'), './server/.eslintrc')
233188
]);
234189
});
235190
});
@@ -238,12 +193,8 @@ describe('angular-fullstack:endpoint', function() {
238193
assert.file(getExpectedFiles.endpoint('foo-bar'));
239194
});
240195

241-
it('should pass jscs', function() {
242-
return jscsDir(dir, 'foo-bar').should.be.fulfilled();
243-
});
244-
245196
it('should pass lint', function() {
246-
return jshintDir(dir, 'foo-bar').should.be.fulfilled();
197+
return eslintDir(dir, 'foo-bar').should.be.fulfilled();
247198
});
248199
});
249200
});

src/test/get-expected-files.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ export function app(options) {
6767
'client/components/navbar/navbar.component.' + script,
6868
'client/components/util/util.module.' + script,
6969
'client/components/util/util.service.' + script,
70-
'server/.jshintrc',
71-
'server/.jshintrc-spec',
70+
'server/.eslintrc',
7271
'server/app.js',
7372
'server/index.js',
7473
'server/routes.js',
@@ -92,10 +91,10 @@ export function app(options) {
9291
'.babelrc',
9392
'.buildignore',
9493
'.editorconfig',
94+
'.eslintrc',
9595
'.gitattributes',
9696
'.gitignore',
9797
'.travis.yml',
98-
'.jscsrc',
9998
'.yo-rc.json',
10099
'gulpfile.babel.js',
101100
'package.json',
@@ -121,7 +120,7 @@ export function app(options) {
121120
]);
122121
} else {
123122
files = files.concat([
124-
'client/.jshintrc'
123+
'client/.eslintrc'
125124
]);
126125
}
127126

0 commit comments

Comments
 (0)