fix(rome_service): inject defaults for missing globals
MODIFY
crates/rome_cli/tests/configs.rs
crates/rome_cli/tests/configs.rs
@@ -120,3 +120,11 @@ pub const CONFIG_LINTER_SUPPRESSED_GROUP: &str = r#"{
}
}
}"#;
+
+pub const CONFIG_INCORRECT_GLOBALS_V2: &str = r#"{
+ "javascript": {
+ "formatter": {
+ "quoteStyle": "single"
+ }
+ }
+}"#;

MODIFY
crates/rome_cli/tests/main.rs
crates/rome_cli/tests/main.rs
@@ -1008,7 +1008,7 @@ mod init {
mod configuration {
use crate::configs::{
CONFIG_ALL_FIELDS, CONFIG_BAD_LINE_WIDTH, CONFIG_INCORRECT_GLOBALS,
- CONFIG_LINTER_WRONG_RULE,
+ CONFIG_INCORRECT_GLOBALS_V2, CONFIG_LINTER_WRONG_RULE,
};
use pico_args::Arguments;
use rome_cli::{run_cli, CliSession};
@@ -1110,4 +1110,22 @@ mod configuration {
_ => panic!("expected an error, but found none"),
}
}
+
+ #[test]
+ fn ignore_globals() {
+ let mut fs = MemoryFileSystem::default();
+
+ let file_path = Path::new("rome.json");
+ fs.insert(file_path.into(), CONFIG_INCORRECT_GLOBALS_V2.as_bytes());
+
+ let result = run_cli(CliSession {
+ app: App::with_filesystem_and_console(
+ DynRef::Borrowed(&mut fs),
+ DynRef::Owned(Box::new(BufferConsole::default())),
+ ),
+ args: Arguments::from_vec(vec![OsString::from("check"), OsString::from("file.js")]),
+ });
+
+ assert!(result.is_ok());
+ }
}

MODIFY
crates/rome_service/src/configuration/javascript.rs
crates/rome_service/src/configuration/javascript.rs
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use std::marker::PhantomData;
#[derive(Default, Debug, Deserialize, Serialize, Eq, PartialEq)]
-#[serde(deny_unknown_fields)]
+#[serde(default, deny_unknown_fields)]
pub struct JavascriptConfiguration {
#[serde(skip_serializing_if = "Option::is_none")]
pub formatter: Option<JavascriptFormatter>,

fix(rome_service): inject defaults for missing globals (#2998)