Skip to content

Commit cd7649f

Browse files
JustinBeckwithshivanee-p
authored andcommitted
refactor: enable tslint rules (#664)
1 parent ed297e3 commit cd7649f

24 files changed

Lines changed: 1549 additions & 1467 deletions

handwritten/bigtable/src/app-profile.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ Please use the format 'my-app-profile' or '${instance.name}/appProfiles/my-app-p
272272
const options =
273273
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
274274

275-
const reqOpts: any = {
275+
const reqOpts = {
276276
name: this.name,
277-
};
277+
} as google.bigtable.admin.v2.IDeleteAppProfileRequest;
278278

279279
if (is.boolean(options.ignoreWarnings)) {
280280
reqOpts.ignoreWarnings = options.ignoreWarnings;
@@ -443,12 +443,12 @@ Please use the format 'my-app-profile' or '${instance.name}/appProfiles/my-app-p
443443
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb!;
444444
const gaxOptions =
445445
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
446-
const reqOpts: any = {
446+
const reqOpts = {
447447
appProfile: AppProfile.formatAppProfile_(metadata as AppProfileOptions),
448448
updateMask: {
449449
paths: [],
450450
},
451-
};
451+
} as google.bigtable.admin.v2.IUpdateAppProfileRequest;
452452
reqOpts.appProfile!.name = this.name;
453453
const fieldsForMask = [
454454
'description',
@@ -457,8 +457,8 @@ Please use the format 'my-app-profile' or '${instance.name}/appProfiles/my-app-p
457457
'allowTransactionalWrites',
458458
];
459459
fieldsForMask.forEach(field => {
460-
if (reqOpts.appProfile[field]) {
461-
reqOpts.updateMask.paths.push(snakeCase(field));
460+
if (reqOpts.appProfile![field]) {
461+
reqOpts.updateMask!.paths!.push(snakeCase(field));
462462
}
463463
});
464464

handwritten/bigtable/src/chunktransformer.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ class TransformError extends Error {
6565
* ROW_IN_PROGRESS: state after first valid chunk without commitRow or resetRow
6666
* CELL_IN_PROGRESS: state when valueSize > 0(partial cell)
6767
*/
68-
export const RowStateEnum = Object.freeze({
69-
NEW_ROW: 1,
70-
ROW_IN_PROGRESS: 2,
71-
CELL_IN_PROGRESS: 3,
72-
});
68+
export enum RowStateEnum {
69+
NEW_ROW = 1,
70+
ROW_IN_PROGRESS = 2,
71+
CELL_IN_PROGRESS = 3,
72+
}
7373

7474
/**
7575
* ChunkTransformer formats all incoming chunks in to row
@@ -143,6 +143,8 @@ export class ChunkTransformer extends Transform {
143143
case RowStateEnum.CELL_IN_PROGRESS:
144144
this.processCellInProgress(chunk);
145145
break;
146+
default:
147+
break;
146148
}
147149
if (this._destroyed) {
148150
return;

handwritten/bigtable/src/filter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface Time {
4747
end: Date;
4848
}
4949

50+
// tslint:disable-next-line no-any
5051
export type RawFilter = any;
5152

5253
export interface Condition {
@@ -255,6 +256,7 @@ export class Filter {
255256
[index: string]: Function;
256257
}
257258
const filter = new Filter();
259+
// tslint:disable-next-line no-any
258260
arrify(filters).forEach((filterObj: any) => {
259261
const key = Object.keys(filterObj)[0];
260262
if (typeof ((filter as {}) as Fn)[key] !== 'function') {
@@ -434,6 +436,7 @@ export class Filter {
434436
}
435437

436438
if (col.start || col.end) {
439+
// tslint:disable-next-line no-any
437440
const range: any = Filter.createRange(col.start!, col.end!, 'Qualifier');
438441

439442
range.familyName = col.family;

handwritten/bigtable/src/index.ts

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,22 @@ export interface BigtableOptions extends gax.GoogleAuthOptions {
104104
*/
105105
apiEndpoint?: string;
106106

107+
appProfileId?: string;
108+
107109
/**
108110
* Internal only.
109111
*/
110-
BigtableClient: v2.BigtableClient;
112+
BigtableClient?: gax.ClientOptions;
111113

112114
/**
113115
* Internal only.
114116
*/
115-
BigtableInstanceAdminClient: v2.BigtableInstanceAdminClient;
117+
BigtableInstanceAdminClient?: gax.ClientOptions;
116118

117119
/**
118120
* Internal only.
119121
*/
120-
BigtableTableAdminClient: v2.BigtableTableAdminClient;
122+
BigtableTableAdminClient?: gax.ClientOptions;
121123
}
122124

123125
/**
@@ -197,10 +199,10 @@ export interface BigtableOptions extends gax.GoogleAuthOptions {
197199
* const Bigtable = require('@google-cloud/bigtable');
198200
* const bigtable = new Bigtable();
199201
*
200-
* const callback = function(err, instance, operation) {
202+
* const callback = (err, instance, operation) => {
201203
* operation
202204
* .on('error', console.log)
203-
* .on('complete', function() {
205+
* .on('complete', () => {
204206
* // `instance` is your newly created Instance object.
205207
* });
206208
* };
@@ -283,7 +285,7 @@ export interface BigtableOptions extends gax.GoogleAuthOptions {
283285
* }
284286
* ];
285287
*
286-
* table.insert(rows, function(err) {
288+
* table.insert(rows, err => {
287289
* if (!err) {
288290
* // Your rows were successfully inserted.
289291
* }
@@ -297,15 +299,15 @@ export interface BigtableOptions extends gax.GoogleAuthOptions {
297299
* //-
298300
* table.createReadStream()
299301
* .on('error', console.error)
300-
* .on('data', function(row) {
302+
* .on('data', row => {
301303
* // `row` is a Row object.
302304
* });
303305
*
304306
* //-
305307
* // If you're not anticpating a large number of results, a callback mode
306308
* // is also available.
307309
* //-
308-
* const callback = function(err, rows) {
310+
* const callback = (err, rows) => {
309311
* // `rows` is an array of Row objects.
310312
* };
311313
*
@@ -326,7 +328,7 @@ export interface BigtableOptions extends gax.GoogleAuthOptions {
326328
* //-
327329
* const row = table.row('alincoln');
328330
*
329-
* row.get(function(err) {
331+
* row.get(err => {
330332
* // `row.data` is now populated.
331333
* });
332334
*
@@ -378,7 +380,7 @@ export interface BigtableOptions extends gax.GoogleAuthOptions {
378380
* // We can delete all of an individual row's cells using
379381
* // {@link Row#delete}.
380382
* //-
381-
* const callback = function(err) {
383+
* const callback = err => {
382384
* if (!err) {
383385
* // All cells for this row were deleted successfully.
384386
* }
@@ -408,7 +410,7 @@ export interface BigtableOptions extends gax.GoogleAuthOptions {
408410
* prefix: 'gwash'
409411
* };
410412
*
411-
* table.deleteRows(options, function(err) {
413+
* table.deleteRows(options, err => {
412414
* if (!err) {
413415
* // Rows were deleted successfully.
414416
* }
@@ -417,14 +419,14 @@ export interface BigtableOptions extends gax.GoogleAuthOptions {
417419
* //-
418420
* // If you omit the prefix, you can delete all rows in your table.
419421
* //-
420-
* table.deleteRows(function(err) {
422+
* table.deleteRows(err => {
421423
* if (!err) {
422424
* // All rows were deleted successfully.
423425
* }
424426
* });
425427
*/
426428
export class Bigtable {
427-
customEndpoint: string;
429+
customEndpoint?: string;
428430
options: BigtableOptions;
429431
api: {
430432
[index: string]:
@@ -434,13 +436,17 @@ export class Bigtable {
434436
};
435437
auth: GoogleAuth;
436438
projectId: string;
437-
appProfileId: string;
439+
appProfileId?: string;
438440
projectName: string;
439441
shouldReplaceProjectIdToken: boolean;
442+
// tslint:disable-next-line variable-name
440443
static AppProfile: AppProfile;
444+
// tslint:disable-next-line variable-name
441445
static Instance: Instance;
446+
// tslint:disable-next-line variable-name
442447
static Cluster: Cluster;
443-
constructor(options: any = {}) {
448+
449+
constructor(options: BigtableOptions = {}) {
444450
// Determine what scopes are needed.
445451
// It is the union of the scopes on all three clients.
446452
const scopes: string[] = [];
@@ -486,37 +492,37 @@ export class Bigtable {
486492
BigtableClient: Object.assign(
487493
{
488494
servicePath: customEndpoint ? customEndpointBaseUrl : defaultBaseUrl,
489-
port: customEndpoint ? parseInt(customEndpointPort, 10) : 443,
495+
port: customEndpoint ? Number(customEndpointPort) : 443,
490496
sslCreds: customEndpoint
491497
? grpc.credentials.createInsecure()
492498
: undefined,
493499
},
494500
options
495-
),
501+
) as gax.ClientOptions,
496502
BigtableInstanceAdminClient: Object.assign(
497503
{
498504
servicePath: customEndpoint
499505
? customEndpointBaseUrl
500506
: defaultAdminBaseUrl,
501-
port: customEndpoint ? parseInt(customEndpointPort, 10) : 443,
507+
port: customEndpoint ? Number(customEndpointPort) : 443,
502508
sslCreds: customEndpoint
503509
? grpc.credentials.createInsecure()
504510
: undefined,
505511
},
506512
options
507-
),
513+
) as gax.ClientOptions,
508514
BigtableTableAdminClient: Object.assign(
509515
{
510516
servicePath: customEndpoint
511517
? customEndpointBaseUrl
512518
: defaultAdminBaseUrl,
513-
port: customEndpoint ? parseInt(customEndpointPort, 10) : 443,
519+
port: customEndpoint ? Number(customEndpointPort) : 443,
514520
sslCreds: customEndpoint
515521
? grpc.credentials.createInsecure()
516522
: undefined,
517523
},
518524
options
519-
),
525+
) as gax.ClientOptions,
520526
};
521527

522528
this.api = {};
@@ -582,7 +588,7 @@ export class Bigtable {
582588
*
583589
* operation
584590
* .on('error', console.log)
585-
* .on('complete', function() {
591+
* .on('complete', () => {
586592
* // The instance was created successfully.
587593
* });
588594
* };
@@ -621,17 +627,17 @@ export class Bigtable {
621627
const callback =
622628
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
623629

624-
const reqOpts: any = {
630+
const reqOpts = {
625631
parent: this.projectName,
626632
instanceId: id,
627633
instance: {
628634
displayName: options.displayName || id,
629635
labels: options.labels,
630636
},
631-
};
637+
} as google.bigtable.admin.v2.CreateInstanceRequest;
632638

633639
if (options.type) {
634-
reqOpts.instance.type = Instance.getTypeType_(options.type);
640+
reqOpts.instance!.type = Instance.getTypeType_(options.type);
635641
}
636642

637643
reqOpts.clusters = arrify(options.clusters!).reduce((clusters, cluster) => {
@@ -759,7 +765,9 @@ export class Bigtable {
759765
return new Instance(this, name);
760766
}
761767

768+
// tslint:disable-next-line no-any
762769
request<T = any>(config?: any): AbortableDuplex;
770+
// tslint:disable-next-line no-any
763771
request<T = any>(config?: any, callback?: RequestCallback<T>): void;
764772
/**
765773
* Funnel all API requests through this method, to be sure we have a project ID.
@@ -770,6 +778,7 @@ export class Bigtable {
770778
* @param {object} config.reqOpts Request options.
771779
* @param {function} [callback] Callback function.
772780
*/
781+
// tslint:disable-next-line no-any
773782
request<T = any>(
774783
config: RequestOptions,
775784
callback?: (err: ServiceError | null, resp?: T) => void
@@ -790,16 +799,15 @@ export class Bigtable {
790799
let gaxClient = this.api[config.client];
791800
if (!gaxClient) {
792801
// Lazily instantiate client.
793-
gaxClient = new v2[config.client](
794-
(this.options[config.client] as {}) as gax.ClientOptions
795-
);
802+
const clientOptions = this.options[config.client]!;
803+
gaxClient = new v2[config.client](clientOptions);
796804
this.api[config.client] = gaxClient;
797805
}
798806
let reqOpts = extend(true, {}, config.reqOpts);
799807
if (this.shouldReplaceProjectIdToken && projectId !== '{{projectId}}') {
800808
reqOpts = replaceProjectIdToken(reqOpts, projectId!);
801809
}
802-
const requestFn = (gaxClient as any)[config.method!].bind(
810+
const requestFn = gaxClient[config.method!].bind(
803811
gaxClient,
804812
reqOpts,
805813
config.gaxOpts
@@ -930,9 +938,10 @@ promisifyAll(Bigtable, {
930938
*/
931939

932940
// Allow creating a `Bigtable` instance without using the `new` keyword.
933-
// eslint-disable-next-line no-class-assign
941+
// tslint:disable-next-line no-any
934942
(Bigtable as any) = new Proxy(Bigtable, {
935943
apply(target, thisArg, argumentsList) {
944+
// tslint:disable-next-line no-any
936945
return new (target as any)(...argumentsList);
937946
},
938947
});

0 commit comments

Comments
 (0)