Skip to content

Commit 9bc8f64

Browse files
authored
chore: Increase linting strictness (#2534)
removes a number of disabled eslint rules NODE-2692
1 parent e7822f9 commit 9bc8f64

36 files changed

+742
-433
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@
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": "npm run check:ts && eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
9696
"check:test": "mocha --recursive test/functional test/unit",
97-
"check:ts": "tsc --noEmit",
97+
"check:ts": "tsc -v && tsc --noEmit",
9898
"check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",
9999
"check:ocsp": "mocha --config \"test/manual/mocharc.json\" test/manual/ocsp_support.test.js",
100100
"check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.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.prototype['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 && this.$prototypeConnect) {
53+
this.$MongoClient.prototype.connect = this.$prototypeConnect;
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/change_stream.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type { Topology } from './sdam/topology';
2020
import type { Writable } from 'stream';
2121
import type { StreamOptions } from './cursor/core_cursor';
2222
import type { OperationParent } from './operations/command';
23+
import type { CollationOptions } from './cmap/wire_protocol/write_command';
2324
const kResumeQueue = Symbol('resumeQueue');
2425

2526
const CHANGE_STREAM_OPTIONS = ['resumeAfter', 'startAfter', 'startAtOperationTime', 'fullDocument'];
@@ -33,6 +34,14 @@ const CHANGE_DOMAIN_TYPES = {
3334
CLUSTER: Symbol('Cluster')
3435
};
3536

37+
export interface ResumeOptions {
38+
startAtOperationTime?: Timestamp;
39+
batchSize?: number;
40+
maxAwaitTimeMS?: number;
41+
collation?: CollationOptions;
42+
readPreference?: ReadPreference;
43+
}
44+
3645
/**
3746
* Represents the logical starting point for a new or resuming {@link https://docs.mongodb.com/master/changeStreams/#change-stream-resume-token| Change Stream} on the server.
3847
* @public
@@ -209,6 +218,7 @@ export class ChangeStream extends EventEmitter {
209218
this.topology = parent.s.topology;
210219
} else if (parent instanceof MongoClient) {
211220
this.type = CHANGE_DOMAIN_TYPES.CLUSTER;
221+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
212222
this.topology = parent.topology!;
213223
} else {
214224
throw new TypeError(
@@ -406,30 +416,32 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
406416
}
407417
}
408418

409-
set resumeToken(token) {
419+
set resumeToken(token: ResumeToken) {
410420
this._resumeToken = token;
411421
this.emit(ChangeStream.RESUME_TOKEN_CHANGED, token);
412422
}
413423

414-
get resumeToken() {
424+
get resumeToken(): ResumeToken {
415425
return this._resumeToken;
416426
}
417427

418-
get resumeOptions() {
419-
const result: Document = {};
428+
get resumeOptions(): ResumeOptions {
429+
const result = {} as ResumeOptions;
420430
for (const optionName of CURSOR_OPTIONS) {
421431
if (Reflect.has(this.options, optionName)) {
422-
result[optionName] = Reflect.get(this.options, optionName);
432+
Reflect.set(result, optionName, Reflect.get(this.options, optionName));
423433
}
424434
}
425435

426436
if (this.resumeToken || this.startAtOperationTime) {
427-
['resumeAfter', 'startAfter', 'startAtOperationTime'].forEach(key => delete result[key]);
437+
['resumeAfter', 'startAfter', 'startAtOperationTime'].forEach(key =>
438+
Reflect.deleteProperty(result, key)
439+
);
428440

429441
if (this.resumeToken) {
430442
const resumeKey =
431443
this.options.startAfter && !this.hasReceived ? 'startAfter' : 'resumeAfter';
432-
result[resumeKey] = this.resumeToken;
444+
Reflect.set(result, resumeKey, this.resumeToken);
433445
} else if (this.startAtOperationTime && maxWireVersion(this.server) >= 7) {
434446
result.startAtOperationTime = this.startAtOperationTime;
435447
}
@@ -438,7 +450,7 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
438450
return result;
439451
}
440452

441-
cacheResumeToken(resumeToken: ResumeToken) {
453+
cacheResumeToken(resumeToken: ResumeToken): void {
442454
if (this.bufferedCount() === 0 && this.cursorState.postBatchResumeToken) {
443455
this.resumeToken = this.cursorState.postBatchResumeToken;
444456
} else {
@@ -447,7 +459,7 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
447459
this.hasReceived = true;
448460
}
449461

450-
_processBatch(batchName: string, response?: Document) {
462+
_processBatch(batchName: string, response?: Document): void {
451463
const cursor = response?.cursor || {};
452464
if (cursor.postBatchResumeToken) {
453465
this.cursorState.postBatchResumeToken = cursor.postBatchResumeToken;
@@ -458,7 +470,7 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
458470
}
459471
}
460472

461-
_initializeCursor(callback: Callback) {
473+
_initializeCursor(callback: Callback): void {
462474
super._initializeCursor((err, response) => {
463475
if (err || response == null) {
464476
callback(err, response);
@@ -482,7 +494,7 @@ export class ChangeStreamCursor extends Cursor<AggregateOperation, ChangeStreamC
482494
});
483495
}
484496

485-
_getMore(callback: Callback) {
497+
_getMore(callback: Callback): void {
486498
super._getMore((err, response) => {
487499
if (err) {
488500
callback(err);
@@ -644,7 +656,7 @@ function processError(changeStream: ChangeStream, error?: AnyError, callback?: C
644656
changeStream.closed = true;
645657
}
646658

647-
if (cursor && isResumableError(error, maxWireVersion(cursor.server))) {
659+
if (cursor && isResumableError(error as MongoError, maxWireVersion(cursor.server))) {
648660
changeStream.cursor = undefined;
649661

650662
// stop listening to all events from old cursor

0 commit comments

Comments
 (0)