mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter): Correct configuration file parsing for jsx-no-useless-fragment (#2512)
fix: #2484 I fixed the configuration parsing for jsx-no-useless-fragment.
This commit is contained in:
parent
cd75c1ca59
commit
93742f89e9
1 changed files with 9 additions and 5 deletions
|
|
@ -56,10 +56,13 @@ declare_oxc_lint!(
|
||||||
|
|
||||||
impl Rule for JsxNoUselessFragment {
|
impl Rule for JsxNoUselessFragment {
|
||||||
fn from_configuration(value: serde_json::Value) -> Self {
|
fn from_configuration(value: serde_json::Value) -> Self {
|
||||||
let allow_expressions =
|
let value = value.as_array().and_then(|arr| arr.first()).and_then(|val| val.as_object());
|
||||||
value.get("allowExpressions").and_then(serde_json::Value::as_bool).unwrap_or(false);
|
|
||||||
|
|
||||||
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>) {
|
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||||
|
|
@ -224,15 +227,16 @@ fn test() {
|
||||||
(r"<Fragment key={item.id}>{item.value}</Fragment>", None),
|
(r"<Fragment key={item.id}>{item.value}</Fragment>", None),
|
||||||
(r"<Fooo content={<>eeee ee eeeeeee eeeeeeee</>} />", None),
|
(r"<Fooo content={<>eeee ee eeeeeee eeeeeeee</>} />", None),
|
||||||
(r"<>{foos.map(foo => foo)}</>", None),
|
(r"<>{foos.map(foo => foo)}</>", None),
|
||||||
(r"<>{moo}</>", Some(json!({ "allowExpressions": true }))),
|
(r"<>{moo}</>", Some(json!([{ "allowExpressions": true }]))),
|
||||||
(
|
(
|
||||||
r"
|
r"
|
||||||
<>
|
<>
|
||||||
{moo}
|
{moo}
|
||||||
</>
|
</>
|
||||||
",
|
",
|
||||||
Some(json!({ "allowExpressions": true })),
|
Some(json!([{ "allowExpressions": true }])),
|
||||||
),
|
),
|
||||||
|
(r"{1 && <>{1}</>}", Some(json!(["warn", {"allowExpressions": true}]))),
|
||||||
];
|
];
|
||||||
|
|
||||||
let fail = vec![
|
let fail = vec![
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue