Skip to content

Commit

Permalink
test(NODE-4976): ensure all use of BigInt is gated by the useBigInt64…
Browse files Browse the repository at this point in the history
… flag (#558)
  • Loading branch information
W-A-James authored Feb 7, 2023
1 parent c7e19af commit c095034
Show file tree
Hide file tree
Showing 19 changed files with 3,542 additions and 116 deletions.
10 changes: 8 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
},
"plugins": [
"prettier",
"eslint-plugin-tsdoc"
"eslint-plugin-tsdoc",
"no-bigint-usage"
],
"reportUnusedDisableDirectives": true,
"rules": {
Expand Down Expand Up @@ -62,7 +63,12 @@
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-call": "off"
"@typescript-eslint/no-unsafe-call": "off",
"no-bigint-usage/no-bigint-literals": "error",
"no-restricted-globals": [
"error",
"BigInt"
]
},
"overrides": [
{
Expand Down
36 changes: 33 additions & 3 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ functions:
working_dir: src
script: |
${PREPARE_SHELL}
echo "NODE_VERSION=${NODE_VERSION} TEST_TARGET=${TEST_TARGET}"
NODE_VERSION=${NODE_VERSION} ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh ${TEST_TARGET}
echo "NODE_VERSION=${NODE_VERSION} NO_BIGINT=${NO_BIGINT} TEST_TARGET=${TEST_TARGET}"
NODE_VERSION=${NODE_VERSION} NO_BIGINT=${NO_BIGINT} ${PROJECT_DIRECTORY}/.evergreen/run-tests.sh ${TEST_TARGET}
run checks:
- command: shell.exec
type: test
Expand All @@ -69,6 +69,18 @@ functions:
binary: bash
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-typescript.sh
run eslint plugin tests:
- command: subprocess.exec
type: test
params:
working_dir: src
timeout_secs: 60
env:
NODE_VERSION: ${NODE_VERSION}
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
binary: bash
args:
- .evergreen/run-eslint-plugin-test.sh

tasks:
- name: node-tests-v14
Expand Down Expand Up @@ -121,6 +133,17 @@ tasks:
- func: run tests
vars:
TEST_TARGET: web
- name: no-bigint-web-tests
tags: ["no-bigint", "web"]
commands:
- func: fetch source
vars:
NODE_MAJOR_VERSION: 18
- func: install dependencies
- func: run tests
vars:
TEST_TARGET: web
NO_BIGINT: true
- name: run-checks
tags:
- run-checks
Expand Down Expand Up @@ -160,12 +183,19 @@ tasks:
vars:
TS_VERSION: "next"
TRY_COMPILING_LIBRARY: "false"
- name: check-eslint-plugin
commands:
- func: fetch source
vars:
NODE_MAJOR_VERSION: 18
- func: install dependencies
- func: run eslint plugin tests

buildvariants:
- name: linux
display_name: RHEL 8.0
run_on: rhel80-small
tasks: [".node", ".web"]
tasks: [".node", ".web", "check-eslint-plugin"]
- name: lint
display_name: lint
run_on: rhel80-small
Expand Down
16 changes: 16 additions & 0 deletions .evergreen/run-eslint-plugin-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

if [ -z "$NODE_VERSION" ]; then
echo "NODE_VERSION environment variable must be specified"
exit 1
fi

NODE_ARTIFACTS_PATH="${PROJECT_DIRECTORY}/node-artifacts"

export PATH="/opt/mongodbtoolchain/v2/bin:$PATH"
export NVM_DIR="${NODE_ARTIFACTS_PATH}/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

cd etc/eslint/no-bigint-usage
npm install
npm run test
1 change: 1 addition & 0 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ case $1 in
;;
"web")
export WEB="true"
export NO_BIGINT="${NO_BIGINT:-false}"
npm run check:web
;;
*)
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ docs/public
*.0x
*.cpuprofile
*.heapprofile

.nvmrc
5 changes: 5 additions & 0 deletions etc/eslint/no-bigint-usage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# no-bigint-usage

Simple eslint plugin to disallow the use of BigInt literals and associated APIs.

Based on [this tutorial by Linus Spukas](https://dev.to/spukas/how-to-write-your-first-eslint-plugin-145)
20 changes: 20 additions & 0 deletions etc/eslint/no-bigint-usage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function noBigIntLiterals(context) {
return {
Literal(node) {
if (node.bigint && /n$/.test(node.raw)) {
context.report(
{
node,
message: 'BigInt literals not allowed'
}
)
}
}
};
}

module.exports = {
rules: {
'no-bigint-literals': { create: noBigIntLiterals }
}
}
Loading

0 comments on commit c095034

Please sign in to comment.