Skip to content

Commit 3f817aa

Browse files
thomaslombartBelco90
authored andcommitted
fix: report query instead of var reference (#10)
1 parent e121350 commit 3f817aa

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

lib/rules/await-async-query.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ module.exports = {
6262
});
6363
} else {
6464
references.forEach(reference => {
65-
const node = reference.identifier;
66-
if (!isAwaited(node.parent) && !isPromiseResolved(node)) {
65+
const referenceNode = reference.identifier;
66+
if (
67+
!isAwaited(referenceNode.parent) &&
68+
!isPromiseResolved(referenceNode)
69+
) {
6770
context.report({
68-
node: reference.identifier,
71+
node,
6972
messageId: 'awaitAsyncQuery',
7073
data: {
7174
name: node.name,

tests/lib/rules/await-async-query.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,30 @@ ruleTester.run('await-async-query', rule, {
122122

123123
invalid:
124124
// async queries without await operator or then method are not valid
125-
ASYNC_QUERIES_COMBINATIONS.map(query => ({
126-
code: `async () => {
125+
[
126+
...ASYNC_QUERIES_COMBINATIONS.map(query => ({
127+
code: `async () => {
127128
doSomething()
128129
const foo = ${query}('foo')
129130
}
130131
`,
131-
errors: [
132-
{
133-
messageId: 'awaitAsyncQuery',
134-
},
135-
],
136-
})),
132+
errors: [
133+
{
134+
messageId: 'awaitAsyncQuery',
135+
},
136+
],
137+
})),
138+
...ASYNC_QUERIES_COMBINATIONS.map(query => ({
139+
code: `async () => {
140+
const foo = ${query}('foo')
141+
expect(foo).toBeInTheDocument()
142+
}
143+
`,
144+
errors: [
145+
{
146+
message: `\`${query}\` must have \`await\` operator`,
147+
},
148+
],
149+
})),
150+
],
137151
});

0 commit comments

Comments
 (0)