mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter) Fix no object as default param with parenthesis (#1244)
This commit is contained in:
parent
3a92828a0a
commit
f3f3383733
2 changed files with 12 additions and 1 deletions
|
|
@ -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}) => {};"#,
|
||||
|
|
|
|||
|
|
@ -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"}) {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue