Skip to content

Commit c095034

Browse files
authored
test(NODE-4976): ensure all use of BigInt is gated by the useBigInt64 flag (#558)
1 parent c7e19af commit c095034

19 files changed

+3542
-116
lines changed

.eslintrc.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
},
2727
"plugins": [
2828
"prettier",
29-
"eslint-plugin-tsdoc"
29+
"eslint-plugin-tsdoc",
30+
"no-bigint-usage"
3031
],
3132
"reportUnusedDisableDirectives": true,
3233
"rules": {
@@ -62,7 +63,12 @@
6263
"@typescript-eslint/no-unsafe-assignment": "off",
6364
"@typescript-eslint/no-unsafe-return": "off",
6465
"@typescript-eslint/no-unsafe-argument": "off",
65-
"@typescript-eslint/no-unsafe-call": "off"
66+
"@typescript-eslint/no-unsafe-call": "off",
67+
"no-bigint-usage/no-bigint-literals": "error",
68+
"no-restricted-globals": [
69+
"error",
70+
"BigInt"
71+
]
6672
},
6773
"overrides": [
6874
{

.evergreen/config.yml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ functions:
4545
working_dir: src
4646
script: |
4747
${PREPARE_SHELL}
48-
echo "NODE_VERSION=${NODE_VERSION} TEST_TARGET=${TEST_TARGET}"
49-
NODE_VERSION=${NODE_VERSION} ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh ${TEST_TARGET}
48+
echo "NODE_VERSION=${NODE_VERSION} NO_BIGINT=${NO_BIGINT} TEST_TARGET=${TEST_TARGET}"
49+
NODE_VERSION=${NODE_VERSION} NO_BIGINT=${NO_BIGINT} ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh ${TEST_TARGET}
5050
run checks:
5151
- command: shell.exec
5252
type: test
@@ -69,6 +69,18 @@ functions:
6969
binary: bash
7070
args:
7171
- ${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh
72+
run eslint plugin tests:
73+
- command: subprocess.exec
74+
type: test
75+
params:
76+
working_dir: src
77+
timeout_secs: 60
78+
env:
79+
NODE_VERSION: ${NODE_VERSION}
80+
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
81+
binary: bash
82+
args:
83+
- .evergreen/run-eslint-plugin-test.sh
7284

7385
tasks:
7486
- name: node-tests-v14
@@ -121,6 +133,17 @@ tasks:
121133
- func: run tests
122134
vars:
123135
TEST_TARGET: web
136+
- name: no-bigint-web-tests
137+
tags: ["no-bigint", "web"]
138+
commands:
139+
- func: fetch source
140+
vars:
141+
NODE_MAJOR_VERSION: 18
142+
- func: install dependencies
143+
- func: run tests
144+
vars:
145+
TEST_TARGET: web
146+
NO_BIGINT: true
124147
- name: run-checks
125148
tags:
126149
- run-checks
@@ -160,12 +183,19 @@ tasks:
160183
vars:
161184
TS_VERSION: "next"
162185
TRY_COMPILING_LIBRARY: "false"
186+
- name: check-eslint-plugin
187+
commands:
188+
- func: fetch source
189+
vars:
190+
NODE_MAJOR_VERSION: 18
191+
- func: install dependencies
192+
- func: run eslint plugin tests
163193

164194
buildvariants:
165195
- name: linux
166196
display_name: RHEL 8.0
167197
run_on: rhel80-small
168-
tasks: [".node", ".web"]
198+
tasks: [".node", ".web", "check-eslint-plugin"]
169199
- name: lint
170200
display_name: lint
171201
run_on: rhel80-small

.evergreen/run-eslint-plugin-test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
if [ -z "$NODE_VERSION" ]; then
4+
echo "NODE_VERSION environment variable must be specified"
5+
exit 1
6+
fi
7+
8+
NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"
9+
10+
export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
11+
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
12+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
13+
14+
cd etc/eslint/no-bigint-usage
15+
npm install
16+
npm run test

.evergreen/run-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ case $1 in
1717
;;
1818
"web")
1919
export WEB="true"
20+
export NO_BIGINT="${NO_BIGINT:-false}"
2021
npm run check:web
2122
;;
2223
*)

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ docs/public
2929
*.0x
3030
*.cpuprofile
3131
*.heapprofile
32+
33+
.nvmrc

etc/eslint/no-bigint-usage/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# no-bigint-usage
2+
3+
Simple eslint plugin to disallow the use of BigInt literals and associated APIs.
4+
5+
Based on [this tutorial by Linus Spukas](https://dev.to/spukas/how-to-write-your-first-eslint-plugin-145)

etc/eslint/no-bigint-usage/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function noBigIntLiterals(context) {
2+
return {
3+
Literal(node) {
4+
if (node.bigint && /n$/.test(node.raw)) {
5+
context.report(
6+
{
7+
node,
8+
message: 'BigInt literals not allowed'
9+
}
10+
)
11+
}
12+
}
13+
};
14+
}
15+
16+
module.exports = {
17+
rules: {
18+
'no-bigint-literals': { create: noBigIntLiterals }
19+
}
20+
}

0 commit comments

Comments
 (0)