Skip to content

Commit 6b54856

Browse files
committed
chore: increase linting strictness
1 parent 32059ff commit 6b54856

34 files changed

+693
-399
lines changed

.eslintrc.json

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,6 @@
3232
"strict": ["error", "global"],
3333
"promise/no-native": "error",
3434

35-
// TBD
36-
"@typescript-eslint/ban-types": "off",
37-
"@typescript-eslint/explicit-module-boundary-types": "off",
38-
"@typescript-eslint/no-empty-function": "off",
39-
"@typescript-eslint/no-explicit-any": "off",
40-
"@typescript-eslint/no-this-alias": "off",
41-
"@typescript-eslint/no-non-null-assertion": "off",
42-
"@typescript-eslint/no-var-requires": "off",
43-
"no-var": "off",
44-
"prefer-const": "off",
45-
"prefer-spread": "off",
46-
"prefer-rest-params": "off"
47-
48-
// possible future options
49-
// "@typescript-eslint/ban-types": 2,
50-
// "@typescript-eslint/explicit-module-boundary-types": 2,
51-
// "@typescript-eslint/no-empty-function": 2,
52-
// "@typescript-eslint/no-explicit-any": 2,
53-
// "@typescript-eslint/no-this-alias": 2,
54-
// "@typescript-eslint/no-non-null-assertion": 2,
55-
// "@typescript-eslint/no-var-requires": 2,
56-
// "no-var": 2,
57-
// "prefer-const": 2
58-
},
59-
"settings": {
60-
"jsdoc": {
61-
"check-types": false,
62-
"mode": "typescript",
63-
"tagNamePreference": {
64-
"augments": "extends"
65-
}
66-
}
35+
"@typescript-eslint/no-explicit-any": "off"
6736
}
6837
}

package-lock.json

Lines changed: 350 additions & 104 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
"build:docs": "npm run build:dts && typedoc",
9393
"check:bench": "node test/benchmarks/driverBench",
9494
"check:coverage": "nyc npm run check:test",
95-
"check:lint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
95+
"check:lint": "tsc -v && tsc --noEmit && eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
9696
"check:test": "mocha --recursive test/functional test/unit",
9797
"check:ts": "tsc --noEmit",
9898
"check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",

src/apm.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import type { MongoClient } from './mongo_client';
77

