Skip to content

Commit

Permalink
fix(prefer-to-have-value): check that property exists before accessing (
Browse files Browse the repository at this point in the history
#243)

Co-authored-by: Ben Monro <[email protected]>
  • Loading branch information
G-Rath and benmonro authored Dec 26, 2021
1 parent e8cefd3 commit 3f59068
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/__tests__/lib/rules/prefer-to-have-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ ruleTester.run("prefer-to-have-value", rule, {

`const element = { value: 'foo' };
expect(element.value).not.toBe('foo');`,
`
const res = makePath()();
expect(res.value).toEqual('/repositories/create');
`,
],
invalid: [
{
Expand Down
4 changes: 3 additions & 1 deletion src/assignment-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export function getQueryNodeFrom(context, nodeWithValueProp) {
};
}

const query = queryNode.callee.name || queryNode.callee.property.name;
const query =
queryNode.callee.name ||
(queryNode.callee.property && queryNode.callee.property.name);
const queryArg = queryNode.arguments[0] && queryNode.arguments[0].value;
const isDTLQuery = queries.includes(query);

Expand Down

0 comments on commit 3f59068

Please sign in to comment.