Skip to content

Commit 19fbcf3

Browse files
committed
refactor(no-await-sync-query): catch sync queries with detection helper
1 parent 4279c72 commit 19fbcf3

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lib/rules/no-await-sync-query.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ export const RULE_NAME = 'no-await-sync-query';
55
export type MessageIds = 'noAwaitSyncQuery';
66
type Options = [];
77

8-
const SYNC_QUERIES_REGEXP = /^(get|query)(All)?By(LabelText|PlaceholderText|Text|AltText|Title|DisplayValue|Role|TestId)$/;
9-
108
export default createTestingLibraryRule<Options, MessageIds>({
119
name: RULE_NAME,
1210
meta: {
@@ -25,18 +23,19 @@ export default createTestingLibraryRule<Options, MessageIds>({
2523
},
2624
defaultOptions: [],
2725

28-
create(context) {
29-
const reportError = (node: TSESTree.Identifier) =>
30-
context.report({
31-
node,
32-
messageId: 'noAwaitSyncQuery',
33-
data: {
34-
name: node.name,
35-
},
36-
});
26+
create(context, _, helpers) {
3727
return {
38-
[`AwaitExpression > CallExpression > Identifier[name=${SYNC_QUERIES_REGEXP}]`]: reportError,
39-
[`AwaitExpression > CallExpression > MemberExpression > Identifier[name=${SYNC_QUERIES_REGEXP}]`]: reportError,
28+
'AwaitExpression > CallExpression Identifier'(node: TSESTree.Identifier) {
29+
if (helpers.isSyncQuery(node)) {
30+
context.report({
31+
node,
32+
messageId: 'noAwaitSyncQuery',
33+
data: {
34+
name: node.name,
35+
},
36+
});
37+
}
38+
},
4039
};
4140
},
4241
});

0 commit comments

Comments
 (0)