Skip to content

Commit 48eeefc

Browse files
authored
Merge branch 'main' into tweak-handled-promise-logic
2 parents b17e05a + 2e7e1b6 commit 48eeefc

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

@@ -133,7 +139,6 @@ export interface DetectionHelpers {
133139
isNodeComingFromTestingLibrary: IsNodeComingFromTestingLibraryFn;
134140
}
135141

136-
const USER_EVENT_PACKAGE = '@testing-library/user-event';
137142
const REACT_DOM_TEST_UTILS_PACKAGE = 'react-dom/test-utils';
138143
const FIRE_EVENT_NAME = 'fireEvent';
139144
const CREATE_EVENT_NAME = 'createEvent';
@@ -960,12 +965,11 @@ export function detectTestingLibraryUtils<
960965
}
961966

962967
const hasImportElementMatch = hasImportMatch(importNode, identifierName);
963-
const hasImportModuleMatch =
964-
/testing-library/g.test(importDeclarationName) ||
965-
(typeof customModuleSetting === 'string' &&
966-
importDeclarationName.endsWith(customModuleSetting));
967968

968-
return hasImportElementMatch && hasImportModuleMatch;
969+
return (
970+
hasImportElementMatch &&
971+
isTestingLibraryModule(importDeclarationName, customModuleSetting)
972+
);
969973
};
970974

971975
const helpers: DetectionHelpers = {
@@ -1017,17 +1021,16 @@ export function detectTestingLibraryUtils<
10171021
}
10181022
// check only if testing library import not found yet so we avoid
10191023
// to override importedTestingLibraryNodes after it's found
1020-
if (/testing-library/g.test(node.source.value)) {
1024+
if (isOfficialTestingLibraryModule(node.source.value)) {
10211025
importedTestingLibraryNodes.push(node);
10221026
}
10231027

10241028
// check only if custom module import not found yet so we avoid
10251029
// to override importedCustomModuleNode after it's found
10261030
const customModule = getCustomModule();
10271031
if (
1028-
customModule &&
10291032
!importedCustomModuleNode &&
1030-
node.source.value.endsWith(customModule)
1033+
isCustomTestingLibraryModule(node.source.value, customModule)
10311034
) {
10321035
importedCustomModuleNode = node;
10331036
}
@@ -1036,7 +1039,7 @@ export function detectTestingLibraryUtils<
10361039
// to override importedUserEventLibraryNode after it's found
10371040
if (
10381041
!importedUserEventLibraryNode &&
1039-
node.source.value === USER_EVENT_PACKAGE
1042+
node.source.value === USER_EVENT_MODULE
10401043
) {
10411044
importedUserEventLibraryNode = node;
10421045
}
@@ -1063,7 +1066,7 @@ export function detectTestingLibraryUtils<
10631066
(arg) =>
10641067
isLiteral(arg) &&
10651068
typeof arg.value === 'string' &&
1066-
/testing-library/g.test(arg.value)
1069+
isOfficialTestingLibraryModule(arg.value)
10671070
)
10681071
) {
10691072
importedTestingLibraryNodes.push(callExpression);
@@ -1074,10 +1077,9 @@ export function detectTestingLibraryUtils<
10741077
!importedCustomModuleNode &&
10751078
args.some(
10761079
(arg) =>
1077-
customModule &&
10781080
isLiteral(arg) &&
10791081
typeof arg.value === 'string' &&
1080-
arg.value.endsWith(customModule)
1082+
isCustomTestingLibraryModule(arg.value, customModule)
10811083
)
10821084
) {
10831085
importedCustomModuleNode = callExpression;
@@ -1089,7 +1091,7 @@ export function detectTestingLibraryUtils<
10891091
(arg) =>
10901092
isLiteral(arg) &&
10911093
typeof arg.value === 'string' &&
1092-
arg.value === USER_EVENT_PACKAGE
1094+
arg.value === USER_EVENT_MODULE
10931095
)
10941096
) {
10951097
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)