Skip to content

Commit 347b2cd

Browse files
authored
Merge branch 'main' into fix-setup-async-methods
2 parents 63dfaa6 + 2e7e1b6 commit 347b2cd

18 files changed

+375
-29
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,15 @@
738738
"code",
739739
"test"
740740
]
741+
},
742+
{
743+
"login": "andreww2012",
744+
"name": "Andrew Kazakov",
745+
"avatar_url": "https://avatars.githubusercontent.com/u/6554045?v=4",
746+
"profile": "https://github.com/andreww2012",
747+
"contributions": [
748+
"code"
749+
]
741750
}
742751
],
743752
"contributorsPerLine": 7,

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,9 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
555555
<td align="center" valign="top" width="14.28%"><a href="https://github.com/y-hsgw"><img src="https://avatars.githubusercontent.com/u/49516827?v=4?s=100" width="100px;" alt="Yukihiro Hasegawa"/><br /><sub><b>Yukihiro Hasegawa</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=y-hsgw" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=y-hsgw" title="Tests">⚠️</a></td>
556556
<td align="center" valign="top" width="14.28%"><a href="https://www.charleypugmire.me"><img src="https://avatars.githubusercontent.com/u/3228931?v=4?s=100" width="100px;" alt="Charley Pugmire"/><br /><sub><b>Charley Pugmire</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=puglyfe" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=puglyfe" title="Tests">⚠️</a></td>
557557
</tr>
558+
<tr>
559+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/andreww2012"><img src="https://avatars.githubusercontent.com/u/6554045?v=4?s=100" width="100px;" alt="Andrew Kazakov"/><br /><sub><b>Andrew Kazakov</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=andreww2012" title="Code">💻</a></td>
560+
</tr>
558561
</tbody>
559562
</table>
560563

lib/create-testing-library-rule/detect-testing-library-utils.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ import {
2323
ASYNC_UTILS,
2424
DEBUG_UTILS,
2525
PRESENCE_MATCHERS,
26+
USER_EVENT_MODULE,
2627
} from '../utils';
28+
import {
29+
isCustomTestingLibraryModule,
30+
isOfficialTestingLibraryModule,
31+
isTestingLibraryModule,
32+
} from '../utils/is-testing-library-module';
2733

2834
const SETTING_OPTION_OFF = 'off';
2935

@@ -136,7 +142,6 @@ export interface DetectionHelpers {
136142
isNodeComingFromTestingLibrary: IsNodeComingFromTestingLibraryFn;
137143
}
138144

139-
const USER_EVENT_PACKAGE = '@testing-library/user-event';
140145
const REACT_DOM_TEST_UTILS_PACKAGE = 'react-dom/test-utils';
141146
const FIRE_EVENT_NAME = 'fireEvent';
142147
const CREATE_EVENT_NAME = 'createEvent';
@@ -977,12 +982,11 @@ export function detectTestingLibraryUtils<
977982
}
978983

979984
const hasImportElementMatch = hasImportMatch(importNode, identifierName);
980-
const hasImportModuleMatch =
981-
/testing-library/g.test(importDeclarationName) ||
982-
(typeof customModuleSetting === 'string' &&
983-
importDeclarationName.endsWith(customModuleSetting));
984985

985-
return hasImportElementMatch && hasImportModuleMatch;
986+
return (
987+
hasImportElementMatch &&
988+
isTestingLibraryModule(importDeclarationName, customModuleSetting)
989+
);
986990
};
987991

