fix: ignore None flags on serialization of bitfields#11563
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
📝 WalkthroughWalkthroughIn both BitField zero-value flag filtering
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/structures/src/bitfields/BitField.ts`:
- Around line 177-179: The iterator guard in BitField’s flag iteration is using
the wrong condition, so zero-valued flags like None are not being filtered out.
Update the logic inside BitField’s iterator (the loop over
this.constructor.Flags) so the zero-value check is applied directly to the flag
value before calling this.has(...), and only yield flags whose numeric/bigint
value is greater than zero. Make sure the fix preserves the existing hasParams
behavior and prevents toArray() from emitting zero-bit flags.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: cf1caa20-2c5a-44f9-be37-e8a0eea9c905
📒 Files selected for processing (2)
packages/discord.js/src/util/BitField.jspackages/structures/src/bitfields/BitField.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
- GitHub Check: Tests
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-03-30T11:04:39.419Z
Learnt from: almeidx
Repo: discordjs/discord.js PR: 11471
File: packages/discord.js/src/util/Util.js:83-86
Timestamp: 2026-03-30T11:04:39.419Z
Learning: For the discord.js and rest packages, follow the existing convention for constructing request URLs: use the `api` base URL and `version` string via raw interpolation (e.g., `${api}/v${version}${route}`) without adding normalization such as trimming trailing slashes on `api` or stripping/adding/remapping a leading `v` on `version`. Do not recommend changing this behavior during code review unless the existing pattern in this repo is intentionally being replaced.
Applied to files:
packages/discord.js/src/util/BitField.js
📚 Learning: 2026-05-18T13:40:11.014Z
Learnt from: almeidx
Repo: discordjs/discord.js PR: 11530
File: packages/core/src/api/user.ts:190-190
Timestamp: 2026-05-18T13:40:11.014Z
Learning: When reviewing discord.js (and related) source files, JSDoc `see` links that point to Discord’s documentation on `https://docs.discord.com/developers/...` are correct and should not be flagged as inconsistent. For new/updated links going forward, prefer `https://docs.discord.com/developers` over the legacy `https://discord.com/developers/docs` domain.
Applied to files:
packages/discord.js/src/util/BitField.jspackages/structures/src/bitfields/BitField.ts
📚 Learning: 2026-05-22T17:29:55.128Z
Learnt from: kshitijanurag
Repo: discordjs/discord.js PR: 11537
File: packages/discord.js/src/structures/Guild.js:1486-1495
Timestamp: 2026-05-22T17:29:55.128Z
Learning: When handling Discord Gateway opcode `RequestChannelInfo` (opcode name: `RequestChannelInfo` / payload gateway opcode), do not add or suggest a `nonce` field for correlating responses. This opcode’s payload supports only `guild_id` and `fields` (e.g., `fields: ["status", "voice_start_time"]`); ensure any review feedback reflects that schema and treats `nonce` as unsupported for this opcode.
Applied to files:
packages/discord.js/src/util/BitField.js
📚 Learning: 2026-01-24T21:41:15.330Z
Learnt from: Qjuh
Repo: discordjs/discord.js PR: 11393
File: packages/structures/src/bitfields/ApplicationFlagsBitField.ts:13-15
Timestamp: 2026-01-24T21:41:15.330Z
Learning: For BitField classes, preserve numeric flags by using super.toJSON(true) when you need a numeric value. The toJSON(asNumber?: boolean) method returns a number when asNumber is true and a string otherwise, so always pass true to obtain a numeric representation for storage/comparison. This guidance applies to similar bitfield classes across the codebase (not just ApplicationFlagsBitField).
Applied to files:
packages/structures/src/bitfields/BitField.ts
📚 Learning: 2026-05-18T13:40:11.014Z
Learnt from: almeidx
Repo: discordjs/discord.js PR: 11530
File: packages/core/src/api/user.ts:190-190
Timestamp: 2026-05-18T13:40:11.014Z
Learning: When reviewing JSDoc comments in the discord.js monorepo (e.g., discord.js and related packages), treat `see` links to Discord developer docs as consistent with the new documentation domain. Prefer `https://docs.discord.com/developers/...` over `https://discord.com/developers...`, and do not flag `see` links that already use `https://docs.discord.com/developers/...` as inconsistent.
Applied to files:
packages/structures/src/bitfields/BitField.ts
🔇 Additional comments (2)
packages/discord.js/src/util/BitField.js (1)
134-134: LGTM!Also applies to: 159-160
packages/structures/src/bitfields/BitField.ts (1)
141-142: LGTM!
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11563 +/- ##
==========================================
- Coverage 31.90% 31.89% -0.01%
==========================================
Files 390 390
Lines 14067 14069 +2
Branches 1107 1107
==========================================
Hits 4488 4488
- Misses 9441 9443 +2
Partials 138 138
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| const serialized: Partial<Record<keyof Flags, boolean>> = {}; | ||
| for (const [flag, bit] of Object.entries(this.constructor.Flags)) { | ||
| if (Number.isNaN(Number(flag))) serialized[flag as keyof Flags] = this.has(bit as bigint | number, ...hasParams); | ||
| if (Number.isNaN(Number(flag)) && (bit as bigint | number) > 0) |
There was a problem hiding this comment.
this will not work if bit is bigint. You'll need to either convert to number or bigint and do the check
There was a problem hiding this comment.
Makes
discord.jsmainlib and@discordjs/structuresrobust for the change in discordjs/discord-api-types#1705