diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d46ae3d3cc..967c1a6b9be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,10 @@ multiple files: ### Editors +#### Other changes + +- The Rome LSP is now able to show diagnostics that belong to JSON lint rules. + ### Formatter - Added a new option called `--jsx-quote-style` to the formatter. This option allows you to choose between single and double quotes for JSX attributes. [#4486](https://github.com/rome/tools/issues/4486) @@ -96,6 +100,8 @@ multiple files: This rule proposes turning function expressions into arrow functions. Function expressions that use `this` are ignored. +- [`noDuplicateJsonKeys`](https://docs.rome.tools/lint/rules/noDuplicateJsonKeys/) + #### Other changes - [`noRedeclare`](https://docs.rome.tools/lint/rules/noredeclare/): allow redeclare of index signatures are in different type members [#4478](https://github.com/rome/tools/issues/4478) diff --git a/Cargo.lock b/Cargo.lock index f57123d69c4..15ffc6aaa46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2169,6 +2169,7 @@ dependencies = [ "rome_js_parser", "rome_js_semantic", "rome_js_syntax", + "rome_json_analyze", "rome_json_formatter", "rome_json_parser", "rome_json_syntax", @@ -2867,9 +2868,9 @@ dependencies = [ [[package]] name = "trybuild" -version = "1.0.79" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3115bddce1b5f52dd4b5e0ec8298a66ce733e4cc6759247dc2d1c11508ec38" +checksum = "501dbdbb99861e4ab6b60eb6a7493956a9defb644fd034bc4a5ef27c693c8a3a" dependencies = [ "basic-toml", "glob", diff --git a/crates/rome_cli/tests/commands/check.rs b/crates/rome_cli/tests/commands/check.rs index e27e4cdbadb..2b23abba829 100644 --- a/crates/rome_cli/tests/commands/check.rs +++ b/crates/rome_cli/tests/commands/check.rs @@ -2398,3 +2398,46 @@ fn ignores_unknown_file() { result, )); } + +#[test] +fn check_json_files() { + let mut fs = MemoryFileSystem::default(); + let mut console = BufferConsole::default(); + + let file_path1 = Path::new("test.json"); + fs.insert( + file_path1.into(), + r#"{ "foo": true, "foo": true }"#.as_bytes(), + ); + + let configuration = Path::new("rome.json"); + fs.insert( + configuration.into(), + r#"{ + "linter": { + "rules": { + "nursery": { + "noDuplicateJsonKeys": "error" + } + } + } + }"# + .as_bytes(), + ); + + let result = run_cli( + DynRef::Borrowed(&mut fs), + &mut console, + Args::from(&[("check"), file_path1.as_os_str().to_str().unwrap()]), + ); + + assert!(result.is_err(), "run_cli returned {result:?}"); + + assert_cli_snapshot(SnapshotPayload::new( + module_path!(), + "check_json_files", + fs, + console, + result, + )); +} diff --git a/crates/rome_cli/tests/snapshots/main_commands_check/check_json_files.snap b/crates/rome_cli/tests/snapshots/main_commands_check/check_json_files.snap new file mode 100644 index 00000000000..bf6fd24809e --- /dev/null +++ b/crates/rome_cli/tests/snapshots/main_commands_check/check_json_files.snap @@ -0,0 +1,60 @@ +--- +source: crates/rome_cli/tests/snap_test.rs +expression: content +--- +## `rome.json` + +```json +{ + "linter": { + "rules": { + "nursery": { + "noDuplicateJsonKeys": "error" + } + } + } +} +``` + +## `test.json` + +```json +{ "foo": true, "foo": true } +``` + +# Termination Message + +```block +internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × Some errors were emitted while running checks + + + +``` + +# Emitted Messages + +```block +test.json:1:3 lint/nursery/noDuplicateJsonKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + × The key foo was already declared. + + > 1 │ { "foo": true, "foo": true } + │ ^^^^^ + + i This where a duplicated key was declared again. + + > 1 │ { "foo": true, "foo": true } + │ ^^^^^ + + i If a key is defined multiple times, only the last definition takes effect. Previous definitions are ignored. + + +``` + +```block +Checked 1 file(s) in