Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 59b75af

Browse files
authored
chore(tslint) Add tslint check and do some cleanup. (#12)
1 parent 0403058 commit 59b75af

10 files changed

+59
-40
lines changed

circle.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
dependencies:
2+
override:
3+
- npm update
4+
cache_directories:
5+
- testapp/node_modules
26
post:
37
- npm run webdriver:
48
background: true
5-
- npm run install_testapp
9+
- cd testapp && npm update
610
- npm run testapp:
711
background: true
812
test:
913
override:
10-
- gulp lint
14+
- ./node_modules/.bin/gulp lint
1115
- npm test
1216
- npm run test:e2e

gulpfile.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var gulp = require('gulp');
44
var runSequence = require('run-sequence');
55
var spawn = require('child_process').spawn;
6+
var tslint = require('gulp-tslint');
67

78
var runSpawn = function(done, task, opt_arg) {
89
var child = spawn(task, opt_arg, {stdio: 'inherit'});
@@ -20,10 +21,8 @@ gulp.task('webdriver:update', function(done) {
2021
runSpawn(done, 'webdriver-manager', ['update']);
2122
});
2223

23-
gulp.task('jshint', function(done) {
24-
runSpawn(done, 'node', ['node_modules/jshint/bin/jshint', 'lib', 'spec', 'scripts',
25-
'--exclude=lib/selenium-webdriver/**/*.js,spec/dependencyTest/*.js,' +
26-
'spec/install/**/*.js']);
24+
gulp.task('tslint', function() {
25+
return gulp.src(['lib/**/*.ts', 'spec/**/*.ts']).pipe(tslint()).pipe(tslint.report());
2726
});
2827

2928
gulp.task('format:enforce', () => {
@@ -45,7 +44,7 @@ gulp.task('tsc', function(done) {
4544
});
4645

4746
gulp.task('lint', function(done) {
48-
runSequence('jshint', 'format:enforce', done);
47+
runSequence('tslint', 'format:enforce', done);
4948
});
5049

5150
gulp.task('prepublish', function(done) {
@@ -54,7 +53,7 @@ gulp.task('prepublish', function(done) {
5453

5554
gulp.task('pretest', function(done) {
5655
runSequence(
57-
['webdriver:update', 'jshint', 'clang'], 'tsc', 'built:copy', done);
56+
['webdriver:update', 'tslint', 'clang'], 'tsc', 'built:copy', done);
5857
});
5958

6059
gulp.task('default', ['prepublish']);

lib/blockingproxy.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Promise} from 'es6-promise';
22
import * as http from 'http';
33
import * as url from 'url';
44

5-
var angularWaits = require('./angular/wait.js');
5+
let angularWaits = require('./angular/wait.js');
66

77
/**
88
* The stability proxy is an http server responsible for intercepting
@@ -45,7 +45,7 @@ export class BlockingProxy {
4545
* @param {string} originalUrl The URL from the incoming command.
4646
*/
4747
static executeAsyncUrl(originalUrl: string) {
48-
var parts = originalUrl.split('/');
48+
let parts = originalUrl.split('/');
4949
return [parts[0], parts[1], parts[2], 'execute_async'].join('/');
5050
}
5151

@@ -70,12 +70,12 @@ export class BlockingProxy {
7070
// See https://code.google.com/p/selenium/wiki/JsonWireProtocol for
7171
// descriptions of the paths.
7272
// We shouldn't stabilize if we haven't loaded the page yet.
73-
var parts = commandPath.split('/');
73+
let parts = commandPath.split('/');
7474
if (parts.length < 4) {
7575
return false;
7676
}
7777

78-
var commandsToWaitFor = [
78+
let commandsToWaitFor = [
7979
'executeScript', 'screenshot', 'source', 'title', 'element', 'elements', 'execute', 'keys',
8080
'moveto', 'click', 'buttondown', 'buttonup', 'doubleclick', 'touch', 'get'
8181
];
@@ -98,21 +98,20 @@ export class BlockingProxy {
9898
* @return {http.ClientRequest}
9999
*/
100100
createSeleniumRequest(method, messageUrl, callback) {
101-
var parsedUrl = url.parse(this.seleniumAddress);
102-
var options = {};
101+
let parsedUrl = url.parse(this.seleniumAddress);
102+
let options = {};
103103
options['method'] = method;
104104
options['path'] = parsedUrl.path + messageUrl;
105105
options['hostname'] = parsedUrl.hostname;
106106
options['port'] = parsedUrl.port;
107107

108-
var request = http.request(options, callback);
108+
let request = http.request(options, callback);
109109

110110
return request;
111111
};
112112

113113
handleProxyCommand(message, data, response) {
114-
console.log('Got message: ' + message.url);
115-
var command = message.url.split('/')[2];
114+
let command = message.url.split('/')[2];
116115
switch (command) {
117116
case 'enabled':
118117
if (message.method === 'GET') {
@@ -152,10 +151,10 @@ export class BlockingProxy {
152151
}
153152

154153
sendRequestToStabilize(originalRequest) {
155-
var self = this;
154+
let self = this;
156155
console.log('Waiting for stability...', originalRequest.url);
157-
var deferred = new Promise((resolve, reject) => {
158-
var stabilityRequest = self.createSeleniumRequest(
156+
let deferred = new Promise((resolve, reject) => {
157+
let stabilityRequest = self.createSeleniumRequest(
159158
'POST', BlockingProxy.executeAsyncUrl(originalRequest.url), function(stabilityResponse) {
160159
// TODO - If the response is that angular is not available on the
161160
// page, should we just go ahead and continue?
@@ -170,7 +169,7 @@ export class BlockingProxy {
170169
});
171170

172171
stabilityResponse.on('end', () => {
173-
var value = JSON.parse(stabilityData).value;
172+
let value = JSON.parse(stabilityData).value;
174173
if (value) {
175174
// waitForAngular only returns a value if there was an error
176175
// in the browser.
@@ -193,8 +192,8 @@ export class BlockingProxy {
193192
}
194193

195194
requestListener(originalRequest: http.IncomingMessage, response: http.ServerResponse) {
196-
var self = this;
197-
var stabilized = Promise.resolve(null);
195+
let self = this;
196+
let stabilized = Promise.resolve(null);
198197

199198
if (BlockingProxy.isProxyCommand(originalRequest.url)) {
200199
let commandData = '';
@@ -216,7 +215,7 @@ export class BlockingProxy {
216215

217216
stabilized.then(
218217
() => {
219-
var seleniumRequest = self.createSeleniumRequest(
218+
let seleniumRequest = self.createSeleniumRequest(
220219
originalRequest.method, originalRequest.url, function(seleniumResponse) {
221220
response.writeHead(seleniumResponse.statusCode, seleniumResponse.headers);
222221
seleniumResponse.pipe(response);

lib/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class BPClient {
1818

1919
let request = http.request(options, (response) => {
2020
response.on('data', () => {});
21-
response.on('error', (err) => {reject(err)});
21+
response.on('error', (err) => reject(err));
2222
response.on('end', () => {
2323
resolve();
2424
});

lib/config.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import * as minimist from 'minimist';
44

55
export interface Config {
6-
help?: boolean
7-
seleniumAddress?: string
8-
port?: number
9-
rootElement?: string
6+
help?: boolean;
7+
seleniumAddress?: string;
8+
port?: number;
9+
rootElement?: string;
1010
}
1111

1212
const opts: minimist.Opts = {
@@ -37,5 +37,5 @@ Options:
3737
--port, -p The port to listen on
3838
--selenumAddress, -s The address of the selenium remote server to proxy
3939
--rootElement Element housing ng-app, if not html or body
40-
`)
40+
`);
4141
}

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@
2525
"clang-format": "^1.0.34",
2626
"gulp": "^3.9.1",
2727
"gulp-clang-format": "^1.0.23",
28+
"gulp-tslint": "^7.0.1",
2829
"jasmine": "2.3.2",
2930
"jasmine-ts": "0.0.3",
3031
"jshint": "2.9.1",
3132
"run-sequence": "^1.2.2",
3233
"ts-node": "^1.3.0",
34+
"tslint": "^4.0.2",
35+
"tslint-eslint-rules": "^3.1.0",
3336
"typescript": "^2.0.3",
37+
"vrsource-tslint-rules": "^0.14.1",
3438
"webdriver-manager": "^10.2.2"
3539
},
3640
"repository": {
@@ -46,7 +50,6 @@
4650
"test": "jasmine-ts spec/unit/**/*.ts",
4751
"test:auto": "find lib spec | entr jasmine-ts spec/unit/**/*.ts",
4852
"testapp": "cd testapp && npm start",
49-
"install_testapp": "cd testapp && npm install",
5053
"test:e2e": "jasmine-ts spec/e2e/**/*.ts"
5154
},
5255
"jshintConfig": {

spec/e2e/ng1_async_spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('ng1 synchronizing with slow pages', function() {
7979

8080
driver.getPageSource()
8181
.then((source) => {
82-
expect(source).toMatch('polling mechanism')
82+
expect(source).toMatch('polling mechanism');
8383
done();
8484
})
8585
.thenCatch(done.fail);

spec/unit/config_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {processArgs} from '../../lib/config';
22

33
describe('cli launcher', () => {
44
it('should read selenium address from commandline', () => {
5-
let argv = processArgs(['--seleniumAddress', 'http://test.com'])
6-
expect(argv.seleniumAddress).toBe('http://test.com')
5+
let argv = processArgs(['--seleniumAddress', 'http://test.com']);
6+
expect(argv.seleniumAddress).toBe('http://test.com');
77
});
88
});

spec/unit/proxy_spec.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {BlockingProxy} from '../../lib/blockingproxy'
1+
import {BlockingProxy} from '../../lib/blockingproxy';
22

33
describe('BlockingProxy', () => {
4-
it('should be able to be created',
5-
() => {
6-
let proxy = new BlockingProxy(8111);
7-
expect(proxy.stabilityEnabled).toBe(true);
8-
});
4+
it('should be able to be created', () => {
5+
let proxy = new BlockingProxy(8111);
6+
expect(proxy.stabilityEnabled).toBe(true);
7+
});
98
});

tslint.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"rulesDirectory": [
3+
"node_modules/vrsource-tslint-rules/rules",
4+
"node_modules/tslint-eslint-rules/dist/rules"
5+
],
6+
"rules": {
7+
"no-duplicate-imports": true,
8+
"no-duplicate-variable": true,
9+
"no-jasmine-focus": true,
10+
"no-var-keyword": true,
11+
"semicolon": [true],
12+
"variable-name": [true, "ban-keywords"],
13+
"no-inner-declarations": [true, "function"]
14+
}
15+
}

0 commit comments

Comments
 (0)