mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(linter): Handle cases where createElement is an Identifier in is_create_element_call (#2474)
I fixed a false negative issue in the `is_create_element_call` function where createElement was an Identifier. https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/utils/react.rs#L13-L19 In the case of [eslint-plugin-react's button-has-type rule](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/button-has-type.md), the following triggers the expected errors: ```ts // error React.createElement("button") // error createElement("button") ``` However, with Oxlint, it behaves differently: ```ts // error React.createElement("button") // false negative createElement("button") ```
This commit is contained in:
parent
2714a32970
commit
35a0f895dc
3 changed files with 13 additions and 0 deletions
|
|
@ -223,6 +223,7 @@ fn test() {
|
|||
(r"<button type={condition ? 'button' : 'submit'}/>", None),
|
||||
(r"<button type={condition ? `button` : `submit`}/>", None),
|
||||
(r#"<button type="button"/>"#, Some(serde_json::json!([{ "reset": false }]))),
|
||||
(r#"createElement("span")"#, None),
|
||||
(r#"React.createElement("span")"#, None),
|
||||
(r#"React.createElement("span", {type: "foo"})"#, None),
|
||||
(r#"React.createElement("button", {type: "button"})"#, None),
|
||||
|
|
@ -290,6 +291,7 @@ fn test() {
|
|||
r#"<button type={condition ? "reset" : "button"}/>"#,
|
||||
Some(serde_json::json!([{ "reset": false }])),
|
||||
),
|
||||
(r#"createElement("button")"#, None),
|
||||
(r#"React.createElement("button")"#, None),
|
||||
(r#"React.createElement("button", {type: foo})"#, None),
|
||||
(r#"React.createElement("button", {type: "foo"})"#, None),
|
||||
|
|
|
|||
|
|
@ -108,6 +108,13 @@ expression: button_has_type
|
|||
╰────
|
||||
help: Change the `type` attribute to one of the allowed values: `button`, `submit`, or `reset`.
|
||||
|
||||
⚠ eslint-plugin-react(button-has-type): `button` elements must have an explicit `type` attribute.
|
||||
╭─[button_has_type.tsx:1:1]
|
||||
1 │ createElement("button")
|
||||
· ───────────────────────
|
||||
╰────
|
||||
help: Add a `type` attribute to the `button` element.
|
||||
|
||||
⚠ eslint-plugin-react(button-has-type): `button` elements must have an explicit `type` attribute.
|
||||
╭─[button_has_type.tsx:1:1]
|
||||
1 │ React.createElement("button")
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ pub fn is_create_element_call(call_expr: &CallExpression) -> bool {
|
|||
return member_expr.static_property_name() == Some("createElement");
|
||||
}
|
||||
|
||||
if let Some(ident) = call_expr.callee.get_identifier_reference() {
|
||||
return ident.name == "createElement";
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue