Skip to content

Commit 0c5fa90

Browse files
committed
chore(NODE-4321): add typescript to eslint rules
1 parent 9613021 commit 0c5fa90

15 files changed

+595
-555
lines changed

.eslintrc.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"plugin:prettier/recommended",
66
"plugin:@typescript-eslint/eslint-recommended",
77
"plugin:@typescript-eslint/recommended",
8-
"prettier/@typescript-eslint"
8+
"prettier/@typescript-eslint",
9+
"plugin:@typescript-eslint/recommended-requiring-type-checking"
910
],
1011
"env": {
1112
"node": true
@@ -17,8 +18,12 @@
1718
"Set": true,
1819
"Map": false
1920
},
21+
"parser": "@typescript-eslint/parser",
2022
"parserOptions": {
21-
"ecmaVersion": 2017
23+
"ecmaVersion": 2017,
24+
"project": [
25+
"./tsconfig.json"
26+
]
2227
},
2328
"plugins": [
2429
"prettier",
@@ -52,6 +57,11 @@
5257
"Function": false
5358
}
5459
}
55-
]
60+
],
61+
"@typescript-eslint/no-unsafe-member-access": "off",
62+
"@typescript-eslint/no-unsafe-assignment": "off",
63+
"@typescript-eslint/no-unsafe-return": "off",
64+
"@typescript-eslint/no-unsafe-argument": "off",
65+
"@typescript-eslint/no-unsafe-call": "off"
5666
}
5767
}

package-lock.json

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

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,23 @@
3131
"@babel/plugin-external-helpers": "^7.10.4",
3232
"@babel/preset-env": "^7.11.0",
3333
"@istanbuljs/nyc-config-typescript": "^1.0.1",
34-
"@microsoft/api-extractor": "^7.11.2",
34+
"@microsoft/api-extractor": "^7.28.0",
3535
"@rollup/plugin-babel": "^5.2.0",
3636
"@rollup/plugin-commonjs": "^15.0.0",
3737
"@rollup/plugin-json": "^4.1.0",
3838
"@rollup/plugin-node-resolve": "^9.0.0",
3939
"@rollup/plugin-replace": "^4.0.0",
4040
"@rollup/plugin-typescript": "^6.0.0",
41-
"@typescript-eslint/eslint-plugin": "^3.10.1",
42-
"@typescript-eslint/parser": "^3.10.1",
41+
"@types/node": "^18.0.0",
42+
"@typescript-eslint/eslint-plugin": "^5.30.0",
43+
"@typescript-eslint/parser": "^5.30.0",
4344
"array-includes": "^3.1.3",
4445
"benchmark": "^2.1.4",
4546
"chai": "^4.2.0",
46-
"eslint": "^7.7.0",
47-
"eslint-config-prettier": "^6.11.0",
48-
"eslint-plugin-prettier": "^3.1.4",
49-
"eslint-plugin-tsdoc": "^0.2.6",
47+
"eslint": "^7.32.0",
48+
"eslint-config-prettier": "^6.15.0",
49+
"eslint-plugin-prettier": "^3.4.1",
50+
"eslint-plugin-tsdoc": "^0.2.16",
5051
"karma": "^6.3.4",
5152
"karma-chai": "^0.1.0",
5253
"karma-chrome-launcher": "^3.1.0",
@@ -65,10 +66,9 @@
6566
"rollup-plugin-node-polyfills": "^0.2.1",
6667
"rollup-plugin-polyfill-node": "^0.7.0",
6768
"standard-version": "^9.3.0",
68-
"ts-node": "^9.0.0",
69+
"ts-node": "^9.1.1",
6970
"tsd": "^0.20.0",
70-
"typedoc": "^0.21.2",
71-
"typescript": "^4.0.2",
71+
"typescript": "^4.7.4",
7272
"typescript-cached-transpile": "0.0.6",
7373
"uuid": "^8.3.2"
7474
},

