Skip to content

Commit 5a5881e

Browse files
committed
refactor: rename helpers for determining query variants
1 parent b1355ad commit 5a5881e

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

lib/detect-testing-library-utils.ts

+18-14
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export type DetectionHelpers = {
5252
getCustomModuleImportName: () => string | undefined;
5353
isTestingLibraryImported: () => boolean;
5454
isValidFilename: () => boolean;
55-
isGetByQuery: (node: TSESTree.Identifier) => boolean;
56-
isQueryByQuery: (node: TSESTree.Identifier) => boolean;
57-
isFindByQuery: (node: TSESTree.Identifier) => boolean;
55+
isGetQueryVariant: (node: TSESTree.Identifier) => boolean;
56+
isQueryQueryVariant: (node: TSESTree.Identifier) => boolean;
57+
isFindQueryVariant: (node: TSESTree.Identifier) => boolean;
5858
isSyncQuery: (node: TSESTree.Identifier) => boolean;
5959
isAsyncQuery: (node: TSESTree.Identifier) => boolean;
6060
isCustomQuery: (node: TSESTree.Identifier) => boolean;
@@ -152,38 +152,42 @@ export function detectTestingLibraryUtils<
152152
};
153153

154154
/**
155-
* Determines whether a given node is `getBy*` or `getAllBy*` query variant or not.
155+
* Determines whether a given node is `get*` query variant or not.
156156
*/
157-
const isGetByQuery: DetectionHelpers['isGetByQuery'] = (node) => {
157+
const isGetQueryVariant: DetectionHelpers['isGetQueryVariant'] = (node) => {
158158
return /^get(All)?By.+$/.test(node.name);
159159
};
160160

161161
/**
162-
* Determines whether a given node is `queryBy*` or `queryAllBy*` query variant or not.
162+
* Determines whether a given node is `query*` query variant or not.
163163
*/
164-
const isQueryByQuery: DetectionHelpers['isQueryByQuery'] = (node) => {
164+
const isQueryQueryVariant: DetectionHelpers['isQueryQueryVariant'] = (
165+
node
166+
) => {
165167
return /^query(All)?By.+$/.test(node.name);
166168
};
167169

168170
/**
169-
* Determines whether a given node is `findBy*` or `findAllBy*` query variant or not.
171+
* Determines whether a given node is `find*` query variant or not.
170172
*/
171-
const isFindByQuery: DetectionHelpers['isFindByQuery'] = (node) => {
173+
const isFindQueryVariant: DetectionHelpers['isFindQueryVariant'] = (
174+
node
175+
) => {
172176
return /^find(All)?By.+$/.test(node.name);
173177
};
174178

175179
/**
176180
* Determines whether a given node is sync query or not.
177181
*/
178182
const isSyncQuery: DetectionHelpers['isSyncQuery'] = (node) => {
179-
return isGetByQuery(node) || isQueryByQuery(node);
183+
return isGetQueryVariant(node) || isQueryQueryVariant(node);
180184
};
181185

182186
/**
183187
* Determines whether a given node is async query or not.
184188
*/
185189
const isAsyncQuery: DetectionHelpers['isAsyncQuery'] = (node) => {
186-
return isFindByQuery(node);
190+
return isFindQueryVariant(node);
187191
};
188192

189193
const isCustomQuery: DetectionHelpers['isCustomQuery'] = (node) => {
@@ -364,9 +368,9 @@ export function detectTestingLibraryUtils<
364368
getCustomModuleImportName,
365369
isTestingLibraryImported,
366370
isValidFilename,
367-
isGetByQuery,
368-
isQueryByQuery,
369-
isFindByQuery,
371+
isGetQueryVariant,
372+
isQueryQueryVariant,
373+
isFindQueryVariant,
370374
isSyncQuery,
371375
isAsyncQuery,
372376
isCustomQuery,

lib/rules/prefer-explicit-assert.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
5454

5555
return {
5656
'CallExpression Identifier'(node: TSESTree.Identifier) {
57-
if (helpers.isGetByQuery(node)) {
57+
if (helpers.isGetQueryVariant(node)) {
5858
getQueryCalls.push(node);
5959
}
6060
},

lib/rules/prefer-presence-queries.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
4242
return;
4343
}
4444

45-
const isPresenceQuery = helpers.isGetByQuery(node);
45+
const isPresenceQuery = helpers.isGetQueryVariant(node);
4646
const expectStatement = expectCallNode.parent;
4747
const isPresenceAssert = helpers.isPresenceAssert(expectStatement);
4848
const isAbsenceAssert = helpers.isAbsenceAssert(expectStatement);

tests/fake-rule.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ export default createTestingLibraryRule<Options, MessageIds>({
5050
}
5151

5252
// force queries to be reported
53-
if (helpers.isGetByQuery(node)) {
53+
if (helpers.isGetQueryVariant(node)) {
5454
return context.report({ node, messageId: 'getByError' });
5555
}
5656

57-
if (helpers.isQueryByQuery(node)) {
57+
if (helpers.isQueryQueryVariant(node)) {
5858
return context.report({ node, messageId: 'queryByError' });
5959
}
6060

61-
if (helpers.isFindByQuery(node)) {
61+
if (helpers.isFindQueryVariant(node)) {
6262
return context.report({ node, messageId: 'findByError' });
6363
}
6464
};

0 commit comments

Comments
 (0)