From 93742f89e91bc7c45491b6d2b49a134fa65f2b5c Mon Sep 17 00:00:00 2001 From: keita hino Date: Mon, 26 Feb 2024 16:49:50 +0900 Subject: [PATCH] fix(linter): Correct configuration file parsing for jsx-no-useless-fragment (#2512) fix: #2484 I fixed the configuration parsing for jsx-no-useless-fragment. --- .../src/rules/react/jsx_no_useless_fragment.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs b/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs index bb9c2cea0..8ec05c1e9 100644 --- a/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs +++ b/crates/oxc_linter/src/rules/react/jsx_no_useless_fragment.rs @@ -56,10 +56,13 @@ declare_oxc_lint!( impl Rule for JsxNoUselessFragment { fn from_configuration(value: serde_json::Value) -> Self { - let allow_expressions = - value.get("allowExpressions").and_then(serde_json::Value::as_bool).unwrap_or(false); + let value = value.as_array().and_then(|arr| arr.first()).and_then(|val| val.as_object()); - Self { allow_expressions } + Self { + allow_expressions: value + .and_then(|val| val.get("allowExpressions").and_then(serde_json::Value::as_bool)) + .unwrap_or(true), + } } fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { @@ -224,15 +227,16 @@ fn test() { (r"{item.value}", None), (r"eeee ee eeeeeee eeeeeeee} />", None), (r"<>{foos.map(foo => foo)}", None), - (r"<>{moo}", Some(json!({ "allowExpressions": true }))), + (r"<>{moo}", Some(json!([{ "allowExpressions": true }]))), ( r" <> {moo} ", - Some(json!({ "allowExpressions": true })), + Some(json!([{ "allowExpressions": true }])), ), + (r"{1 && <>{1}}", Some(json!(["warn", {"allowExpressions": true}]))), ]; let fail = vec![