Skip to content

Commit 3f59068

Browse files
G-Rathbenmonro
andauthored
fix(prefer-to-have-value): check that property exists before accessing (#243)
Co-authored-by: Ben Monro <[email protected]>
1 parent e8cefd3 commit 3f59068

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/__tests__/lib/rules/prefer-to-have-value.js

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ ruleTester.run("prefer-to-have-value", rule, {
5252

5353
`const element = { value: 'foo' };
5454
expect(element.value).not.toBe('foo');`,
55+
`
56+
const res = makePath()();
57+
expect(res.value).toEqual('/repositories/create');
58+
`,
5559
],
5660
invalid: [
5761
{

src/assignment-ast.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ export function getQueryNodeFrom(context, nodeWithValueProp) {
7474
};
7575
}
7676

77-
const query = queryNode.callee.name || queryNode.callee.property.name;
77+
const query =
78+
queryNode.callee.name ||
79+
(queryNode.callee.property && queryNode.callee.property.name);
7880
const queryArg = queryNode.arguments[0] && queryNode.arguments[0].value;
7981
const isDTLQuery = queries.includes(query);
8082

0 commit comments

Comments
 (0)