Skip to content

Commit

Permalink
Use dev Node to check for unsupported Node builtins in tests (#5158)
Browse files Browse the repository at this point in the history
The `n/no-unsupported-features/es-builtins`,
`n/no-unsupported-features/es-syntax`, and
`n/no-unsupported-features/node-builtins` ESLint rules ensure that
production code is not using features of JavaScript that are unsupported
by the expected version of Node. It does this by keeping track of which
versions various features will become generally available and failing if
the version of Node it sees does not match.

By default, this rule uses `engines.node` to know which is the "expected
version of Node". While that is fine for production code, we use a later
version of Node — which is set to the current LTS version — for tests,
and therefore we may be allowed to use features that were once
experimental in previous versions.

To fix this, this commit overrides the three
`n/no-unsupported-features/*` rules to use the current LTS of Node for
tests.
  • Loading branch information
mcmire authored Jan 16, 2025
1 parent 21c4ec6 commit 9f36688
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eslint-warning-thresholds.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"jsdoc/check-tag-names": 375,
"jsdoc/require-returns": 22,
"jsdoc/tag-lines": 328,
"n/no-unsupported-features/node-builtins": 18,
"n/no-unsupported-features/node-builtins": 4,
"n/prefer-global/text-encoder": 4,
"n/prefer-global/text-decoder": 4,
"prettier/prettier": 115,
Expand Down
7 changes: 7 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import jest from '@metamask/eslint-config-jest';
import nodejs from '@metamask/eslint-config-nodejs';
import typescript from '@metamask/eslint-config-typescript';

const NODE_LTS_VERSION = 22;

const config = createConfig([
...base,
{
Expand Down Expand Up @@ -83,6 +85,11 @@ const config = createConfig([
'jest/prefer-lowercase-title': 'warn',
'jest/prefer-strict-equal': 'warn',
},
settings: {
node: {
version: `^${NODE_LTS_VERSION}`,
},
},
},
{
// These files are test helpers, not tests. We still use the Jest ESLint
Expand Down

0 comments on commit 9f36688

Please sign in to comment.