feat(json_analyze): implement noEmptyObjectKeys#9365
Conversation
🦋 Changeset detectedLatest commit: 71a10da The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
crates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/invalid.json
Outdated
Show resolved
Hide resolved
Merging this PR will not alter performance
Comparing Footnotes
|
0d4df75 to
c437733
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (6)
📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a new JSON lint rule Suggested reviewers
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
NoEmptyObjectKeysOptionswould 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
⛔ Files ignored due to path filters (7)
crates/biome_cli/src/execute/migrate/eslint_any_rule_to_biome.rsis excluded by!**/migrate/eslint_any_rule_to_biome.rsand included by**crates/biome_configuration/src/analyzer/linter/rules.rsis excluded by!**/rules.rsand included by**crates/biome_diagnostics_categories/src/categories.rsis excluded by!**/categories.rsand included by**crates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/invalid.json.snapis excluded by!**/*.snapand included by**crates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/valid.json.snapis excluded by!**/*.snapand included by**packages/@biomejs/backend-jsonrpc/src/workspace.tsis excluded by!**/backend-jsonrpc/src/workspace.tsand included by**packages/@biomejs/biome/configuration_schema.jsonis excluded by!**/configuration_schema.jsonand included by**
📒 Files selected for processing (6)
.changeset/wild-dolls-talk.mdcrates/biome_json_analyze/src/lint/nursery/no_empty_object_keys.rscrates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/invalid.jsoncrates/biome_json_analyze/tests/specs/nursery/noEmptyObjectKeys/valid.jsoncrates/biome_rule_options/src/lib.rscrates/biome_rule_options/src/no_empty_object_keys.rs
.changeset/wild-dolls-talk.md
Outdated
| "@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. |
There was a problem hiding this comment.
nit: 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 the use of empty keys in JSON objects. |
crates/biome_json_analyze/src/lint/nursery/no_empty_object_keys.rs
Outdated
Show resolved
Hide resolved
| 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", ""); |
There was a problem hiding this comment.
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().
There was a problem hiding this comment.
Ahhh awesome, there's a utility, thanks!
Summary
Port Eslint JSON's no-empty-keys, disallowing empty keys in JSON objects.
Test Plan
Unit tests
Docs