Skip to content

Commit 3473673

Browse files
authored
Add official tslint config (googleapis#142)
* Adds the official tslint config 'variable-name' had to be made weaker as this module has some public members that don't follow the camelCase naming convention. 'no-duplicate-variable', 'no-unreachable' and 'label-undefined' are no longer necessary as the compiler obviates these now.
1 parent 257816b commit 3473673

File tree

8 files changed

+70
-71
lines changed

8 files changed

+70
-71
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"typescript": "^2.2.2"
5252
},
5353
"scripts": {
54-
"lint": "tslint -c tslint.json ts/**/*.ts",
54+
"lint": "tslint --type-check -p tsconfig.json -c tslint.json ts/**/*.ts",
5555
"mocha": "mocha --reporter spec --timeout 4000 --require source-map-support/register",
5656
"generate-docs": "typedoc --name 'Google Node.js OAuth 2.0 Client' --out docs --readme README.md ts/lib",
5757
"coverage": "istanbul cover -x 'apis/**' _mocha -- --reporter spec --timeout 4000",

ts/lib/auth/computeclient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import * as util from 'util';
1817
import Auth2Client from './oauth2client';
1918

2019
export default class Compute extends Auth2Client {

ts/lib/auth/oauth2client.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import LoginTicket from './loginticket';
1919
import PemVerifier from './../pemverifier';
2020
import { merge } from 'lodash';
2121
import * as querystring from 'querystring';
22-
import * as util from 'util';
2322
const noop = Function.prototype;
2423

2524
export default class OAuth2Client extends AuthClient {
@@ -324,6 +323,10 @@ export default class OAuth2Client extends AuthClient {
324323
// Callbacks will close over this to ensure that we only retry once
325324
let retry = true;
326325
const unusedUri = null;
326+
327+
// Declare authCb upfront to avoid the linter complaining about use before
328+
// declaration.
329+
let authCb;
327330

328331
// Hook the callback routine to call the _postRequest method.
329332
const postRequestCb = (err, body, resp) => {
@@ -346,7 +349,7 @@ export default class OAuth2Client extends AuthClient {
346349
}
347350
};
348351

349-
const authCb = (err, headers, response) => {
352+
authCb = (err, headers, response) => {
350353
if (err) {
351354
postRequestCb(err, null, response);
352355
} else {

ts/lib/auth/refreshclient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import Auth2Client from './oauth2client';
18-
import * as util from 'util';
1918

2019
export default class UserRefreshClient extends Auth2Client {
2120

ts/test/test.googleauth.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,41 @@ import * as nock from 'nock';
1919
import * as fs from 'fs';
2020
import * as path from 'path';
2121
import GoogleAuth from '../lib/auth/googleauth';
22-
import { Transporter, DefaultTransporter } from '../lib/transporters';
22+
import { DefaultTransporter } from '../lib/transporters';
2323

2424
nock.disableNetConnect();
2525

26+
// Mocks the transporter class to simulate GCE.
27+
class MockTransporter extends DefaultTransporter {
28+
public isGCE: boolean;
29+
public throw_error: boolean;
30+
public executionCount: number;
31+
constructor(simulate_gce, throw_error?) {
32+
super();
33+
this.isGCE = false;
34+
if (simulate_gce) {
35+
this.isGCE = true;
36+
}
37+
this.throw_error = throw_error;
38+
this.executionCount = 0;
39+
}
40+
public request(options, callback) {
41+
if (options.method === 'GET' && options.uri === 'http://metadata.google.internal') {
42+
this.executionCount += 1;
43+
let err = null;
44+
const response = { headers: { } };
45+
if (this.throw_error) {
46+
err = new Error('blah');
47+
} else if (this.isGCE) {
48+
response.headers['metadata-flavor'] = 'Google';
49+
}
50+
return callback(err, null, response);
51+
} else {
52+
throw new Error('unexpected request');
53+
}
54+
}
55+
}
56+
2657
// Creates a standard JSON auth object for testing.
2758
function createJwtJSON() {
2859
return {
@@ -1340,34 +1371,3 @@ describe('GoogleAuth', () => {
13401371
});
13411372
});
13421373
});
1343-
1344-
// Mocks the transporter class to simulate GCE.
1345-
class MockTransporter extends DefaultTransporter {
1346-
public isGCE: boolean;
1347-
public throw_error: boolean;
1348-
public executionCount: number;
1349-
constructor(simulate_gce, throw_error?) {
1350-
super();
1351-
this.isGCE = false;
1352-
if (simulate_gce) {
1353-
this.isGCE = true;
1354-
}
1355-
this.throw_error = throw_error;
1356-
this.executionCount = 0;
1357-
}
1358-
public request(options, callback) {
1359-
if (options.method === 'GET' && options.uri === 'http://metadata.google.internal') {
1360-
this.executionCount += 1;
1361-
let err = null;
1362-
const response = { headers: { } };
1363-
if (this.throw_error) {
1364-
err = new Error('blah');
1365-
} else if (this.isGCE) {
1366-
response.headers['metadata-flavor'] = 'Google';
1367-
}
1368-
return callback(err, null, response);
1369-
} else {
1370-
throw new Error('unexpected request');
1371-
}
1372-
}
1373-
}

ts/test/test.oauth2.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import * as fs from 'fs';
2121
import * as crypto from 'crypto';
2222
import * as nock from 'nock';
2323
import * as path from 'path';
24-
import AuthClient from '../lib/auth/authclient';
2524
import GoogleAuth from '../lib/auth/googleauth';
2625

2726
nock.disableNetConnect();

ts/test/test.transporters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import * as assert from 'assert';
1818
import * as nock from 'nock';
19-
import { Transporter, DefaultTransporter } from '../lib/transporters';
19+
import { DefaultTransporter } from '../lib/transporters';
2020

2121
// tslint:disable-next-line
2222
const version = require('../package.json').version;

tslint.json

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
{
2-
"lintOptions": {
3-
"typeCheck": true
4-
},
5-
"extends": "tslint:latest",
62
"rules": {
7-
"ban": [true,
8-
["describe", "only"],
9-
["it", "only"],
10-
["Object", "assign"]
11-
],
12-
13-
"callable-types": true,
14-
"interface-name": [false],
15-
"interface-over-type-literal": true,
16-
"file-header": [true,
17-
"Copyright "
18-
],
19-
"max-classes-per-file": [false],
20-
"max-line-length": [true, 140],
21-
"member-ordering": [false],
22-
"no-angle-bracket-type-assertion": true,
23-
"no-empty-interface": true,
24-
"no-string-throw": true,
3+
"class-name": true,
4+
"comment-format": [true, "check-space"],
5+
"eofline": true,
6+
"forin": true,
7+
"indent": [true, "spaces"],
8+
"jsdoc-format": true,
9+
"label-position": true,
10+
// "label-undefined": true,
11+
"no-arg": true,
12+
"no-conditional-assignment": true,
13+
"no-construct": true,
14+
"no-debugger": true,
15+
// "no-duplicate-key": true,
16+
"no-duplicate-variable": true,
17+
"no-empty": true,
18+
"no-inferrable-types": true,
19+
"no-internal-module": true,
20+
"no-shadowed-variable": true,
2521
"no-switch-case-fall-through": true,
26-
"object-literal-sort-keys": false,
27-
"object-literal-shorthand": false,
28-
"ordered-imports": [
29-
false
30-
],
31-
"prefer-const": true,
32-
"quotemark": [true, "single", "avoid-escape"],
33-
"switch-default": false,
34-
"trailing-comma": [false],
35-
"variable-name": [false]
22+
"no-trailing-whitespace": true,
23+
// "no-unreachable": true,
24+
"no-unused-expression": true,
25+
"no-unused-variable": true,
26+
"no-use-before-declare": true,
27+
"no-var-keyword": true,
28+
"quotemark": [true, "single"],
29+
"radix": true,
30+
"semicolon": [true, "always"],
31+
"switch-default": true,
32+
"triple-equals": [true, "allow-null-check"],
33+
// "variable-name": [true, "check-format", "ban-keywords"]
34+
"variable-name": [true, "ban-keywords"]
3635
}
3736
}

0 commit comments

Comments
 (0)