Skip to content

Commit c1953a9

Browse files
committed
refactor: review feedback
1 parent 89caf8c commit c1953a9

File tree

8 files changed

+51
-20
lines changed

8 files changed

+51
-20
lines changed

lib/configs/angular.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export = {
1111
'testing-library/no-container': 'error',
1212
'testing-library/no-debugging-utils': 'error',
1313
'testing-library/no-dom-import': ['error', 'angular'],
14-
'testing-library/no-global-regexp-flag-in-query': 'error',
1514
'testing-library/no-node-access': 'error',
1615
'testing-library/no-promise-in-fire-event': 'error',
1716
'testing-library/no-render-in-setup': 'error',

lib/configs/dom.ts

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export = {
88
'testing-library/await-async-query': 'error',
99
'testing-library/await-async-utils': 'error',
1010
'testing-library/no-await-sync-query': 'error',
11-
'testing-library/no-global-regexp-flag-in-query': 'error',
1211
'testing-library/no-promise-in-fire-event': 'error',
1312
'testing-library/no-wait-for-empty-callback': 'error',
1413
'testing-library/no-wait-for-multiple-assertions': 'error',

lib/configs/react.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export = {
1111
'testing-library/no-container': 'error',
1212
'testing-library/no-debugging-utils': 'error',
1313
'testing-library/no-dom-import': ['error', 'react'],
14-
'testing-library/no-global-regexp-flag-in-query': 'error',
1514
'testing-library/no-node-access': 'error',
1615
'testing-library/no-promise-in-fire-event': 'error',
1716
'testing-library/no-render-in-setup': 'error',

lib/configs/vue.ts

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export = {
1212
'testing-library/no-container': 'error',
1313
'testing-library/no-debugging-utils': 'error',
1414
'testing-library/no-dom-import': ['error', 'vue'],
15-
'testing-library/no-global-regexp-flag-in-query': 'error',
1615
'testing-library/no-node-access': 'error',
1716
'testing-library/no-promise-in-fire-event': 'error',
1817
'testing-library/no-render-in-setup': 'error',

lib/node-utils/is-node-of-type.ts

-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ export const isReturnStatement = ASTUtils.isNodeOfType(
5959
export const isFunctionExpression = ASTUtils.isNodeOfType(
6060
AST_NODE_TYPES.FunctionExpression
6161
);
62-
export const isIdentifier = ASTUtils.isNodeOfType(AST_NODE_TYPES.Identifier);

lib/rules/no-global-regexp-flag-in-query.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { TSESTree } from '@typescript-eslint/utils';
1+
import { ASTUtils, TSESTree } from '@typescript-eslint/utils';
22

33
import { createTestingLibraryRule } from '../create-testing-library-rule';
44
import {
55
isMemberExpression,
6-
isIdentifier,
76
isCallExpression,
87
isProperty,
98
isObjectExpression,
@@ -20,10 +19,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
2019
docs: {
2120
description: 'Disallow the use of the global RegExp flag (/g) in queries',
2221
recommendedConfig: {
23-
dom: 'error',
24-
angular: 'error',
25-
react: 'error',
26-
vue: 'error',
22+
dom: false,
23+
angular: false,
24+
react: false,
25+
vue: false,
2726
},
2827
},
2928
messages: {
@@ -53,15 +52,18 @@ export default createTestingLibraryRule<Options, MessageIds>({
5352
if (
5453
isCallExpression(node.parent) &&
5554
isMemberExpression(node.parent.callee) &&
56-
isIdentifier(node.parent.callee.property)
55+
ASTUtils.isIdentifier(node.parent.callee.property)
5756
) {
5857
lint(node, node.parent.callee.property);
5958
}
6059
},
6160
[`CallExpression[callee.type=Identifier] > Literal[regex.flags=/g/].arguments`](
6261
node: TSESTree.Literal
6362
) {
64-
if (isCallExpression(node.parent) && isIdentifier(node.parent.callee)) {
63+
if (
64+
isCallExpression(node.parent) &&
65+
ASTUtils.isIdentifier(node.parent.callee)
66+
) {
6567
lint(node, node.parent.callee);
6668
}
6769
},
@@ -73,7 +75,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
7375
isObjectExpression(node.parent.parent) &&
7476
isCallExpression(node.parent.parent.parent) &&
7577
isMemberExpression(node.parent.parent.parent.callee) &&
76-
isIdentifier(node.parent.parent.parent.callee.property)
78+
ASTUtils.isIdentifier(node.parent.parent.parent.callee.property)
7779
) {
7880
lint(node, node.parent.parent.parent.callee.property);
7981
}

tests/__snapshots__/index.test.ts.snap

-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Object {
1616
"error",
1717
"angular",
1818
],
19-
"testing-library/no-global-regexp-flag-in-query": "error",
2019
"testing-library/no-node-access": "error",
2120
"testing-library/no-promise-in-fire-event": "error",
2221
"testing-library/no-render-in-setup": "error",
@@ -39,7 +38,6 @@ Object {
3938
"testing-library/await-async-query": "error",
4039
"testing-library/await-async-utils": "error",
4140
"testing-library/no-await-sync-query": "error",
42-
"testing-library/no-global-regexp-flag-in-query": "error",
4341
"testing-library/no-promise-in-fire-event": "error",
4442
"testing-library/no-wait-for-empty-callback": "error",
4543
"testing-library/no-wait-for-multiple-assertions": "error",
@@ -65,7 +63,6 @@ Object {
6563
"error",
6664
"react",
6765
],
68-
"testing-library/no-global-regexp-flag-in-query": "error",
6966
"testing-library/no-node-access": "error",
7067
"testing-library/no-promise-in-fire-event": "error",
7168
"testing-library/no-render-in-setup": "error",
@@ -96,7 +93,6 @@ Object {
9693
"error",
9794
"vue",
9895
],
99-
"testing-library/no-global-regexp-flag-in-query": "error",
10096
"testing-library/no-node-access": "error",
10197
"testing-library/no-promise-in-fire-event": "error",
10298
"testing-library/no-render-in-setup": "error",

tests/lib/rules/no-global-regexp-flag-in-query.test.ts

+40-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,38 @@ ruleTester.run(RULE_NAME, rule, {
3737
utils.findByRole('button', {name: /hello/i})
3838
`,
3939
`
40-
const {queryAllByPlaceholderText} = render(<Component/>)
41-
queryAllByPlaceholderText(/hello/i)
40+
const {queryAllByPlaceholderText} = render(<Component/>)
41+
queryAllByPlaceholderText(/hello/i)
42+
`,
43+
`
44+
const text = 'hello';
45+
/hello/g.test(text)
46+
text.match(/hello/g)
47+
`,
48+
`
49+
const text = somethingElse()
50+
/hello/g.test(text)
51+
text.match(/hello/g)
52+
`,
53+
`
54+
import somethingElse from 'somethingElse'
55+
somethingElse.lookup(/hello/g)
56+
`,
57+
`
58+
import { screen } from '@testing-library/dom'
59+
screen.notAQuery(/hello/g)
60+
`,
61+
`
62+
import { screen } from '@testing-library/dom'
63+
screen.notAQuery('button', {name: /hello/g})
64+
`,
65+
`
66+
const utils = render(<Component/>)
67+
utils.notAQuery('button', {name: /hello/i})
68+
`,
69+
`
70+
const utils = render(<Component/>)
71+
utils.notAQuery(/hello/i)
4272
`,
4373
],
4474
invalid: [
@@ -59,6 +89,8 @@ ruleTester.run(RULE_NAME, rule, {
5989
errors: [
6090
{
6191
messageId: 'noGlobalRegExpFlagInQuery',
92+
line: 3,
93+
column: 46,
6294
},
6395
],
6496
},
@@ -69,6 +101,8 @@ ruleTester.run(RULE_NAME, rule, {
69101
errors: [
70102
{
71103
messageId: 'noGlobalRegExpFlagInQuery',
104+
line: 3,
105+
column: 65,
72106
},
73107
],
74108
},
@@ -79,6 +113,8 @@ ruleTester.run(RULE_NAME, rule, {
79113
errors: [
80114
{
81115
messageId: 'noGlobalRegExpFlagInQuery',
116+
line: 3,
117+
column: 47,
82118
},
83119
],
84120
},
@@ -89,6 +125,8 @@ ruleTester.run(RULE_NAME, rule, {
89125
errors: [
90126
{
91127
messageId: 'noGlobalRegExpFlagInQuery',
128+
line: 3,
129+
column: 33,
92130
},
93131
],
94132
},

0 commit comments

Comments
 (0)