Skip to content

feat(json_analyze): implement noEmptyObjectKeys#9365

Merged
Netail merged 4 commits intobiomejs:mainfrom
Netail:feat/no-empty-object-keys
Mar 7, 2026
Merged

feat(json_analyze): implement noEmptyObjectKeys#9365
Netail merged 4 commits intobiomejs:mainfrom
Netail:feat/no-empty-object-keys

Conversation

@Netail
Copy link
Member

@Netail Netail commented Mar 6, 2026

Summary

Port Eslint JSON's no-empty-keys, disallowing empty keys in JSON objects.

Test Plan

Unit tests

Docs

@changeset-bot
Copy link

changeset-bot bot commented Mar 6, 2026

🦋 Changeset detected

Latest commit: 71a10da

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-CLI Area: CLI A-Project Area: project A-Linter Area: linter L-JSON Language: JSON and super languages A-Diagnostic Area: diagnostocis labels Mar 6, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 6, 2026

Merging this PR will not alter performance

✅ 58 untouched benchmarks
⏩ 156 skipped benchmarks1


Comparing Netail:feat/no-empty-object-keys (71a10da) with main (701ddd3)

Open in CodSpeed

Footnotes

  1. 156 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Netail Netail force-pushed the feat/no-empty-object-keys branch from 0d4df75 to c437733 Compare March 6, 2026 18:13
@Netail Netail marked this pull request as ready for review March 6, 2026 18:13
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 61bb275a-457b-4357-bb55-85c0e3bfaae3

📥 Commits

Reviewing files that changed from the base of the PR and between cd58c3b and 71a10da.

⛔ Files ignored due to path filters (6)
  • Cargo.lock is excluded by !**/*.lock and included by **
  • crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs is excluded by !**/migrate/eslint_any_rule_to_biome.rs and included by **
  • crates/biome_configuration/src/analyzer/linter/rules.rs is excluded by !**/rules.rs and included by **
  • crates/biome_diagnostics_categories/src/categories.rs is excluded by !**/categories.rs and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and included by **
📒 Files selected for processing (3)
  • crates/biome_json_analyze/Cargo.toml
  • crates/biome_json_analyze/src/lint/nursery/no_empty_object_keys.rs
  • crates/biome_rule_options/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/biome_rule_options/src/lib.rs

Walkthrough

Adds a new JSON lint rule noEmptyObjectKeys that flags empty or whitespace-only object keys. Implements the rule in the nursery lints, emits diagnostics with a message and note, and reads/unescapes JSON member names to detect emptiness. Introduces NoEmptyObjectKeysOptions (unit-like) and exports it, registers the rule in tests with new valid/invalid fixtures, and adds a patch changeset entry. Also adds a workspace dependency and exposes the new options module. No existing public declarations were removed or otherwise modified.

Suggested reviewers

  • dyc3
  • ematipico
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: implementing a new lint rule noEmptyObjectKeys for JSON analysis.
Description check ✅ Passed The description provides relevant context about the change, referencing the ESLint rule being ported and mentioning unit tests as part of the implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link
Contributor

@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

🧹 Nitpick comments (3)
crates/biome_json_analyze/src/lint/nursery/no_empty_object_keys.rs (1)

92-97: Diagnostic text could mention whitespace-only keys explicitly.

The current message says “empty” only; this rule also targets whitespace-only keys, so a tiny wording tweak would be clearer.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_json_analyze/src/lint/nursery/no_empty_object_keys.rs` around
lines 92 - 97, Update the diagnostic text in no_empty_object_keys.rs so it
explicitly mentions whitespace-only keys in addition to empty keys: replace the
message string "Unexpected empty object key." and adjust the note to say
something like "Empty or whitespace-only keys..." so users know the rule targets
keys that are only whitespace; locate the diagnostic construction where that
message string is used and update both the main message and the note text
accordingly.
crates/biome_rule_options/src/no_empty_object_keys.rs (1)

6-6: Add a brief rustdoc line for the options type.

A one-liner doc comment on NoEmptyObjectKeysOptions would align this with rule/options documentation conventions.

Suggested patch
 #[serde(rename_all = "camelCase", deny_unknown_fields, default)]
+/// Options for the `noEmptyObjectKeys` JSON lint rule.
 pub struct NoEmptyObjectKeysOptions {}

As per coding guidelines, rules and their options should use inline rustdoc documentation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/biome_rule_options/src/no_empty_object_keys.rs` at line 6, Add a
one-line rustdoc comment above the NoEmptyObjectKeysOptions struct to document
its purpose (e.g., "Options for the `no-empty-object-keys` rule.") so the type
follows rule/options documentation conventions; locate the struct named
NoEmptyObjectKeysOptions and insert a /// rustdoc line directly above it
summarizing the options in one short sentence.
.changeset/wild-dolls-talk.md (1)

5-5: Tiny wording polish for the release note.

The second sentence reads as a fragment; consider tightening it into one end-user-facing sentence.

Suggested wording
-Added the nursery rule [`noEmptyObjectKeys`](https://biomejs.dev/linter/rules/no-empty-object-keys/). Disallowing the use of empty keys in JSON objects.
+Added the nursery rule [`noEmptyObjectKeys`](https://biomejs.dev/linter/rules/no-empty-object-keys/), which disallows empty keys in JSON objects.

As per coding guidelines, changeset descriptions should be end-user focused and concise (1–3 sentences).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.changeset/wild-dolls-talk.md at line 5, The changeset's second sentence is
a fragment; update the description in .changeset/wild-dolls-talk.md to a single
concise end-user-facing sentence (1–3 sentences total) that mentions the new
nursery rule noEmptyObjectKeys and what it does, e.g. "Added the nursery rule
noEmptyObjectKeys to disallow empty keys in JSON objects." Ensure the wording is
tight and user-focused.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/biome_json_analyze/src/lint/nursery/no_empty_object_keys.rs`:
- Around line 74-79: The condition in run (in no_empty_object_keys.rs) only
treats trimmed_value of "\\t" and "\\n" as empty escapes; extend the check to
also consider "\\r" and "\\f" so keys that are literal backslash-r or
backslash-f are flagged. Update the if that currently checks trimmed_value ==
"\\t" || trimmed_value == "\\n" to also include trimmed_value == "\\r" ||
trimmed_value == "\\f" (keeping the existing trimmed_value.is_empty() check),
ensuring the rule's returned Some(()) triggers for those escapes as well.

---

Nitpick comments:
In @.changeset/wild-dolls-talk.md:
- Line 5: The changeset's second sentence is a fragment; update the description
in .changeset/wild-dolls-talk.md to a single concise end-user-facing sentence
(1–3 sentences total) that mentions the new nursery rule noEmptyObjectKeys and
what it does, e.g. "Added the nursery rule noEmptyObjectKeys to disallow empty
keys in JSON objects." Ensure the wording is tight and user-focused.

In `@crates/biome_json_analyze/src/lint/nursery/no_empty_object_keys.rs`:
- Around line 92-97: Update the diagnostic text in no_empty_object_keys.rs so it
explicitly mentions whitespace-only keys in addition to empty keys: replace the
message string "Unexpected empty object key." and adjust the note to say
something like "Empty or whitespace-only keys..." so users know the rule targets
keys that are only whitespace; locate the diagnostic construction where that
message string is used and update both the main message and the note text
accordingly.

In `@crates/biome_rule_options/src/no_empty_object_keys.rs`:
- Line 6: Add a one-line rustdoc comment above the NoEmptyObjectKeysOptions
struct to document its purpose (e.g., "Options for the `no-empty-object-keys`
rule.") so the type follows rule/options documentation conventions; locate the
struct named NoEmptyObjectKeysOptions and insert a /// rustdoc line directly
above it summarizing the options in one short sentence.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9e447f40-c73b-42ce-9451-d9b0635fc2c9

📥 Commits

Reviewing files that changed from the base of the PR and between bc5dd99 and c437733.

⛔ Files ignored due to path filters (7)
  • crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rs is excluded by !**/migrate/eslint_any_rule_to_biome.rs and included by **
  • crates/biome_configuration/src/analyzer/linter/rules.rs is excluded by !**/rules.rs and included by **
  • crates/biome_diagnostics_categories/src/categories.rs is excluded by !**/categories.rs and included by **
  • crates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/invalid.json.snap is excluded by !**/*.snap and included by **
  • crates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/valid.json.snap is excluded by !**/*.snap and included by **
  • packages/@biomejs/backend-jsonrpc/src/workspace.ts is excluded by !**/backend-jsonrpc/src/workspace.ts and included by **
  • packages/@biomejs/biome/configuration_schema.json is excluded by !**/configuration_schema.json and included by **
📒 Files selected for processing (6)
  • .changeset/wild-dolls-talk.md
  • crates/biome_json_analyze/src/lint/nursery/no_empty_object_keys.rs
  • crates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/invalid.json
  • crates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/valid.json
  • crates/biome_rule_options/src/lib.rs
  • crates/biome_rule_options/src/no_empty_object_keys.rs

"@biomejs/biome": patch
---

Added the nursery rule [`noEmptyObjectKeys`](https://biomejs.dev/linter/rules/no-empty-object-keys/). Disallowing the use of empty keys in JSON objects.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: wording

Suggested change
Added the nursery rule [`noEmptyObjectKeys`](https://biomejs.dev/linter/rules/no-empty-object-keys/). Disallowing the use of empty keys in JSON objects.
Added the nursery rule [`noEmptyObjectKeys`](https://biomejs.dev/linter/rules/no-empty-object-keys/), which disallows the use of empty keys in JSON objects.

@Netail Netail requested a review from dyc3 March 6, 2026 20:40
let value = node.inner_string_text().ok()?;
let trimmed_value = value.trim();
if trimmed_value.is_empty() || trimmed_value == "\\t" || trimmed_value == "\\n" {
let trimmed_value = value.trim().replace("\\n", "").replace("\\t", "");
Copy link
Contributor

Choose a reason for hiding this comment

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

.replace() allocates a string

Copy link
Member

@Conaclos Conaclos Mar 6, 2026

Choose a reason for hiding this comment

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

To avoid allocation in most of the cases, you could use a simplified version of biome_deserialize::json::unescape_json_string.
First unescape, then apply trim().

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahhh awesome, there's a utility, thanks!

@Netail Netail requested review from Conaclos and dyc3 March 7, 2026 00:21
@Netail Netail merged commit 776cb64 into biomejs:main Mar 7, 2026
35 checks passed
@Netail Netail deleted the feat/no-empty-object-keys branch March 7, 2026 12:20
@github-actions github-actions bot mentioned this pull request Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JSON Language: JSON and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants