@@ -56,7 +56,8 @@ pub struct ESLintRule {
5656 /// Severity of the rule: `off`, `warn`, `error`, etc.
5757 pub severity : AllowWarnDeny ,
5858 /// JSON configuration for the rule, if any.
59- pub config : Option < serde_json:: Value > ,
59+ /// If is `Some`, the `Vec` must not be empty.
60+ pub config : Option < Vec < serde_json:: Value > > ,
6061}
6162
6263impl OxlintRules {
@@ -95,7 +96,15 @@ impl OxlintRules {
9596 . find ( |r| r. name ( ) == rule_name && r. plugin_name ( ) == plugin_name)
9697 } ) ;
9798 if let Some ( rule) = rule {
98- let config = rule_config. config . clone ( ) . unwrap_or_default ( ) ;
99+ // Configs are stored as `Option<Vec<Value>>`, but `from_configuration` expects
100+ // a single `Value` with `Value::Null` being the equivalent of `None`
101+ let config = match & rule_config. config {
102+ Some ( config) => {
103+ debug_assert ! ( !config. is_empty( ) ) ;
104+ serde_json:: Value :: Array ( config. clone ( ) )
105+ }
106+ None => serde_json:: Value :: Null ,
107+ } ;
99108 rules_to_replace. push ( ( rule. from_configuration ( config) , severity) ) ;
100109 }
101110 } else {
@@ -190,7 +199,7 @@ impl Serialize for OxlintRules {
190199 let key = rule. full_name ( ) ;
191200 match rule. config . as_ref ( ) {
192201 // e.g. unicorn/some-rule: ["warn", { foo: "bar" }]
193- Some ( config) if !config . is_null ( ) => {
202+ Some ( config) => {
194203 let value = ( rule. severity . as_str ( ) , config) ;
195204 rules. serialize_entry ( & key, & value) ?;
196205 }
@@ -283,7 +292,7 @@ pub(super) fn unalias_plugin_name(plugin_name: &str, rule_name: &str) -> (String
283292
284293fn parse_rule_value (
285294 value : serde_json:: Value ,
286- ) -> Result < ( AllowWarnDeny , Option < serde_json:: Value > ) , Error > {
295+ ) -> Result < ( AllowWarnDeny , Option < Vec < serde_json:: Value > > ) , Error > {
287296 match value {
288297 serde_json:: Value :: String ( _) | serde_json:: Value :: Number ( _) => {
289298 let severity = AllowWarnDeny :: try_from ( & value) ?;
@@ -307,7 +316,7 @@ fn parse_rule_value(
307316 } else {
308317 // e.g. ["error", "args", { type: "whatever" }, ["len", "also"]]
309318 v. remove ( 0 ) ;
310- Some ( serde_json :: Value :: Array ( v ) )
319+ Some ( v )
311320 } ;
312321
313322 Ok ( ( severity, config) )
@@ -382,7 +391,7 @@ mod test {
382391 assert_eq ! ( r3. rule_name, "dummy" ) ;
383392 assert_eq ! ( r3. plugin_name, "eslint" ) ;
384393 assert ! ( r3. severity. is_warn_deny( ) ) ;
385- assert_eq ! ( r3. config, Some ( serde_json:: json!( [ "arg1" , "args2" ] ) ) ) ;
394+ assert_eq ! ( r3. config, Some ( vec! [ serde_json:: json!( "arg1" ) , serde_json :: json! ( "args2" ) ] ) ) ;
386395
387396 let r4 = rules. next ( ) . unwrap ( ) ;
388397 assert_eq ! ( r4. rule_name, "noop" ) ;
0 commit comments