Skip to content

Commit

Permalink
fix(no-nested-object-setvalue): only throw error for Array & Object e…
Browse files Browse the repository at this point in the history
…xpressions

As title.

Close #17
  • Loading branch information
andykao1213 committed Mar 26, 2022
1 parent 5e26c7e commit e5b342b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/no-nested-object-setvalue.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ module.exports = {
const { parent: setValueCallExpression } =
setValueReference.identifier;
const secondArgument = setValueCallExpression.arguments[1];
if (secondArgument && secondArgument.type !== "Literal") {
if (
secondArgument &&
["ArrayExpression", "ObjectExpression"].includes(
secondArgument.type
)
) {
return context.report({
node: secondArgument,
messageId: "noNestedObj",
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/no-nested-object-setvalue.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ ruleTester.run("no-nested-object-setvalue", rule, {
setValue('yourDetails', { firstName: 'value' });
`,
},
{
code: normalizeIndent`
const {setValue} = useForm();
const myFunc = () => 10
setValue('yourDetails', myFunc);
`,
},
{
code: normalizeIndent`
const {setValue} = useForm();
const myVar = 10
setValue('yourDetails', myVar);
`,
},
{
code: normalizeIndent`
function Component() {
Expand Down

0 comments on commit e5b342b

Please sign in to comment.