Skip to content

Commit cb2ab8e

Browse files
committed
feat: add EVENT_HANDLER_METHODS to no-node-access rule
1 parent 665577c commit cb2ab8e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/rules/no-node-access.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { TSESTree, ASTUtils } from '@typescript-eslint/utils';
22

33
import { createTestingLibraryRule } from '../create-testing-library-rule';
4-
import { ALL_RETURNING_NODES } from '../utils';
4+
import { ALL_RETURNING_NODES, EVENT_HANDLER_METHODS } from '../utils';
55

66
export const RULE_NAME = 'no-node-access';
77
export type MessageIds = 'noNodeAccess';
88
export type Options = [{ allowContainerFirstChild: boolean }];
99

10+
const ALL_PROHIBITED_MEMBERS = [
11+
...ALL_RETURNING_NODES,
12+
...EVENT_HANDLER_METHODS,
13+
] as const;
14+
1015
export default createTestingLibraryRule<Options, MessageIds>({
1116
name: RULE_NAME,
1217
meta: {
@@ -58,7 +63,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
5863

5964
if (
6065
propertyName &&
61-
ALL_RETURNING_NODES.some(
66+
ALL_PROHIBITED_MEMBERS.some(
6267
(allReturningNode) => allReturningNode === propertyName
6368
)
6469
) {

lib/utils/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ const METHODS_RETURNING_NODES = [
114114
'querySelectorAll',
115115
] as const;
116116

117+
const EVENT_HANDLER_METHODS = [
118+
'click',
119+
'focus',
120+
'blur',
121+
'select',
122+
'submit',
123+
] as const;
124+
117125
const ALL_RETURNING_NODES = [
118126
...PROPERTIES_RETURNING_NODES,
119127
...METHODS_RETURNING_NODES,
@@ -147,4 +155,5 @@ export {
147155
ALL_RETURNING_NODES,
148156
PRESENCE_MATCHERS,
149157
ABSENCE_MATCHERS,
158+
EVENT_HANDLER_METHODS,
150159
};

0 commit comments

Comments
 (0)