88
/** @public */
99
export class Instrumentation extends EventEmitter {
10-
$MongoClient: any;
11-
$prototypeConnect: any;
10+
$MongoClient?: typeof MongoClient;
11+
$prototypeConnect?: typeof MongoClient['connect'];
1212

1313
/** @event */
1414
static readonly STARTED = 'started' as const;
@@ -21,13 +21,14 @@ export class Instrumentation extends EventEmitter {
2121
super();
2222
}
2323

24-
instrument(MongoClient: any, callback: Callback) {
24+
instrument(mongoClientClass: typeof MongoClient, callback?: Callback): void {
2525
// store a reference to the original functions
26-
this.$MongoClient = MongoClient;
27-
const $prototypeConnect = (this.$prototypeConnect = MongoClient.prototype.connect);
26+
this.$MongoClient = mongoClientClass;
27+
const $prototypeConnect = (this.$prototypeConnect = mongoClientClass.prototype.connect);
2828

29+
// eslint-disable-next-line @typescript-eslint/no-this-alias
2930
const instrumentation = this;
30-
MongoClient.prototype.connect = function (this: MongoClient, callback: Callback) {
31+
mongoClientClass.prototype.connect = function (this: MongoClient, callback: Callback) {
3132
// override monitorCommands to be switched on
3233
this.s.options = { ...(this.s.options ?? {}), monitorCommands: true };
3334

@@ -42,12 +43,14 @@ export class Instrumentation extends EventEmitter {
4243
);
4344

4445
return $prototypeConnect.call(this, callback);
45-
};
46+
} as MongoClient['connect'];
4647

4748
if (typeof callback === 'function') callback(undefined, this);
4849
}
4950

50-
uninstrument() {
51-
this.$MongoClient.prototype.connect = this.$prototypeConnect;
51+
uninstrument(): void {
52+
if (this.$MongoClient) {
53+
this.$MongoClient.prototype.connect = this.$prototypeConnect as any;
54+
}
5255
}
5356
}

src/bson.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525

2626
/** @public */
2727
export interface Document {
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2829
[key: string]: any;
2930
}
3031

src/bulk/common.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export class BulkWriteResult {
216216
}
217217
}
218218

219-
toJSON(): object {
219+
toJSON(): Document {
220220
return this.result;
221221
}
222222

@@ -235,9 +235,9 @@ export class BulkWriteResult {
235235
* @category Error
236236
*/
237237
export class WriteConcernError {
238-
err: any;
238+
err: { errmsg: string; code: number };
239239

240-
constructor(err: any) {
240+
constructor(err: { errmsg: string; code: number }) {
241241
this.err = err;
242242
}
243243

@@ -266,9 +266,9 @@ export class WriteConcernError {
266266
* @category Error
267267
*/
268268
export class WriteError {
269-
err: any;
269+
err: { errmsg?: string; code: number; index: number; op: Document };
270270

271-
constructor(err: any) {
271+
constructor(err: { errmsg?: string; code: number; index: number; op: Document }) {
272272
this.err = err;
273273
}
274274

@@ -288,11 +288,11 @@ export class WriteError {
288288
}
289289

290290
/** Returns the underlying operation that caused the error */
291-
getOperation(): any {
291+
getOperation(): Document {
292292
return this.err.op;
293293
}
294294

295-
toJSON(): { code: number; index: number; errmsg?: string; op: any } {
295+
toJSON(): { code: number; index: number; errmsg?: string; op: Document } {
296296
return { code: this.err.code, index: this.err.index, errmsg: this.err.errmsg, op: this.err.op };
297297
}
298298

@@ -578,8 +578,8 @@ export class BulkWriteError extends MongoError {
578578
result?: BulkWriteResult;
579579

580580
/** Creates a new BulkWriteError */
581-
constructor(error?: any, result?: BulkWriteResult) {
582-
const message = error.err || error.errmsg || error.errMessage || error;
581+
constructor(error?: MongoError, result?: BulkWriteResult) {
582+
const message = (error as any).err || error?.errmsg || (error as any).errMessage || error;
583583
super(message);
584584

585585
Object.assign(this, error);

src/bulk/ordered.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class OrderedBulkOperation extends BulkOperationBase {
6868
}
6969
}
7070

71-
export function initializeOrderedBulkOp(collection: Collection, options: BulkWriteOptions) {
71+
export function initializeOrderedBulkOp(
72+
collection: Collection,
73+
options: BulkWriteOptions
74+
): OrderedBulkOperation {
7275
return new OrderedBulkOperation(collection, options);
7376
}

src/bulk/unordered.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ class UnorderedBulkOperation extends BulkOperationBase {
9797
}
9898
}
9999

100-
export function initializeUnorderedBulkOp(collection: Collection, options: BulkWriteOptions) {
100+
export function initializeUnorderedBulkOp(
101+
collection: Collection,
102+
options: BulkWriteOptions
103+
): UnorderedBulkOperation {
101104
return new UnorderedBulkOperation(collection, options);
102105
}

src/change_stream.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export class ChangeStream extends EventEmitter {
209209
this.topology = parent.s.topology;
210210
} else if (parent instanceof MongoClient) {
211211
this.type = CHANGE_DOMAIN_TYPES.CLUSTER;
212+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
212213
this.topology = parent.topology!;
213214
} else {
214215
throw new TypeError(
@@ -406,16 +407,16 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
406407
}
407408
}
408409

409-
set resumeToken(token) {
410+
set resumeToken(token: ResumeToken) {
410411
this._resumeToken = token;
411412
this.emit(ChangeStream.RESUME_TOKEN_CHANGED, token);
412413
}
413414

414-
get resumeToken() {
415+
get resumeToken(): ResumeToken {
415416
return this._resumeToken;
416417
}
417418

418-
get resumeOptions() {
419+
get resumeOptions(): Document {
419420
const result: Document = {};
420421
for (const optionName of CURSOR_OPTIONS) {
421422
if (Reflect.has(this.options, optionName)) {
@@ -438,7 +439,7 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
438439
return result;
439440
}
440441

441-
cacheResumeToken(resumeToken: ResumeToken) {
442+
cacheResumeToken(resumeToken: ResumeToken): void {
442443
if (this.bufferedCount() === 0 && this.cursorState.postBatchResumeToken) {
443444
this.resumeToken = this.cursorState.postBatchResumeToken;
444445
} else {
@@ -447,7 +448,7 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
447448
this.hasReceived = true;
448449
}
449450

450-
_processBatch(batchName: string, response?: Document) {
451+
_processBatch(batchName: string, response?: Document): void {
451452
const cursor = response?.cursor || {};
452453
if (cursor.postBatchResumeToken) {
453454
this.cursorState.postBatchResumeToken = cursor.postBatchResumeToken;
@@ -458,7 +459,7 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
458459
}
459460
}
460461

461-
_initializeCursor(callback: Callback) {
462+
_initializeCursor(callback: Callback): void {
462463
super._initializeCursor((err, result) => {
463464
if (err || result == null) {
464465
callback(err, result);
@@ -484,7 +485,7 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
484485
});
485486
}
486487

487-
_getMore(callback: Callback) {
488+
_getMore(callback: Callback): void {
488489
super._getMore((err, response) => {
489490
if (err) {
490491
callback(err);
@@ -646,7 +647,7 @@ function processError(changeStream: ChangeStream, error?: AnyError, callback?: C
646647
changeStream.closed = true;
647648
}
648649

649-
if (cursor && isResumableError(error, maxWireVersion(cursor.server))) {
650+
if (cursor && isResumableError(error as MongoError, maxWireVersion(cursor.server))) {
650651
changeStream.cursor = undefined;
651652

652653
// stop listening to all events from old cursor

0 commit comments

Comments
 (0)