Skip to content

Commit 145d320

Browse files
committed
chore(lint): lint ts as well as js
1 parent 0d914b2 commit 145d320

15 files changed

+163
-100
lines changed

addon/ng2/commands/build.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ module.exports = Command.extend({
1717
aliases: ['b'],
1818

1919
availableOptions: [
20-
{ name: 'target', type: String, default: 'development', aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] },
20+
{
21+
name: 'target',
22+
type: String,
23+
default: 'development',
24+
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
25+
},
2126
{ name: 'environment', type: String, default: '', aliases: ['e'] },
2227
{ name: 'output-path', type: 'Path', default: 'dist/', aliases: ['o'] },
2328
{ name: 'watch', type: Boolean, default: false, aliases: ['w'] },
@@ -26,13 +31,13 @@ module.exports = Command.extend({
2631
],
2732

2833
run: function (commandOptions: BuildOptions) {
29-
if (commandOptions.environment === ''){
34+
if (commandOptions.environment === '') {
3035
if (commandOptions.target === 'development') {
3136
commandOptions.environment = 'dev';
3237
}
3338
if (commandOptions.target === 'production') {
3439
commandOptions.environment = 'prod';
35-
}
40+
}
3641
}
3742

3843
var project = this.project;

addon/ng2/commands/doc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const DocCommand = Command.extend({
1010
'<keyword>'
1111
],
1212

13-
run: function(commandOptions, rawArgs:Array<string>) {
13+
run: function(commandOptions, rawArgs: Array<string>) {
1414
var keyword = rawArgs[0];
15-
15+
1616
var docTask = new DocTask({
1717
ui: this.ui,
1818
analytics: this.analytics,
@@ -23,4 +23,4 @@ const DocCommand = Command.extend({
2323
}
2424
});
2525

26-
module.exports = DocCommand;
26+
module.exports = DocCommand;

addon/ng2/commands/generate.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const GenerateCommand = EmberGenerateCommand.extend({
2121
!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
2222
SilentError.debugOrThrow('angular-cli/commands/generate', `Invalid blueprint: ${rawArgs[0]}`);
2323
}
24-
24+
2525
// Override default help to hide ember blueprints
2626
EmberGenerateCommand.prototype.printDetailedHelp = function (options) {
2727
var blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
2828
var blueprints = blueprintList
2929
.filter(bp => bp.indexOf('-test') === -1)
3030
.filter(bp => bp !== 'ng2')
3131
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));
32-
32+
3333
var output = '';
3434
blueprints
3535
.forEach(function (bp) {
@@ -38,7 +38,7 @@ const GenerateCommand = EmberGenerateCommand.extend({
3838
this.ui.writeLine(chalk.cyan(' Available blueprints'));
3939
this.ui.writeLine(output);
4040
};
41-
41+
4242
return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);
4343
}
4444
});

addon/ng2/commands/github-pages-deploy.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const fsCopy = Promise.denodeify(fse.copy);
1818
module.exports = Command.extend({
1919
name: 'github-pages:deploy',
2020
aliases: ['gh-pages:deploy'],
21-
description: 'Build the test app for production, commit it into a git branch, setup GitHub repo and push to it',
21+
description: 'Build the test app for production, commit it into a git branch, ' +
22+
'setup GitHub repo and push to it',
2223
works: 'insideProject',
2324

2425
availableOptions: [
@@ -27,12 +28,12 @@ module.exports = Command.extend({
2728
type: String,
2829
default: 'new gh-pages version',
2930
description: 'The commit message to include with the build, must be wrapped in quotes.'
30-
}, {
31+
}, {
3132
name: 'target',
3233
type: String,
33-
default: 'production',
34+
default: 'production',
3435
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
35-
}, {
36+
}, {
3637
name: 'environment',
3738
type: String,
3839
default: '',
@@ -66,13 +67,13 @@ module.exports = Command.extend({
6667
cwd: root
6768
};
6869

69-
if (options.environment === ''){
70+
if (options.environment === '') {
7071
if (options.target === 'development') {
7172
options.environment = 'dev';
7273
}
7374
if (options.target === 'production') {
7475
options.environment = 'prod';
75-
}
76+
}
7677
}
7778

7879
var projectName = this.project.pkg.name;
@@ -137,7 +138,7 @@ module.exports = Command.extend({
137138
}
138139

139140
function build() {
140-
if (options.skipBuild) return Promise.resolve();
141+
if (options.skipBuild) { return Promise.resolve(); }
141142
return buildTask.run(buildOptions);
142143
}
143144

@@ -165,7 +166,7 @@ module.exports = Command.extend({
165166

166167
function checkoutGhPages() {
167168
return execPromise(`git checkout ${ghPagesBranch}`)
168-
.catch(createGhPagesBranch)
169+
.catch(createGhPagesBranch);
169170
}
170171

171172
function createGhPagesBranch() {
@@ -179,16 +180,16 @@ module.exports = Command.extend({
179180
function copyFiles() {
180181
return fsReadDir(outDir)
181182
.then((files) => Promise.all(files.map((file) => {
182-
if (file === '.gitignore'){
183+
if (file === '.gitignore') {
183184
// don't overwrite the .gitignore file
184185
return Promise.resolve();
185186
}
186-
return fsCopy(path.join(outDir, file), path.join('.', file))
187+
return fsCopy(path.join(outDir, file), path.join('.', file));
187188
})));
188189
}
189190

190191
function updateBaseHref() {
191-
if (options.userPage) return Promise.resolve();
192+
if (options.userPage) { return Promise.resolve(); }
192193
let indexHtml = path.join(root, 'index.html');
193194
return fsReadFile(indexHtml, 'utf8')
194195
.then((data) => data.replace(/<base href="\/">/g, `<base href="/${projectName}/">`))
@@ -215,7 +216,8 @@ module.exports = Command.extend({
215216
function printProjectUrl() {
216217
return execPromise('git remote -v')
217218
.then((stdout) => {
218-
let userName = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m)[1].toLowerCase();
219+
let match = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m);
220+
let userName = match[1].toLowerCase();
219221
let url = `https://${userName}.github.io/${options.userPage ? '' : (projectName + '/')}`;
220222
ui.writeLine(chalk.green(`Deployed! Visit ${url}`));
221223
ui.writeLine('Github pages might take a few minutes to show the deployed site.');
@@ -225,7 +227,8 @@ module.exports = Command.extend({
225227
function failGracefully(error) {
226228
if (error && (/git clean/.test(error.message) || /Permission denied/.test(error.message))) {
227229
ui.writeLine(error.message);
228-
let msg = 'There was a permissions error during git file operations, please close any open project files/folders and try again.';
230+
let msg = 'There was a permissions error during git file operations, ' +
231+
'please close any open project files/folders and try again.';
229232
msg += `\nYou might also need to return to the ${initialBranch} branch manually.`;
230233
return Promise.reject(new SilentError(msg));
231234
} else {

addon/ng2/commands/serve.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as Command from 'ember-cli/lib/models/command';
33
import * as Promise from 'ember-cli/lib/ext/promise';
44
import * as SilentError from 'silent-error';
55
import * as PortFinder from 'portfinder';
6-
import * as EOL from 'os';
76
import * as ServeWebpackTask from '../tasks/serve-webpack.ts';
87

98
PortFinder.basePort = 49152;
@@ -36,23 +35,54 @@ module.exports = Command.extend({
3635

3736
availableOptions: [
3837
{ name: 'port', type: Number, default: defaultPort, aliases: ['p'] },
39-
{ name: 'host', type: String, default: 'localhost', aliases: ['H'], description: 'Listens on all interfaces by default' },
38+
{
39+
name: 'host',
40+
type: String,
41+
default: 'localhost',
42+
aliases: ['H'],
43+
description: 'Listens on all interfaces by default'
44+
},
4045
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
4146
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
4247
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
43-
{ name: 'live-reload-host', type: String, aliases: ['lrh'], description: 'Defaults to host' },
44-
{ name: 'live-reload-base-url', type: String, aliases: ['lrbu'], description: 'Defaults to baseURL' },
45-
{ name: 'live-reload-port', type: Number, aliases: ['lrp'], description: '(Defaults to port number within [49152...65535])' },
46-
{ name: 'live-reload-live-css', type: Boolean, default: true, description: 'Whether to live reload CSS (default true)' },
47-
{ name: 'target', type: String, default: 'development', aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }] },
48+
{
49+
name: 'live-reload-host',
50+
type: String,
51+
aliases: ['lrh'],
52+
description: 'Defaults to host'
53+
},
54+
{
55+
name: 'live-reload-base-url',
56+
type: String,
57+
aliases: ['lrbu'],
58+
description: 'Defaults to baseURL'
59+
},
60+
{
61+
name: 'live-reload-port',
62+
type: Number,
63+
aliases: ['lrp'],
64+
description: '(Defaults to port number within [49152...65535])'
65+
},
66+
{
67+
name: 'live-reload-live-css',
68+
type: Boolean,
69+
default: true,
70+
description: 'Whether to live reload CSS (default true)'
71+
},
72+
{
73+
name: 'target',
74+
type: String,
75+
default: 'development',
76+
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
77+
},
4878
{ name: 'environment', type: String, default: '', aliases: ['e'] },
4979
{ name: 'ssl', type: Boolean, default: false },
5080
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
5181
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' }
5282
],
5383

5484
run: function(commandOptions: ServeTaskOptions) {
55-
if (commandOptions.environment === ''){
85+
if (commandOptions.environment === '') {
5686
if (commandOptions.target === 'development') {
5787
commandOptions.environment = 'dev';
5888
}
@@ -65,19 +95,11 @@ module.exports = Command.extend({
6595

6696
return this._checkExpressPort(commandOptions)
6797
.then(this._autoFindLiveReloadPort.bind(this))
68-
.then((commandOptions: ServeTaskOptions) => {
69-
commandOptions = assign({}, commandOptions, {
98+
.then((opts: ServeTaskOptions) => {
99+
commandOptions = assign({}, opts, {
70100
baseURL: this.project.config(commandOptions.target).baseURL || '/'
71101
});
72102

73-
if (commandOptions.proxy) {
74-
if (!commandOptions.proxy.match(/^(http:|https:)/)) {
75-
var message = 'You need to include a protocol with the proxy URL.' + EOL + 'Try --proxy http://' + commandOptions.proxy;
76-
77-
return Promise.reject(new SilentError(message));
78-
}
79-
}
80-
81103
var serve = new ServeWebpackTask({
82104
ui: this.ui,
83105
analytics: this.analytics,

addon/ng2/models/config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class CliConfig {
4747
fs.writeFileSync(path, JSON.stringify(this._config, null, 2), { encoding: 'utf-8' });
4848
}
4949

50-
set(jsonPath: string, value: any, force: boolean = false): boolean {
50+
set(jsonPath: string, value: any, force = false): boolean {
5151
let method: any = null;
5252
let splittedPath = jsonPath.split('.');
5353
if (ARRAY_METHODS.indexOf(splittedPath[splittedPath.length - 1]) != -1) {
@@ -114,7 +114,9 @@ export class CliConfig {
114114
}
115115
}
116116

117-
private _findParent(jsonPath: string): { parent: any, name: string | number, remaining?: string } {
117+
private _findParent(jsonPath: string): {
118+
parent: any, name: string | number, remaining?: string
119+
} {
118120
this._validatePath(jsonPath);
119121

120122
let parent: any = null;
@@ -177,14 +179,14 @@ export class CliConfig {
177179
if (config.defaults.sourceDir || config.defaults.prefix) {
178180
config.apps[0].root = config.apps[0].root || config.defaults.sourceDir;
179181
config.apps[0].prefix = config.apps[0].prefix || config.defaults.prefix;
180-
182+
181183
console.error(chalk.yellow(
182184
'The "defaults.prefix" and "defaults.sourceDir" properties of angular-cli.json '
183185
+ 'are deprecated in favor of "apps[0].root" and "apps[0].prefix".\n'
184186
+ 'Please update in order to avoid errors in future versions of angular-cli.'
185187
));
186188
}
187-
189+
188190
return config;
189191
}
190192
}

addon/ng2/models/find-lazy-modules.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import * as glob from 'glob';
33
import * as path from 'path';
44
import * as ts from 'typescript';
55

6-
import {Observable} from 'rxjs/Observable';
76
import {getSource, findNodes, getContentOfKeyLiteral} from '../utilities/ast-utils';
87

98

10-
const loadChildrenRegex = /(\{[^{}]+?(loadChildren|['"]loadChildren['"])\s*:\s*)('[^']+'|"[^"]+")/gm;
11-
12-
139
interface Array<T> {
1410
flatMap: <R>(mapFn: (item: T) => Array<R>) => Array<R>;
1511
}
@@ -37,14 +33,15 @@ export function findLoadChildren(tsFilePath: string): string[] {
3733
// key is an expression, can't do anything.
3834
return false;
3935
}
40-
return key == 'loadChildren'
36+
return key == 'loadChildren';
4137
})
4238
// Remove initializers that are not files.
4339
.filter((node: ts.PropertyAssignment) => {
4440
return node.initializer.kind === ts.SyntaxKind.StringLiteral;
4541
})
46-
// Get the full text of the initiliazer.
42+
// Get the full text of the initializer.
4743
.map((node: ts.PropertyAssignment) => {
44+
/* tslint:disable:no-eval */
4845
return eval(node.initializer.getText(source));
4946
})
5047
.flatMap((value: string) => unique[value] ? undefined : unique[value] = value)

0 commit comments

Comments
 (0)