Skip to content

Commit

Permalink
feat(linter): make noDuplicateJsonKeys stable (#3657)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Aug 28, 2024
1 parent ca10947 commit 365fe78
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 44 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Add an `ignoreNull` option for [noDoubleEquals](https://biomejs.dev/linter/rules/no-double-equals/). Contributed by @peaBerberian.

- The rule `noDuplicateObjectKeys` now works for JSON and JSONC files. Contributed by @ematipico

#### Bug fixes

- Don't request alt text for elements hidden from assistive technologies ([#3316](https://github.com/biomejs/biome/issues/3316)). Contributed by @robintown
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/tests/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2632,8 +2632,8 @@ fn check_json_files() {
r#"{
"linter": {
"rules": {
"nursery": {
"noDuplicateJsonKeys": "error"
"suspicious": {
"noDuplicateObjectKeys": "error"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2596,8 +2596,8 @@ fn check_json_files() {
r#"{
"linter": {
"rules": {
"nursery": {
"noDuplicateJsonKeys": "error"
"suspicious": {
"noDuplicateObjectKeys": "error"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ expression: content
{
"linter": {
"rules": {
"nursery": {
"noDuplicateJsonKeys": "error"
"suspicious": {
"noDuplicateObjectKeys": "error"
}
}
}
Expand All @@ -36,7 +36,7 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
test.json:1:3 lint/nursery/noDuplicateJsonKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
test.json:1:3 lint/suspicious/noDuplicateObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× The key foo was already declared.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ expression: content
{
"linter": {
"rules": {
"nursery": {
"noDuplicateJsonKeys": "error"
"suspicious": {
"noDuplicateObjectKeys": "error"
}
}
}
Expand All @@ -36,7 +36,7 @@ lint ━━━━━━━━━━━━━━━━━━━━━━━━━
# Emitted Messages

```block
test.json:1:3 lint/nursery/noDuplicateJsonKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
test.json:1:3 lint/suspicious/noDuplicateObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× The key foo was already declared.
Expand Down
1 change: 0 additions & 1 deletion crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ define_categories! {
"lint/nursery/noDuplicateAtImportRules": "https://biomejs.dev/linter/rules/no-duplicate-at-import-rules",
"lint/nursery/noDuplicateElseIf": "https://biomejs.dev/linter/rules/no-duplicate-else-if",
"lint/nursery/noDuplicateFontNames": "https://biomejs.dev/linter/rules/no-font-family-duplicate-names",
"lint/nursery/noDuplicateJsonKeys": "https://biomejs.dev/linter/rules/no-duplicate-json-keys",
"lint/nursery/noDuplicateSelectorsKeyframeBlock": "https://biomejs.dev/linter/rules/no-duplicate-selectors-keyframe-block",
"lint/nursery/noDuplicatedFields": "https://biomejs.dev/linter/rules/no-duplicated-fields",
"lint/nursery/noDynamicNamespaceImportAccess": "https://biomejs.dev/linter/rules/no-dynamic-namespace-import-access",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::fmt::Display;
use crate::JsRuleAction;

declare_lint_rule! {
/// Prevents object literals having more than one property declaration for the same name.
/// Disallow two keys with the same name inside objects.
///
/// If an object property with the same name is defined multiple times (except when combining a getter with a setter), only the last definition makes it into the object and previous definitions are ignored, which is likely a mistake.
///
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_json_analyze/src/lint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Generated file, do not edit by hand, see `xtask/codegen`

pub mod nursery;
::biome_analyze::declare_category! { pub Lint { kind : Lint , groups : [self :: nursery :: Nursery ,] } }
pub mod suspicious;
::biome_analyze::declare_category! { pub Lint { kind : Lint , groups : [self :: suspicious :: Suspicious ,] } }
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use biome_analyze::declare_lint_group;

pub mod no_duplicate_json_keys;
pub mod no_duplicate_object_keys;

declare_lint_group! {
pub Nursery {
name : "nursery" ,
pub Suspicious {
name : "suspicious" ,
rules : [
self :: no_duplicate_json_keys :: NoDuplicateJsonKeys ,
self :: no_duplicate_object_keys :: NoDuplicateObjectKeys ,
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use biome_rowan::{AstNode, AstSeparatedList};
use rustc_hash::FxHashMap;

declare_lint_rule! {
/// Disallow two keys with the same name inside a JSON object.
/// Disallow two keys with the same name inside objects.
///
/// ## Examples
///
Expand All @@ -26,15 +26,15 @@ declare_lint_rule! {
/// "secondTitle": "Second title"
/// }
/// ```
pub NoDuplicateJsonKeys {
pub NoDuplicateObjectKeys {
version: "1.0.0",
name: "noDuplicateJsonKeys",
name: "noDuplicateObjectKeys",
language: "json",
recommended: true,
}
}

impl Rule for NoDuplicateJsonKeys {
impl Rule for NoDuplicateObjectKeys {
type Query = Ast<JsonObjectValue>;
type State = (JsonMemberName, Vec<TextRange>);
type Signals = Vec<Self::State>;
Expand Down
3 changes: 1 addition & 2 deletions crates/biome_json_analyze/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::assists;
use crate::lint;

pub type NoDuplicateJsonKeys =
<lint::nursery::no_duplicate_json_keys::NoDuplicateJsonKeys as biome_analyze::Rule>::Options;
pub type NoDuplicateObjectKeys = < lint :: suspicious :: no_duplicate_object_keys :: NoDuplicateObjectKeys as biome_analyze :: Rule > :: Options ;
pub type UseSortedKeys =
<assists::source::use_sorted_keys::UseSortedKeys as biome_analyze::Rule>::Options;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ expression: invalid.json

# Diagnostics
```
invalid.json:2:2 lint/nursery/noDuplicateJsonKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.json:2:2 lint/suspicious/noDuplicateObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The key foo was already declared.
Expand Down Expand Up @@ -63,7 +63,7 @@ invalid.json:2:2 lint/nursery/noDuplicateJsonKeys ━━━━━━━━━━
```
```
invalid.json:7:3 lint/nursery/noDuplicateJsonKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.json:7:3 lint/suspicious/noDuplicateObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The key lorem was already declared.
Expand Down
9 changes: 2 additions & 7 deletions packages/@biomejs/backend-jsonrpc/src/workspace.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions packages/@biomejs/biome/configuration_schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions xtask/codegen/src/promote_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const KNOWN_PATHS: &[&str] = &[
"crates/biome_js_analyze/src/lint",
"crates/biome_css_analyze/src/lint",
"crates/biome_json_analyze/src/lint",
"crates/biome_graphql_analyze/src/lint",
];
pub fn promote_rule(rule_name: &str, new_group: &str) {
let current_dir = env::current_dir().ok().unwrap();
Expand Down Expand Up @@ -85,10 +86,12 @@ pub fn promote_rule(rule_name: &str, new_group: &str) {
std::fs::write(categories_path, categories).unwrap();

let old_test_path = current_dir
.join("crates/biome_js_analyze/tests/specs/nursery")
.join(analyzers_path.clone())
.join("tests/specs/nursery")
.join(rule_name);
let new_test_path = current_dir
.join("crates/biome_js_analyze/tests/specs")
.join(analyzers_path)
.join("tests/specs")
.join(new_group)
.join(rule_name);
fs::rename(old_test_path, new_test_path).unwrap();
Expand Down

0 comments on commit 365fe78

Please sign in to comment.