Skip to content

Commit bdc3168

Browse files
authored
fix: bug in valid-graphql-wire-adapter-callback-parameters rule (#162)
1 parent af29c89 commit bdc3168

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

lib/rules/valid-graphql-wire-adapter-callback-parameters.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ module.exports = {
2525
const { decorators } = node;
2626

2727
// Check that the @wire decorator is using graphql
28-
const graphQlDecorator =
29-
decorators !== undefined &&
30-
decorators.find((decorator) => {
31-
if (decorator.expression && decorator.expression.arguments) {
32-
return decorator.expression.arguments.some((argument) => {
33-
return argument.name === 'graphql';
34-
});
35-
}
36-
return false;
37-
});
28+
const graphQlDecorator = (decorators || []).find((decorator) => {
29+
if (decorator.expression && decorator.expression.arguments) {
30+
return decorator.expression.arguments.some((argument) => {
31+
return argument.name === 'graphql';
32+
});
33+
}
34+
return false;
35+
});
3836

3937
// Verify that the method definition is using 'errors' not 'error
4038
if (graphQlDecorator !== undefined) {

test/lib/rules/valid-graphql-wire-adapter-callback-parameters.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ testRule('valid-graphql-wire-adapter-callback-parameters', {
3434
wiredMethod({errors, data}) {}
3535
}`,
3636
},
37+
{
38+
code: `
39+
class C {
40+
f({ error }) {
41+
return error;
42+
}
43+
}
44+
`,
45+
},
3746
],
3847
invalid: [
3948
{
@@ -95,6 +104,15 @@ testTypeScript('valid-graphql-wire-adapter-callback-parameters', {
95104
wiredMethod({errors, data}: Record<string, any>): void {}
96105
}`,
97106
},
107+
{
108+
code: `
109+
class C {
110+
f({ error }) {
111+
return error;
112+
}
113+
}
114+
`,
115+
},
98116
],
99117
invalid: [
100118
{

0 commit comments

Comments
 (0)