Skip to content

Commit 1facfc3

Browse files
neriyardenMichaelDeBoey
authored andcommitted
refactor: improve comments readability
1 parent 2c5cb31 commit 1facfc3

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

lib/rules/await-async-queries.ts

+25-15
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
7777
closestCallExpressionNode.parent
7878
);
7979

80-
// check direct usage of async query:
81-
// const element = await findByRole('button')
80+
/**
81+
* Check direct usage of async query:
82+
* const element = await findByRole('button');
83+
*/
8284
if (references.length === 0) {
8385
if (!isPromiseHandled(identifierNode)) {
8486
context.report({
@@ -103,9 +105,11 @@ export default createTestingLibraryRule<Options, MessageIds>({
103105
}
104106
}
105107

106-
// check references usages of async query:
107-
// const promise = findByRole('button')
108-
// const element = await promise
108+
/**
109+
* Check references usages of async query:
110+
* const promise = findByRole('button');
111+
* const element = await promise;
112+
*/
109113
for (const reference of references) {
110114
if (
111115
ASTUtils.isIdentifier(reference.identifier) &&
@@ -129,7 +133,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
129133
functionWrappersNames.includes(identifierNode.name) &&
130134
!isPromiseHandled(identifierNode)
131135
) {
132-
// check async queries used within a wrapper previously detected
136+
// Check async queries used within a wrapper previously detected
133137
context.report({
134138
node: identifierNode,
135139
messageId: 'asyncQueryWrapper',
@@ -141,19 +145,23 @@ export default createTestingLibraryRule<Options, MessageIds>({
141145
if (!functionExpression) return null;
142146

143147
let IdentifierNodeFixer;
144-
// If the wrapper is a property of an object,
145-
// add 'await' before the object, e.g.:
146-
// const obj = { wrapper: () => screen.findByText(/foo/i) };
147-
// await obj.wrapper();
148148
if (isMemberExpression(identifierNode.parent)) {
149+
/**
150+
* If the wrapper is a property of an object,
151+
* add 'await' before the object, e.g.:
152+
* const obj = { wrapper: () => screen.findByText(/foo/i) };
153+
* await obj.wrapper();
154+
*/
149155
IdentifierNodeFixer = fixer.insertTextBefore(
150156
identifierNode.parent,
151157
'await '
152158
);
153-
// Otherwise, add 'await' before the wrapper function, e.g.:
154-
// const wrapper = () => screen.findByText(/foo/i);
155-
// await wrapper();
156159
} else {
160+
/**
161+
* Add 'await' before the wrapper function, e.g.:
162+
* const wrapper = () => screen.findByText(/foo/i);
163+
* await wrapper();
164+
*/
157165
IdentifierNodeFixer = fixer.insertTextBefore(
158166
identifierNode,
159167
'await '
@@ -163,8 +171,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
163171
if (functionExpression.async) {
164172
return IdentifierNodeFixer;
165173
} else {
166-
// Mutate the actual node so if other nodes exist in this
167-
// function expression body they don't also try to fix it.
174+
/**
175+
* Mutate the actual node so if other nodes exist in this
176+
* function expression body they don't also try to fix it.
177+
*/
168178
functionExpression.async = true;
169179

170180
return [

0 commit comments

Comments
 (0)