diff --git a/crates/oxc_linter/src/rules/unicorn/no_object_as_default_parameter.rs b/crates/oxc_linter/src/rules/unicorn/no_object_as_default_parameter.rs index 8a8b018ae..688657587 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_object_as_default_parameter.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_object_as_default_parameter.rs @@ -49,7 +49,9 @@ impl Rule for NoObjectAsDefaultParameter { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { let AstKind::AssignmentPattern(assignment_pat) = node.kind() else { return }; - let Expression::ObjectExpression(object_expr) = &assignment_pat.right else { + let Expression::ObjectExpression(object_expr) = + &assignment_pat.right.without_parenthesized() + else { return; }; @@ -98,6 +100,7 @@ fn test() { r#"const abc = (foo = 123) => {};"#, r#"const abc = (foo = true) => {};"#, r#"const abc = (foo = "bar") => {};"#, + r#"const abc = (foo = ("bar")) => {};"#, r#"const abc = (foo = 123, bar = "foo") => {};"#, r#"const abc = (foo = {}) => {};"#, r#"const abc = ({a = true, b = "foo"}) => {};"#, @@ -107,6 +110,7 @@ fn test() { r#"const {abc = {foo: undefined}} = undefined;"#, r#"const abc = ([{foo = false, bar = 123}]) => {};"#, r#"const abc = ({foo = {a: 123}}) => {};"#, + r#"const abc = ({foo = ({a: 123})}) => {};"#, r#"const abc = ([foo = {a: 123}]) => {};"#, r#"const abc = ({foo: bar = {a: 123}}) => {};"#, r#"const abc = () => (foo = {a: 123});"#, @@ -116,6 +120,7 @@ fn test() { r#"function abc(foo = {a: 123}) {}"#, r#"async function * abc(foo = {a: 123}) {}"#, r#"function abc(foo = {a: false}) {}"#, + r#"function abc(foo = ({a: false})) {}"#, r#"function abc(foo = {a: "bar"}) {}"#, r#"function abc(foo = {a: "bar", b: {c: true}}) {}"#, r#"const abc = (foo = {a: false}) => {};"#, diff --git a/crates/oxc_linter/src/snapshots/no_object_as_default_parameter.snap b/crates/oxc_linter/src/snapshots/no_object_as_default_parameter.snap index 028708da3..568825304 100644 --- a/crates/oxc_linter/src/snapshots/no_object_as_default_parameter.snap +++ b/crates/oxc_linter/src/snapshots/no_object_as_default_parameter.snap @@ -20,6 +20,12 @@ expression: no_object_as_default_parameter · ────────── ╰──── + ⚠ eslint-plugin-unicorn(no-object-as-default-parameter): Do not use an object literal as default for parameter `foo`. + ╭─[no_object_as_default_parameter.tsx:1:1] + 1 │ function abc(foo = ({a: false})) {} + · ────────── + ╰──── + ⚠ eslint-plugin-unicorn(no-object-as-default-parameter): Do not use an object literal as default for parameter `foo`. ╭─[no_object_as_default_parameter.tsx:1:1] 1 │ function abc(foo = {a: "bar"}) {}