diff --git a/eslint.config.js b/eslint.config.js index 65fa512..fff73c6 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,17 +1,33 @@ import { defineConfig, globalIgnores } from "eslint/config"; +import globals from "globals"; export default defineConfig([ globalIgnores(["node"]), { files: ["tests/**/*.js"], + languageOptions: { + // Only allow ECMAScript built-ins and CTS harness globals. + // This causes no-undef to flag any runtime-specific API (setTimeout, process, Buffer, etc.). + globals: { + ...globals.es2025, + // CTS harness globals + assert: "readonly", + loadAddon: "readonly", + mustCall: "readonly", + mustNotCall: "readonly", + gcUntil: "readonly", + experimentalFeatures: "readonly", + }, + }, rules: { - // Test files are expected to be self-contained + "no-undef": "error", "no-restricted-imports": ["error", { patterns: ["*"], }], - "no-restricted-globals": ["error", - { name: "require", message: "Test files are expected to be self-contained" } - ] + "no-restricted-syntax": ["error", + { selector: "MemberExpression[object.name='globalThis']", message: "Avoid globalThis access in test files — use CTS harness globals instead" }, + { selector: "MemberExpression[object.name='global']", message: "Avoid global access in test files — use CTS harness globals instead" } + ], }, }, ]); diff --git a/package-lock.json b/package-lock.json index d8ec84f..2f8e71a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "devDependencies": { "@types/node": "^24.10.1", "eslint": "^9.39.1", + "globals": "^17.4.0", "node-api-headers": "^1.7.0" } }, @@ -123,6 +124,19 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/@eslint/eslintrc/node_modules/globals": { + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@eslint/eslintrc/node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -688,9 +702,9 @@ } }, "node_modules/globals": { - "version": "14.0.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", - "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", + "version": "17.4.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-17.4.0.tgz", + "integrity": "sha512-hjrNztw/VajQwOLsMNT1cbJiH2muO3OROCHnbehc8eY5JyD2gqz4AcMHPqgaOR59DjgUjYAYLeH699g/eWi2jw==", "dev": true, "license": "MIT", "engines": { diff --git a/package.json b/package.json index 1590d7b..0288ad9 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "devDependencies": { "@types/node": "^24.10.1", "eslint": "^9.39.1", + "globals": "^17.4.0", "node-api-headers": "^1.7.0" }, "dependencies": {