Skip to content

test(NODE-4976): ensure all use of BigInt is gated by the useBigInt64 flag #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6348586
chore(NODE-4976): Add eslint plugin
W-A-James Jan 30, 2023
e2f14db
chore(NODE-4976): update package.json
W-A-James Jan 30, 2023
64ad45f
docs(NODE-4976): Reference article
W-A-James Jan 30, 2023
acbd460
chore(NODE-4976): move eslint plugin to etc directory
W-A-James Jan 30, 2023
b681dd5
test(NODE-4976): bigint tests
W-A-James Jan 30, 2023
ac718cd
test(NODE-4976): Complete tests
W-A-James Jan 31, 2023
61630a7
chore(NODE-4976): update package-lock.json
W-A-James Jan 31, 2023
d39722f
test(NODE-4976): eslint fixes
W-A-James Jan 31, 2023
1e22525
Merge branch 'main' into NODE-4976/add_tests_to_ensure_bigint_feature…
W-A-James Jan 31, 2023
6bf2647
test(NODE-4976): Add eslint plugin test
W-A-James Feb 1, 2023
6460a91
chore(NODE-4976): Update package-lock.json
W-A-James Feb 1, 2023
ff03e79
Merge branch 'NODE-4976/add_tests_to_ensure_bigint_features_are_unuse…
W-A-James Feb 1, 2023
5a26c0e
ci(NODE-4976): New task for no bigint envs
W-A-James Feb 3, 2023
ae8767c
test(NODE-4976): removed unneeded tests
W-A-James Feb 3, 2023
63fe625
test(NODE-4976): Fix failing tests
W-A-James Feb 3, 2023
30a438d
chore(NODE-4976): add .nvmrc to .gitignore
W-A-James Feb 3, 2023
08e1a8c
chore(NODE-4976): Update eslint plugin
W-A-James Feb 6, 2023
79739b6
chore(NODE-4976): Update eslint plugin and package.json
W-A-James Feb 6, 2023
23efdc5
fix(NODE-4976): Add eslint ignore comments
W-A-James Feb 6, 2023
f49bbd7
chore(NODE-4976): ci WIP
W-A-James Feb 6, 2023
ad973ef
chore(NODE-4976): Add eslint plugin ci task
W-A-James Feb 6, 2023
09a1378
chore(NODE-4976): Update package-lock.json
W-A-James Feb 6, 2023
6042d80
fix(NODE-4976): Remove unneeded build script and update plugin docs
W-A-James Feb 6, 2023
119880e
chore(NODE-4976): Add npm run script to test in web environment with …
W-A-James Feb 6, 2023
363a2e1
test(NODE-4976): Update plugin tests
W-A-James Feb 6, 2023
600df2b
chore(NODE-4976): Move responsibility to report on uses of BigInt sta…
W-A-James Feb 6, 2023
7aed548
chore(NODE-4976): Change eslint-disable comments to use the new rules
W-A-James Feb 6, 2023
b310a72
style(NODE-4976): Add comments to eslint-disable
W-A-James Feb 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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