Skip to content

feat: enforce ECMAScript-only globals in test files via ESLint#30

Merged
legendecas merged 2 commits intonodejs:mainfrom
kraenhansen:feat/eslint-ecmascript-globals
Mar 14, 2026
Merged

feat: enforce ECMAScript-only globals in test files via ESLint#30
legendecas merged 2 commits intonodejs:mainfrom
kraenhansen:feat/eslint-ecmascript-globals

Conversation

@kraenhansen
Copy link
Contributor

@kraenhansen kraenhansen commented Mar 7, 2026

Summary

  • Adds an allowlist-based ESLint config using globals.es2025 plus the CTS harness globals (assert, loadAddon, mustCall, mustNotCall, gcUntil, experimentalFeatures)
  • Enables no-undef rule so any runtime-specific API (setTimeout, process, Buffer, etc.) triggers a lint error in tests/**/*.js
  • Adds no-restricted-syntax rule to ban globalThis.* and global.* property access in test files, ensuring tests use CTS harness globals (e.g. gcUntil) instead of globalThis.gc()
  • Replaces the previous denylist approach (no-restricted-globals for require) with a stricter allowlist

This ensures CTS test files only use ECMAScript language features and harness-provided globals, making them portable across Node-API runtimes.

Test plan

  • npx eslint tests/ passes with no errors
  • Verified that setTimeout in a test file triggers 'setTimeout' is not defined error
  • Verified that globalThis.gc() in a test file triggers no-restricted-syntax error

🤖 Generated with Claude Code

Add an allowlist-based ESLint config using globals.es2025 plus the CTS
harness globals (assert, loadAddon, mustCall, mustNotCall, gcUntil).
Any runtime-specific API (setTimeout, process, Buffer, etc.) now triggers
a no-undef error in tests/**/*.js files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ests

- Add experimentalFeatures to the allowed CTS harness globals
- Add no-restricted-syntax rule to flag globalThis.* and global.* access,
  ensuring tests use CTS harness globals (e.g. gcUntil) instead

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Member

@legendecas legendecas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When looking at #31, I was also thinking the same about adding a linter rule for globals. Thanks!

@legendecas legendecas merged commit 5427ce8 into nodejs:main Mar 14, 2026
13 checks passed
@github-project-automation github-project-automation bot moved this from Has PR to Done in Node-API Team Project Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants