Skip to content

Conversation

@didinele
Copy link
Member

@didinele didinele commented Nov 17, 2025

should I have ignored api-extractor?

Closes #11272

@vercel
Copy link

vercel bot commented Nov 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
discord-js Ignored Ignored Preview Dec 10, 2025 0:57am
discord-js-guide Ignored Ignored Preview Dec 10, 2025 0:57am

@didinele
Copy link
Member Author

didinele commented Dec 8, 2025

Additionally, I found some other globals which are still being imported while skimming over: File, Blob, and performance.

Unfortunately, there's no ESLint rules for those. Even so

  • I could not find any instances of File being imported. Maybe my search was improper?
  • Blob in only imported within REST once for undici request, removing it poses the following problem:
Argument of type 'Blob' is not assignable to parameter of type 'BodyInit | undefined'.
  Property 'slice' is missing in type 'Blob' but required in type 'import("buffer").Blob'.

where BodyInit is a type referenced from undici. Probably for the best we keep that import

  • performance

@coderabbitai
Copy link

coderabbitai bot commented Dec 10, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This PR removes explicit imports of Node.js global APIs across the monorepo in favor of using global availability, aligning with the goal to remove n/prefer-global ESLint rules for runtime compatibility. Changes include updating the root ESLint configuration with new rule definitions, removing imports of global APIs (URL, URLSearchParams, timers, TextDecoder, process in specific contexts), and adjusting imports to use explicit process where needed.

Changes

Cohort / File(s) Summary
ESLint Configuration Updates
eslint.config.js, packages/create-discord-bot/template/{JavaScript,TypeScript}/eslint.config.js
Introduced nodeBinRuleset for bin script files with shebang rule disabled. Expanded nodeRuleset with explicit rules for n/prefer-global preferences and no-restricted-globals. Added identical rule overrides to both template eslint.config files.
URL Import Removals
packages/api-extractor-model/src/model/SourceLocation.ts, packages/create-discord-bot/scripts/rename-to-app.mjs, packages/create-discord-bot/src/create-discord-bot.ts, packages/create-discord-bot/template/{JavaScript,TypeScript}/src/*, packages/discord.js/scripts/{esmDts,generateRequires}.mjs, packages/proxy/src/handlers/proxyRequests.ts, packages/rest/src/strategies/undiciRequest.ts
Removed explicit imports of URL from 'node:url'; code now relies on global URL constructor without import statements.
URLSearchParams Import Removals
packages/rest/__tests__/{DiscordAPIError,REST,UndiciRequest}.test.ts, packages/ws/src/ws/WebSocketShard.ts
Removed explicit imports of URLSearchParams from 'node:url'; code now relies on global availability.
Timer Imports Removed
packages/actions/src/releasePackages/releasePackage.ts, packages/brokers/src/brokers/redis/RPCRedis.ts, packages/core/src/client.ts, packages/rest/__tests__/RequestHandler.test.ts, packages/ws/src/ws/WebSocketShard.ts
Removed explicit imports of timer utilities (setInterval, clearInterval, setTimeout, clearTimeout) from 'node:timers'; code now relies on global implementations.
Process Import Refactoring
packages/api-extractor/src/cli/RunAction.ts, packages/api-extractor/src/start.ts, packages/docgen/bin/index.ts
Updated process imports: RunAction.ts added explicit default process import, start.ts changed from namespace to default import, docgen added explicit process import.
Process.cwd() Usage Changes
packages/scripts/src/{generateIndex,generateSplitDocumentation}.ts, packages/scripts/src/populateDevDatabaseBranch.ts
Replaced named cwd import with default process import; updated all cwd() calls to process.cwd() for working directory resolution.
Voice/AudioReceiveStream nextTick Refactoring
packages/voice/src/receive/AudioReceiveStream.ts
Changed from named nextTick import to default process import; updated nextTick() calls to process.nextTick().
Buffer Import Changes
packages/rest/src/lib/utils/utils.ts, packages/rest/src/strategies/undiciRequest.ts, packages/voice/__tests__/Secretbox.test.ts
Added or adjusted Buffer imports from 'node:buffer'; utils.ts uses type-only import, undiciRequest.ts added runtime import.
ESLint Directive Updates
packages/create-discord-bot/bin/index.ts, packages/docgen/bin/index.ts, packages/scripts/bin/generateSplitDocumentation.ts
Removed or updated ESLint shebang suppression comments; generateSplitDocumentation.ts also refactored async functions to concise arrow form.
Misc Import Removals & Cleanup
packages/core/src/api/oauth2.ts, packages/formatters/__tests__/formatters.test.ts, packages/formatters/src/formatters.ts, packages/rest/__tests__/{BurstHandler,UndiciRequest}.test.ts, packages/rest/src/lib/handlers/Shared.ts, packages/ws/__tests__/strategy/WorkerShardingStrategy.test.ts
Removed explicit imports of performance, TextDecoder, or ESLint directives; added file-level ESLint disable comments where needed.
Package-Specific Rule Removals
packages/rest/**/*${commonFiles}, packages/voice/**/*${commonFiles} (via eslint.config.js)
Removed package-level ESLint rule overrides (n/prefer-global/url, n/prefer-global/url-search-params, n/prefer-global/buffer, n/prefer-global/process, no-restricted-globals) to align with global rule definitions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~40 minutes

Areas requiring extra attention:

  • ESLint configuration validation: Verify that the new nodeBinRuleset correctly targets bin scripts and that the expanded nodeRuleset rule definitions align across root and template configurations
  • Global API availability: Confirm that all environments where these files run support the global APIs being relied upon (URL, URLSearchParams, timers, Buffer, etc.)
  • Process.cwd() refactoring: Verify the three script files using process.cwd() instead of the cwd() function maintain correct working directory resolution in all execution contexts
  • Buffer type vs. runtime imports: Confirm that packages/rest/src/lib/utils/utils.ts using a type-only Buffer import doesn't cause runtime issues, and packages/rest/src/strategies/undiciRequest.ts adding a runtime Buffer import is appropriate
  • Shebang rule handling: Validate that removing ESLint shebang suppression comments from bin files works correctly with the new nodeBinRuleset configuration

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'chore: remove usage of the prefer-global rules' directly and specifically describes the main objective of the changeset.
Description check ✅ Passed The description relates to the changeset by referencing issue #11272, which is about removing prefer-global rule usages for runtime compatibility.
Linked Issues check ✅ Passed The PR successfully addresses issue #11272 by removing n/prefer-global rule usages across the monorepo and eliminating explicit imports of global Node.js APIs throughout multiple packages.
Out of Scope Changes check ✅ Passed All changes align with the stated objective of removing prefer-global rule usages; however, some files contain related but technically distinct modifications (e.g., eslint config updates, import style refactorings).

Comment @coderabbitai help to get the list of available commands and usage tips.

@didinele didinele requested a review from almeidx December 10, 2025 12:35
@didinele didinele force-pushed the chore/no-prefer-global branch 2 times, most recently from 88a08f2 to 3451711 Compare December 10, 2025 12:41
@didinele
Copy link
Member Author

didinele commented Dec 10, 2025

@coderabbitai review

@didinele didinele force-pushed the chore/no-prefer-global branch from 3451711 to e1032a8 Compare December 10, 2025 12:43
@coderabbitai
Copy link

coderabbitai bot commented Dec 10, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/docgen/bin/index.ts (1)

1-27: Missing explicit import of process.

Line 24 uses process.argv without an explicit import. While process is a global in Node.js, add the import statement: import process from 'node:process' near the top of the file with the other imports.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb7c0e9 and e1032a8.

📒 Files selected for processing (42)
  • eslint.config.js (2 hunks)
  • packages/actions/src/releasePackages/releasePackage.ts (0 hunks)
  • packages/api-extractor-model/src/model/SourceLocation.ts (0 hunks)
  • packages/api-extractor/src/cli/RunAction.ts (1 hunks)
  • packages/api-extractor/src/start.ts (1 hunks)
  • packages/brokers/src/brokers/redis/RPCRedis.ts (0 hunks)
  • packages/core/src/api/oauth2.ts (0 hunks)
  • packages/core/src/client.ts (0 hunks)
  • packages/create-discord-bot/bin/index.ts (0 hunks)
  • packages/create-discord-bot/scripts/rename-to-app.mjs (0 hunks)
  • packages/create-discord-bot/src/create-discord-bot.ts (0 hunks)
  • packages/create-discord-bot/template/JavaScript/eslint.config.js (1 hunks)
  • packages/create-discord-bot/template/JavaScript/src/events/interactionCreate.js (0 hunks)
  • packages/create-discord-bot/template/JavaScript/src/index.js (0 hunks)
  • packages/create-discord-bot/template/JavaScript/src/util/deploy.js (0 hunks)
  • packages/create-discord-bot/template/JavaScript/src/util/loaders.js (1 hunks)
  • packages/create-discord-bot/template/TypeScript/eslint.config.js (1 hunks)
  • packages/create-discord-bot/template/TypeScript/src/events/interactionCreate.ts (0 hunks)
  • packages/create-discord-bot/template/TypeScript/src/index.ts (0 hunks)
  • packages/create-discord-bot/template/TypeScript/src/util/deploy.ts (0 hunks)
  • packages/discord.js/scripts/esmDts.mjs (0 hunks)
  • packages/discord.js/scripts/generateRequires.mjs (0 hunks)
  • packages/docgen/bin/index.ts (1 hunks)
  • packages/formatters/__tests__/formatters.test.ts (0 hunks)
  • packages/formatters/src/formatters.ts (0 hunks)
  • packages/proxy/src/handlers/proxyRequests.ts (0 hunks)
  • packages/rest/__tests__/BurstHandler.test.ts (0 hunks)
  • packages/rest/__tests__/DiscordAPIError.test.ts (0 hunks)
  • packages/rest/__tests__/REST.test.ts (1 hunks)
  • packages/rest/__tests__/RequestHandler.test.ts (0 hunks)
  • packages/rest/__tests__/UndiciRequest.test.ts (0 hunks)
  • packages/rest/src/lib/handlers/Shared.ts (1 hunks)
  • packages/rest/src/lib/utils/utils.ts (1 hunks)
  • packages/rest/src/strategies/undiciRequest.ts (1 hunks)
  • packages/scripts/bin/generateSplitDocumentation.ts (2 hunks)
  • packages/scripts/src/generateIndex.ts (2 hunks)
  • packages/scripts/src/generateSplitDocumentation.ts (2 hunks)
  • packages/scripts/src/populateDevDatabaseBranch.ts (2 hunks)
  • packages/voice/__tests__/Secretbox.test.ts (1 hunks)
  • packages/voice/src/receive/AudioReceiveStream.ts (2 hunks)
  • packages/ws/__tests__/strategy/WorkerShardingStrategy.test.ts (0 hunks)
  • packages/ws/src/ws/WebSocketShard.ts (0 hunks)
💤 Files with no reviewable changes (25)
  • packages/rest/tests/UndiciRequest.test.ts
  • packages/create-discord-bot/template/TypeScript/src/util/deploy.ts
  • packages/rest/tests/BurstHandler.test.ts
  • packages/create-discord-bot/template/TypeScript/src/index.ts
  • packages/core/src/api/oauth2.ts
  • packages/brokers/src/brokers/redis/RPCRedis.ts
  • packages/api-extractor-model/src/model/SourceLocation.ts
  • packages/rest/tests/RequestHandler.test.ts
  • packages/discord.js/scripts/esmDts.mjs
  • packages/create-discord-bot/scripts/rename-to-app.mjs
  • packages/create-discord-bot/bin/index.ts
  • packages/create-discord-bot/template/JavaScript/src/util/deploy.js
  • packages/create-discord-bot/src/create-discord-bot.ts
  • packages/core/src/client.ts
  • packages/ws/tests/strategy/WorkerShardingStrategy.test.ts
  • packages/actions/src/releasePackages/releasePackage.ts
  • packages/proxy/src/handlers/proxyRequests.ts
  • packages/discord.js/scripts/generateRequires.mjs
  • packages/rest/tests/DiscordAPIError.test.ts
  • packages/create-discord-bot/template/TypeScript/src/events/interactionCreate.ts
  • packages/create-discord-bot/template/JavaScript/src/events/interactionCreate.js
  • packages/ws/src/ws/WebSocketShard.ts
  • packages/formatters/tests/formatters.test.ts
  • packages/formatters/src/formatters.ts
  • packages/create-discord-bot/template/JavaScript/src/index.js
🧰 Additional context used
🧬 Code graph analysis (2)
packages/voice/src/receive/AudioReceiveStream.ts (4)
packages/discord.js/src/client/Client.js (1)
  • process (3-3)
packages/discord.js/src/managers/RoleManager.js (1)
  • process (3-3)
packages/discord.js/src/managers/GuildManager.js (1)
  • process (3-3)
packages/discord.js/src/managers/GuildChannelManager.js (1)
  • process (3-3)
eslint.config.js (2)
packages/collection/src/collection.ts (1)
  • merge (994-1022)
packages/api-extractor-utils/src/tsdoc/CommentNode.ts (1)
  • node (24-28)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Tests
🔇 Additional comments (24)
packages/voice/__tests__/Secretbox.test.ts (1)

1-1: Explicit Buffer import aligns with non-global usage goal

Importing Buffer from 'node:buffer' is correct and keeps the test from depending on a global Buffer, matching the PR’s objective and the way Buffer.from is used below.

packages/create-discord-bot/template/JavaScript/src/util/loaders.js (1)

3-3: Relying on global URL instead of importing it looks correct here

The change to only import fileURLToPath and use the global URL in dir instanceof URL keeps behavior the same while removing an unnecessary import, which aligns with the prefer‑global cleanup. Just ensure your ESLint/TypeScript configuration for this template environment treats URL as a global so you don’t get false positives.

packages/scripts/bin/generateSplitDocumentation.ts (2)

1-2: Shebang and lint directive change look good

Keeping the shebang and dropping the eslint-disable comment is fine here and doesn’t affect runtime behavior.


23-25: Arrow function refactor is behavior‑preserving

Converting these async callbacks to concise expression bodies keeps the same return values and types; no issues from this change.

packages/rest/src/lib/handlers/Shared.ts (2)

1-2: ESLint disable is appropriate for cross-environment compatibility.

The file-level disable is necessary because this code uses globalThis.process with runtime checks (lines 188-189) to safely call process.emitWarning() only when running in Node.js environments. The n/prefer-global/process rule would typically prefer direct process usage, but that would throw errors in browser/edge runtimes where process is undefined.

The defensive pattern typeof globalThis.process !== 'undefined' is the correct approach for libraries that need to run across multiple environments.


188-189: LGTM! Proper defensive check for cross-environment compatibility.

The runtime check for process availability before calling emitWarning() is the correct pattern for code that runs in multiple environments (Node.js, browser, edge). The fallback to console.warn() on line 191 ensures the warning is always emitted appropriately.

packages/rest/src/lib/utils/utils.ts (1)

1-1: Type-only Buffer import correctly matches isBufferLike usage (LGTM).

Buffer is only used in the type predicate of isBufferLike, and the runtime check already relies on instanceof Uint8Array/Uint8ClampedArray/ArrayBuffer, which covers Node Buffer instances via Uint8Array. Importing Buffer as a type from 'node:buffer' keeps runtime behavior unchanged while avoiding reliance on a global type, which fits the PR’s goals.

Please re-run the REST package type-check/tests to confirm there are no unexpected diagnostics around Buffer usage after this change.

Also applies to: 149-151

packages/rest/__tests__/REST.test.ts (1)

1-1: LGTM: Explicit Buffer import added.

The explicit import of Buffer from node:buffer is appropriate here, as the file uses Buffer.from() at line 280.

packages/rest/src/strategies/undiciRequest.ts (2)

1-1: LGTM: Explicit Buffer import added.

The explicit import of Buffer from node:buffer is correct for the Buffer.concat() usage at lines 73 and 81.


60-61: LGTM: Global URLSearchParams usage.

The code correctly relies on the global URLSearchParams, which is available in Node.js 10+ and matches the PR's objective to use global implementations where appropriate.

packages/api-extractor/src/cli/RunAction.ts (1)

6-6: LGTM: Explicit process import added.

The explicit import of process from node:process is appropriate for the usages at lines 136 (process.cwd()) and 154 (process.exitCode).

packages/api-extractor/src/start.ts (1)

5-5: LGTM: Import style updated to default import.

The change from namespace import to default import (import process from 'node:process') is consistent with the import style used in other files in this PR and correctly supports the usage at line 19.

packages/scripts/src/generateSplitDocumentation.ts (2)

3-3: LGTM: Consistent with script file pattern.

The change from import { cwd } to import process and using process.cwd() is consistent with the pattern applied across other script files (generateIndex.ts, populateDevDatabaseBranch.ts) in this PR.


1004-1011: LGTM: All cwd() usages updated correctly.

All three usages of path construction have been correctly updated to use process.cwd() instead of the previously imported cwd() function.

packages/scripts/src/generateIndex.ts (2)

3-3: LGTM: Consistent import pattern.

The change to import process from 'node:process' aligns with the pattern used across all script files in this PR.


154-160: LGTM: All path resolutions updated correctly.

All usages of path construction have been correctly updated to use process.cwd() instead of the previously imported cwd() function.

packages/scripts/src/populateDevDatabaseBranch.ts (2)

2-2: LGTM: Consistent import pattern.

The change to import process from 'node:process' is consistent with other script files and supports multiple process usages in this file (process.env, process.cwd(), process.chdir()).


8-11: LGTM: Multiple process API usages covered.

The explicit process import correctly supports process.env (line 8), process.cwd() (line 11), and process.chdir() (line 11).

packages/voice/src/receive/AudioReceiveStream.ts (2)

2-2: LGTM!

The change from a named { nextTick } import to a default process import aligns with the new 'n/prefer-global/process': [2, 'never'] rule and is consistent with patterns used elsewhere in the monorepo (e.g., packages/discord.js/src/client/Client.js).


82-82: LGTM!

Updated call site correctly uses process.nextTick() to match the import change.

packages/create-discord-bot/template/JavaScript/eslint.config.js (1)

14-21: LGTM!

The added rules mirror those in the root eslint.config.js nodeRuleset, ensuring template-generated projects follow the same global/import conventions as the monorepo. The rule choices are consistent: buffer and process require explicit imports for runtime compatibility, while others like URL, URLSearchParams, TextEncoder, and TextDecoder use globals.

packages/create-discord-bot/template/TypeScript/eslint.config.js (1)

21-28: LGTM!

Rules are consistent with both the JavaScript template and the root nodeRuleset, maintaining uniform linting across all project templates.

eslint.config.js (2)

20-32: LGTM!

Centralizing the global preference rules in nodeRuleset is a clean approach. The rule configuration establishes clear conventions: buffer and process require explicit imports for runtime compatibility, while console, TextDecoder, TextEncoder, URL, and URLSearchParams use globals which are available in modern Node.js environments.


115-115: LGTM!

Including nodeBinRuleset in the exported config correctly applies the shebang rule exemption to bin files.

@didinele didinele force-pushed the chore/no-prefer-global branch from e1032a8 to f10860a Compare December 10, 2025 12:57
@didinele didinele force-pushed the chore/no-prefer-global branch from f10860a to 8d78c19 Compare December 10, 2025 12:57
@didinele didinele removed the blocked label Dec 10, 2025
@github-project-automation github-project-automation bot moved this from Review in Progress to Review Approved in discord.js Dec 10, 2025
@kodiakhq kodiakhq bot merged commit 9bf1f73 into main Dec 10, 2025
28 checks passed
@kodiakhq kodiakhq bot deleted the chore/no-prefer-global branch December 10, 2025 14:05
@github-project-automation github-project-automation bot moved this from Review Approved to Done in discord.js Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Remove usage of n/prefer-global rules across the monorepo

7 participants