refactor(rome_service): change how rules config is shaped
MODIFY
crates/rome_cli/tests/configs.rs
crates/rome_cli/tests/configs.rs
@@ -36,7 +36,6 @@ pub const CONFIG_ALL_FIELDS: &str = r#"{
"enabled": true,
"rules": {
"js": {
- "rules": {
"noDeadCode": "off",
"useSimplifiedLogicExpression": "warn",
"noCatchAssign": "error",
@@ -48,7 +47,6 @@ pub const CONFIG_ALL_FIELDS: &str = r#"{
}
}
}
- }
},
"javascript": {
"globals": ["$"],
@@ -75,17 +73,13 @@ pub const CONFIG_LINTER_WRONG_RULE: &str = r#"{
"enabled": true,
"rules": {
"js": {
- "rules": {
"foo_rule": "off"
- }
},
"jsx": {
- "rules": {
"what_the_hell": "off"
}
}
}
- }
}"#;
pub const CONFIG_INCORRECT_GLOBALS: &str = r#"{
@@ -102,12 +96,10 @@ pub const CONFIG_LINTER_SUPPRESSED_RULE: &str = r#"{
"rules": {
"recommended": true,
"js": {
- "rules": {
"noDebugger": "off"
}
}
}
- }
}"#;
pub const CONFIG_LINTER_SUPPRESSED_GROUP: &str = r#"{
@@ -126,12 +118,11 @@ pub const CONFIG_LINTER_DOWNGRADE_DIAGNOSTIC: &str = r#"{
"rules": {
"recommended": true,
"js": {
- "rules": {
+ "recommended": true,
"noDebugger": "warn"
}
}
}
- }
}"#;
pub const CONFIG_LINTER_UPGRADE_DIAGNOSTIC: &str = r#"{
@@ -139,12 +130,10 @@ pub const CONFIG_LINTER_UPGRADE_DIAGNOSTIC: &str = r#"{
"rules": {
"recommended": true,
"js": {
- "rules": {
"noDeadCode": "error"
}
}
}
- }
}"#;
pub const CONFIG_INCORRECT_GLOBALS_V2: &str = r#"{

MODIFY
crates/rome_cli/tests/main.rs
crates/rome_cli/tests/main.rs
@@ -1150,7 +1150,7 @@ mod configuration {
args: Arguments::from_vec(vec![OsString::from("format"), OsString::from("file.js")]),
});
- assert!(result.is_ok());
+ assert!(result.is_ok(), "run_cli returned {result:?}");
}
#[test]
@@ -1167,7 +1167,8 @@ mod configuration {
),
args: Arguments::from_vec(vec![OsString::from("format"), OsString::from("file.js")]),
});
- assert!(result.is_err());
+
+ assert!(result.is_err(), "run_cli returned {result:?}");
match result {
Err(error) => {
@@ -1194,6 +1195,8 @@ mod configuration {
args: Arguments::from_vec(vec![OsString::from("check"), OsString::from("file.js")]),
});
+ assert!(result.is_err(), "run_cli returned {result:?}");
+
match result {
Err(error) => {
assert!(error.to_string().contains("Invalid rule name `foo_rule`"),)
@@ -1217,7 +1220,7 @@ mod configuration {
args: Arguments::from_vec(vec![OsString::from("check"), OsString::from("file.js")]),
});
- assert!(result.is_err());
+ assert!(result.is_err(), "run_cli returned {result:?}");
match result {
Err(error) => {
@@ -1244,6 +1247,6 @@ mod configuration {
args: Arguments::from_vec(vec![OsString::from("check"), OsString::from("file.js")]),
});
- assert!(result.is_ok());
+ assert!(result.is_ok(), "run_cli returned {result:?}");
}
}

MODIFY
crates/rome_service/src/configuration/linter/rules.rs
crates/rome_service/src/configuration/linter/rules.rs
@@ -201,7 +201,7 @@ impl Rules {
}
}
#[derive(Deserialize, Default, Serialize, Debug, Clone)]
-#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
+#[serde(rename_all = "camelCase", default)]
pub struct Js {
#[doc = r" It enables the recommended rules for this group"]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -209,7 +209,8 @@ pub struct Js {
#[doc = r" List of rules for the current group"]
#[serde(
skip_serializing_if = "IndexMap::is_empty",
- deserialize_with = "deserialize_js_rules"
+ deserialize_with = "deserialize_js_rules",
+ flatten
)]
pub rules: IndexMap<String, RuleConfiguration>,
}
@@ -352,7 +353,7 @@ where
Ok(value)
}
#[derive(Deserialize, Default, Serialize, Debug, Clone)]
-#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
+#[serde(rename_all = "camelCase", default)]
pub struct Jsx {
#[doc = r" It enables the recommended rules for this group"]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -360,7 +361,8 @@ pub struct Jsx {
#[doc = r" List of rules for the current group"]
#[serde(
skip_serializing_if = "IndexMap::is_empty",
- deserialize_with = "deserialize_jsx_rules"
+ deserialize_with = "deserialize_jsx_rules",
+ flatten
)]
pub rules: IndexMap<String, RuleConfiguration>,
}
@@ -429,7 +431,7 @@ where
Ok(value)
}
#[derive(Deserialize, Default, Serialize, Debug, Clone)]
-#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
+#[serde(rename_all = "camelCase", default)]
pub struct Regex {
#[doc = r" It enables the recommended rules for this group"]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -437,7 +439,8 @@ pub struct Regex {
#[doc = r" List of rules for the current group"]
#[serde(
skip_serializing_if = "IndexMap::is_empty",
- deserialize_with = "deserialize_regex_rules"
+ deserialize_with = "deserialize_regex_rules",
+ flatten
)]
pub rules: IndexMap<String, RuleConfiguration>,
}
@@ -496,7 +499,7 @@ where
Ok(value)
}
#[derive(Deserialize, Default, Serialize, Debug, Clone)]
-#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
+#[serde(rename_all = "camelCase", default)]
pub struct Ts {
#[doc = r" It enables the recommended rules for this group"]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -504,7 +507,8 @@ pub struct Ts {
#[doc = r" List of rules for the current group"]
#[serde(
skip_serializing_if = "IndexMap::is_empty",
- deserialize_with = "deserialize_ts_rules"
+ deserialize_with = "deserialize_ts_rules",
+ flatten
)]
pub rules: IndexMap<String, RuleConfiguration>,
}

MODIFY
xtask/codegen/src/generate_configuration.rs
xtask/codegen/src/generate_configuration.rs
@@ -71,14 +71,14 @@ pub(crate) fn generate_rules_configuration(mode: Mode) -> Result<()> {
let group_struct = quote! {
#[derive(Deserialize, Default, Serialize, Debug, Clone)]
- #[serde(rename_all = "camelCase", default, deny_unknown_fields)]
+ #[serde(rename_all = "camelCase", default)]
pub struct #group_struct_name {
/// It enables the recommended rules for this group
#[serde(skip_serializing_if = "Option::is_none")]
pub recommended: Option<bool>,
/// List of rules for the current group
- #[serde(skip_serializing_if = "IndexMap::is_empty", deserialize_with = #deserialize_function_string)]
+ #[serde(skip_serializing_if = "IndexMap::is_empty", deserialize_with = #deserialize_function_string, flatten)]
pub rules: IndexMap<String, RuleConfiguration>,
}

refactor(rome_service): change how rules config is shaped (#3016)