Skip to content

Commit d17bc71

Browse files
filipesilvahansl
authored andcommitted
chore(lint): lint ts as well as js (angular#1823)
1 parent b5e86c9 commit d17bc71

40 files changed

+376
-251
lines changed

addon/ng2/commands/build.ts

+11-6
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,18 +31,18 @@ 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

38-
var project = this.project;
39-
var ui = this.ui;
40-
var buildTask = commandOptions.watch ?
43+
const project = this.project;
44+
const ui = this.ui;
45+
const buildTask = commandOptions.watch ?
4146
new WebpackBuildWatch({
4247
cliProject: project,
4348
ui: ui,

addon/ng2/commands/doc.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const DocCommand = Command.extend({
1010
'<keyword>'
1111
],
1212

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

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

addon/ng2/commands/e2e.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = Command.extend({
99
run: function () {
1010
this.project.ngConfig = this.project.ngConfig || CliConfig.fromProject();
1111

12-
var e2eTask = new E2ETask({
12+
const e2eTask = new E2ETask({
1313
ui: this.ui,
1414
analytics: this.analytics,
1515
project: this.project

addon/ng2/commands/generate.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import * as EmberGenerateCommand from 'ember-cli/lib/commands/generate';
22
import * as fs from 'fs';
33
import * as path from 'path';
44
import * as SilentError from 'silent-error';
5-
var chalk = require('chalk');
65
import * as Blueprint from 'ember-cli/lib/models/blueprint';
7-
var EOL = require('os').EOL;
6+
const chalk = require('chalk');
7+
const EOL = require('os').EOL;
88

99
const GenerateCommand = EmberGenerateCommand.extend({
1010
name: 'generate',
@@ -21,24 +21,24 @@ 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) {
27-
var blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
28-
var blueprints = blueprintList
27+
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
28+
const 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-
33-
var output = '';
32+
33+
let output = '';
3434
blueprints
3535
.forEach(function (bp) {
3636
output += bp.printBasicHelp(false) + EOL;
3737
});
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

+23-17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from 'path';
99
import * as WebpackBuild from '../tasks/build-webpack';
1010
import * as CreateGithubRepo from '../tasks/create-github-repo';
1111
import { CliConfig } from '../models/config';
12+
import { oneLine } from 'common-tags';
1213

1314
const fsReadFile = Promise.denodeify(fs.readFile);
1415
const fsWriteFile = Promise.denodeify(fs.writeFile);
@@ -18,7 +19,10 @@ const fsCopy = Promise.denodeify(fse.copy);
1819
module.exports = Command.extend({
1920
name: 'github-pages:deploy',
2021
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',
22+
description: oneLine`
23+
Build the test app for production, commit it into a git branch,
24+
setup GitHub repo and push to it
25+
`,
2226
works: 'insideProject',
2327

2428
availableOptions: [
@@ -60,13 +64,13 @@ module.exports = Command.extend({
6064
}],
6165

6266
run: function(options, rawArgs) {
63-
var ui = this.ui;
64-
var root = this.project.root;
65-
var execOptions = {
67+
const ui = this.ui;
68+
const root = this.project.root;
69+
const execOptions = {
6670
cwd: root
6771
};
6872

69-
if (options.environment === ''){
73+
if (options.environment === '') {
7074
if (options.target === 'development') {
7175
options.environment = 'dev';
7276
}
@@ -75,7 +79,7 @@ module.exports = Command.extend({
7579
}
7680
}
7781

78-
var projectName = this.project.pkg.name;
82+
const projectName = this.project.pkg.name;
7983

8084
const outDir = CliConfig.fromProject().config.apps[0].outDir;
8185

@@ -86,7 +90,7 @@ module.exports = Command.extend({
8690
// declared here so that tests can stub exec
8791
const execPromise = Promise.denodeify(exec);
8892

89-
var buildTask = new WebpackBuild({
93+
const buildTask = new WebpackBuild({
9094
ui: this.ui,
9195
analytics: this.analytics,
9296
cliProject: this.project,
@@ -95,19 +99,19 @@ module.exports = Command.extend({
9599
outputPath: outDir
96100
});
97101

98-
var buildOptions = {
102+
const buildOptions = {
99103
target: options.target,
100104
environment: options.environment,
101105
outputPath: outDir
102106
};
103107

104-
var createGithubRepoTask = new CreateGithubRepo({
108+
const createGithubRepoTask = new CreateGithubRepo({
105109
ui: this.ui,
106110
analytics: this.analytics,
107111
project: this.project
108112
});
109113

110-
var createGithubRepoOptions = {
114+
const createGithubRepoOptions = {
111115
projectName,
112116
ghUsername: options.ghUsername,
113117
ghToken: options.ghToken
@@ -137,7 +141,7 @@ module.exports = Command.extend({
137141
}
138142

139143
function build() {
140-
if (options.skipBuild) return Promise.resolve();
144+
if (options.skipBuild) { return Promise.resolve(); }
141145
return buildTask.run(buildOptions);
142146
}
143147

@@ -165,7 +169,7 @@ module.exports = Command.extend({
165169

166170
function checkoutGhPages() {
167171
return execPromise(`git checkout ${ghPagesBranch}`)
168-
.catch(createGhPagesBranch)
172+
.catch(createGhPagesBranch);
169173
}
170174

171175
function createGhPagesBranch() {
@@ -179,16 +183,16 @@ module.exports = Command.extend({
179183
function copyFiles() {
180184
return fsReadDir(outDir)
181185
.then((files) => Promise.all(files.map((file) => {
182-
if (file === '.gitignore'){
186+
if (file === '.gitignore') {
183187
// don't overwrite the .gitignore file
184188
return Promise.resolve();
185189
}
186-
return fsCopy(path.join(outDir, file), path.join('.', file))
190+
return fsCopy(path.join(outDir, file), path.join('.', file));
187191
})));
188192
}
189193

190194
function updateBaseHref() {
191-
if (options.userPage) return Promise.resolve();
195+
if (options.userPage) { return Promise.resolve(); }
192196
let indexHtml = path.join(root, 'index.html');
193197
return fsReadFile(indexHtml, 'utf8')
194198
.then((data) => data.replace(/<base href="\/">/g, `<base href="/${projectName}/">`))
@@ -215,7 +219,8 @@ module.exports = Command.extend({
215219
function printProjectUrl() {
216220
return execPromise('git remote -v')
217221
.then((stdout) => {
218-
let userName = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m)[1].toLowerCase();
222+
let match = stdout.match(/origin\s+(?:https:\/\/|git@)github\.com(?:\:|\/)([^\/]+)/m);
223+
let userName = match[1].toLowerCase();
219224
let url = `https://${userName}.github.io/${options.userPage ? '' : (projectName + '/')}`;
220225
ui.writeLine(chalk.green(`Deployed! Visit ${url}`));
221226
ui.writeLine('Github pages might take a few minutes to show the deployed site.');
@@ -225,7 +230,8 @@ module.exports = Command.extend({
225230
function failGracefully(error) {
226231
if (error && (/git clean/.test(error.message) || /Permission denied/.test(error.message))) {
227232
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.';
233+
let msg = 'There was a permissions error during git file operations, ' +
234+
'please close any open project files/folders and try again.';
229235
msg += `\nYou might also need to return to the ${initialBranch} branch manually.`;
230236
return Promise.reject(new SilentError(msg));
231237
} else {

addon/ng2/commands/lint.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = Command.extend({
66
description: 'Lints code in existing project',
77
works: 'insideProject',
88
run: function () {
9-
var lintTask = new LintTask({
9+
const lintTask = new LintTask({
1010
ui: this.ui,
1111
analytics: this.analytics,
1212
project: this.project

addon/ng2/commands/serve.ts

+42-20
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,20 +95,12 @@ 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-
81-
var serve = new ServeWebpackTask({
103+
const serve = new ServeWebpackTask({
82104
ui: this.ui,
83105
analytics: this.analytics,
84106
project: this.project,
@@ -93,7 +115,7 @@ module.exports = Command.extend({
93115
.then((foundPort: number) => {
94116

95117
if (commandOptions.port !== foundPort && commandOptions.port !== 0) {
96-
var message = 'Port ' + commandOptions.port + ' is already in use.';
118+
const message = 'Port ' + commandOptions.port + ' is already in use.';
97119
return Promise.reject(new SilentError(message));
98120
}
99121

addon/ng2/commands/test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = TestCommand.extend({
1616
run: function (commandOptions) {
1717
this.project.ngConfig = this.project.ngConfig || CliConfig.fromProject();
1818

19-
var testTask = new TestTask({
19+
const testTask = new TestTask({
2020
ui: this.ui,
2121
analytics: this.analytics,
2222
project: this.project

0 commit comments

Comments
 (0)