988992
const helpers: DetectionHelpers = {
@@ -1034,17 +1038,16 @@ export function detectTestingLibraryUtils<
10341038
}
10351039
// check only if testing library import not found yet so we avoid
10361040
// to override importedTestingLibraryNodes after it's found
1037-
if (/testing-library/g.test(node.source.value)) {
1041+
if (isOfficialTestingLibraryModule(node.source.value)) {
10381042
importedTestingLibraryNodes.push(node);
10391043
}
10401044

10411045
// check only if custom module import not found yet so we avoid
10421046
// to override importedCustomModuleNode after it's found
10431047
const customModule = getCustomModule();
10441048
if (
1045-
customModule &&
10461049
!importedCustomModuleNode &&
1047-
node.source.value.endsWith(customModule)
1050+
isCustomTestingLibraryModule(node.source.value, customModule)
10481051
) {
10491052
importedCustomModuleNode = node;
10501053
}
@@ -1053,7 +1056,7 @@ export function detectTestingLibraryUtils<
10531056
// to override importedUserEventLibraryNode after it's found
10541057
if (
10551058
!importedUserEventLibraryNode &&
1056-
node.source.value === USER_EVENT_PACKAGE
1059+
node.source.value === USER_EVENT_MODULE
10571060
) {
10581061
importedUserEventLibraryNode = node;
10591062
}
@@ -1080,7 +1083,7 @@ export function detectTestingLibraryUtils<
10801083
(arg) =>
10811084
isLiteral(arg) &&
10821085
typeof arg.value === 'string' &&
1083-
/testing-library/g.test(arg.value)
1086+
isOfficialTestingLibraryModule(arg.value)
10841087
)
10851088
) {
10861089
importedTestingLibraryNodes.push(callExpression);
@@ -1091,10 +1094,9 @@ export function detectTestingLibraryUtils<
10911094
!importedCustomModuleNode &&
10921095
args.some(
10931096
(arg) =>
1094-
customModule &&
10951097
isLiteral(arg) &&
10961098
typeof arg.value === 'string' &&
1097-
arg.value.endsWith(customModule)
1099+
isCustomTestingLibraryModule(arg.value, customModule)
10981100
)
10991101
) {
11001102
importedCustomModuleNode = callExpression;
@@ -1106,7 +1108,7 @@ export function detectTestingLibraryUtils<
11061108
(arg) =>
11071109
isLiteral(arg) &&
11081110
typeof arg.value === 'string' &&
1109-
arg.value === USER_EVENT_PACKAGE
1111+
arg.value === USER_EVENT_MODULE
11101112
)
11111113
) {
11121114
importedUserEventLibraryNode = callExpression;

lib/rules/await-async-utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getFunctionName,
88
getInnermostReturningFunction,
99
getVariableReferences,
10+
isCallExpression,
1011
isObjectPattern,
1112
isPromiseHandled,
1213
isProperty,
@@ -110,6 +111,8 @@ export default createTestingLibraryRule<Options, MessageIds>({
110111
const isAssigningKnownAsyncFunctionWrapper =
111112
ASTUtils.isIdentifier(node.id) &&
112113
node.init !== null &&
114+
!isCallExpression(node.init) &&
115+
!ASTUtils.isAwaitExpression(node.init) &&
113116
functionWrappersNames.includes(
114117
getDeepestIdentifierNode(node.init)?.name ?? ''
115118
);

lib/rules/no-node-access.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
4141
type: 'boolean',
4242
},
4343
},
44+
additionalProperties: false,
4445
},
4546
],
4647
},

lib/rules/no-render-in-lifecycle.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
7272
type: 'string',
7373
},
7474
},
75+
additionalProperties: false,
7576
},
7677
],
7778
},

lib/rules/no-unnecessary-act.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
4545
type: 'boolean',
4646
},
4747
},
48+
additionalProperties: false,
4849
},
4950
],
5051
},

lib/rules/prefer-query-matchers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
5050
type: 'string',
5151
},
5252
},
53+
additionalProperties: false,
5354
},
5455
},
5556
},

lib/rules/prefer-user-event.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
9090
properties: {
9191
allowedMethods: { type: 'array' },
9292
},
93+
additionalProperties: false,
9394
},
9495
],
9596
},

lib/utils/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ const LIBRARY_MODULES = [
3333

3434
const USER_EVENT_MODULE = '@testing-library/user-event';
3535

36+
const OLD_LIBRARY_MODULES = [
37+
'dom-testing-library',
38+
'vue-testing-library',
39+
'react-testing-library',
40+
] as const;
41+
3642
const SYNC_QUERIES_VARIANTS = [
3743
'getBy',
3844
'getAllBy',
@@ -154,4 +160,5 @@ export {
154160
ABSENCE_MATCHERS,
155161
EVENT_HANDLER_METHODS,
156162
USER_EVENT_MODULE,
163+
OLD_LIBRARY_MODULES,
157164
};

0 commit comments

Comments
 (0)