src/code.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class Code {
5252

5353
inspect(): string {
5454
const codeJson = this.toJSON();
55-
return `new Code("${codeJson.code}"${
55+
return `new Code("${codeJson.code.toString()}"${
5656
codeJson.scope ? `, ${JSON.stringify(codeJson.scope)}` : ''
5757
})`;
5858
}

src/db_ref.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export class DBRef {
115115
// NOTE: if OID is an ObjectId class it will just print the oid string.
116116
const oid =
117117
this.oid === undefined || this.oid.toString === undefined ? this.oid : this.oid.toString();
118+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
118119
return `new DBRef("${this.namespace}", new ObjectId("${oid}")${
119120
this.db ? `, "${this.db}"` : ''
120121
})`;

src/decimal128.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ export class Decimal128 {
690690
// representation should be treated as 0/-0" spec cases in decimal128-1.json)
691691
if (significand_digits > 34) {
692692
string.push(`${0}`);
693-
if (exponent > 0) string.push('E+' + exponent);
694-
else if (exponent < 0) string.push('E' + exponent);
693+
if (exponent > 0) string.push(`E+${exponent}`);
694+
else if (exponent < 0) string.push(`E${exponent}`);
695695
return string.join('');
696696
}
697697

@@ -709,7 +709,7 @@ export class Decimal128 {
709709
// Exponent
710710
string.push('E');
711711
if (scientific_exponent > 0) {
712-
string.push('+' + scientific_exponent);
712+
string.push(`+${scientific_exponent}`);
713713
} else {
714714
string.push(`${scientific_exponent}`);
715715
}

src/extended_json.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export function isBSONType(value: unknown): value is BSONType {
4444
const BSON_INT32_MAX = 0x7fffffff;
4545
const BSON_INT32_MIN = -0x80000000;
4646
// INT64 boundaries
47+
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
4748
const BSON_INT64_MAX = 0x7fffffffffffffff;
4849
const BSON_INT64_MIN = -0x8000000000000000;
4950

src/long.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,37 @@ import type { Timestamp } from './timestamp';
44

55
interface LongWASMHelpers {
66
/** Gets the high bits of the last operation performed */
7-
get_high(): number;
8-
div_u(lowBits: number, highBits: number, lowBitsDivisor: number, highBitsDivisor: number): number;
9-
div_s(lowBits: number, highBits: number, lowBitsDivisor: number, highBitsDivisor: number): number;
10-
rem_u(lowBits: number, highBits: number, lowBitsDivisor: number, highBitsDivisor: number): number;
11-
rem_s(lowBits: number, highBits: number, lowBitsDivisor: number, highBitsDivisor: number): number;
7+
get_high(this: void): number;
8+
div_u(
9+
this: void,
10+
lowBits: number,
11+
highBits: number,
12+
lowBitsDivisor: number,
13+
highBitsDivisor: number
14+
): number;
15+
div_s(
16+
this: void,
17+
lowBits: number,
18+
highBits: number,
19+
lowBitsDivisor: number,
20+
highBitsDivisor: number
21+
): number;
22+
rem_u(
23+
this: void,
24+
lowBits: number,
25+
highBits: number,
26+
lowBitsDivisor: number,
27+
highBitsDivisor: number
28+
): number;
29+
rem_s(
30+
this: void,
31+
lowBits: number,
32+
highBits: number,
33+
lowBitsDivisor: number,
34+
highBitsDivisor: number
35+
): number;
1236
mul(
37+
this: void,
1338
lowBits: number,
1439
highBits: number,
1540
lowBitsMultiplier: number,
@@ -471,6 +496,7 @@ export class Long {
471496
// into the result, and subtract it from the remainder. It is critical that
472497
// the approximate value is less than or equal to the real value so that the
473498
// remainder never becomes negative.
499+
// eslint-disable-next-line @typescript-eslint/no-this-alias
474500
rem = this;
475501
while (rem.gte(divisor)) {
476502
// Approximate the result of division. This may be a little greater or

src/objectid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ObjectId {
3737
static cacheHexString: boolean;
3838

3939
/** ObjectId Bytes @internal */
40-
private [kId]: Buffer;
40+
private [kId]!: Buffer;
4141
/** ObjectId hexString cache @internal */
4242
private __id?: string;
4343

src/parser/calculate_size.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,16 @@ function calculateElement(
121121
);
122122
}
123123
} else if (value['_bsontype'] === 'Binary') {
124+
const binary: Binary = value;
124125
// Check what kind of subtype we have
125-
if (value.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
126+
if (binary.sub_type === Binary.SUBTYPE_BYTE_ARRAY) {
126127
return (
127128
(name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) +
128-
(value.position + 1 + 4 + 1 + 4)
129+
(binary.position + 1 + 4 + 1 + 4)
129130
);
130131
} else {
131132
return (
132-
(name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (value.position + 1 + 4 + 1)
133+
(name != null ? Buffer.byteLength(name, 'utf8') + 1 : 0) + (binary.position + 1 + 4 + 1)
133134
);
134135
}
135136
} else if (value['_bsontype'] === 'Symbol') {

src/parser/deserializer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ function deserializeObject(
697697
value = new DBRef(namespace, oid);
698698
} else {
699699
throw new BSONError(
700-
'Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"'
700+
`Detected unknown BSON type ${elementType.toString(16)} for fieldname "${name}"`
701701
);
702702
}
703703
if (name === '__proto__') {
@@ -742,9 +742,11 @@ function isolateEval(
742742
functionCache?: { [hash: string]: Function },
743743
object?: Document
744744
) {
745+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
745746
if (!functionCache) return new Function(functionString);
746747
// Check for cache hit, eval if missing and return cached function
747748
if (functionCache[functionString] == null) {
749+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
748750
functionCache[functionString] = new Function(functionString);
749751
}
750752

src/parser/serializer.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ export function serializeInto(
763763
if (Array.isArray(object)) {
764764
// Get object keys
765765
for (let i = 0; i < object.length; i++) {
766-
const key = '' + i;
766+
const key = String(i);
767767
let value = object[i];
768768

769769
// Is there an override value
@@ -841,6 +841,7 @@ export function serializeInto(
841841
} else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
842842
index = serializeMinMax(buffer, key, value, index, true);
843843
} else if (typeof value['_bsontype'] !== 'undefined') {
844+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
844845
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
845846
}
846847
}
@@ -942,6 +943,7 @@ export function serializeInto(
942943
} else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
943944
index = serializeMinMax(buffer, key, value, index);
944945
} else if (typeof value['_bsontype'] !== 'undefined') {
946+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
945947
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
946948
}
947949
}
@@ -1047,6 +1049,7 @@ export function serializeInto(
10471049
} else if (value['_bsontype'] === 'MinKey' || value['_bsontype'] === 'MaxKey') {
10481050
index = serializeMinMax(buffer, key, value, index);
10491051
} else if (typeof value['_bsontype'] !== 'undefined') {
1052+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
10501053
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
10511054
}
10521055
}

src/parser/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ declare let window: any;
3333
declare let require: Function;
3434
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3535
declare let global: any;
36-
declare const self: unknown;
3736
// eslint-disable-next-line @typescript-eslint/no-explicit-any
3837
declare let process: any; // Used by @rollup/plugin-replace
3938

src/utils/global.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function getGlobal<T = Record<string, unknown>>(): T {
1717
checkForMath(typeof window === 'object' && window) ||
1818
checkForMath(typeof self === 'object' && self) ||
1919
checkForMath(typeof global === 'object' && global) ||
20+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
2021
Function('return this')()
2122
);
2223
}

src/uuid.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class UUID {
2525
static cacheHexString: boolean;
2626

2727
/** UUID Bytes @internal */
28-
private [kId]: Buffer;
28+
private [kId]!: Buffer;
2929
/** UUID hexString cache @internal */
3030
private __id?: string;
3131

0 commit comments

Comments
 (0)