@@ -83,7 +83,8 @@ tester.run("no-useless-non-capturing-group", rule as any, {
83
83
output : `/abcd/.test(str)` ,
84
84
errors : [
85
85
{
86
- message : "Unexpected quantifier Non-capturing group." ,
86
+ message :
87
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
87
88
line : 1 ,
88
89
column : 2 ,
89
90
endLine : 1 ,
@@ -96,7 +97,8 @@ tester.run("no-useless-non-capturing-group", rule as any, {
96
97
output : `/abcd/v.test(str)` ,
97
98
errors : [
98
99
{
99
- message : "Unexpected quantifier Non-capturing group." ,
100
+ message :
101
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
100
102
line : 1 ,
101
103
column : 2 ,
102
104
endLine : 1 ,
@@ -109,7 +111,8 @@ tester.run("no-useless-non-capturing-group", rule as any, {
109
111
output : `/[abcd]/.test(str)` ,
110
112
errors : [
111
113
{
112
- message : "Unexpected quantifier Non-capturing group." ,
114
+ message :
115
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
113
116
line : 1 ,
114
117
column : 2 ,
115
118
endLine : 1 ,
@@ -120,19 +123,24 @@ tester.run("no-useless-non-capturing-group", rule as any, {
120
123
{
121
124
code : `/(?:ab|cd)/.test(str)` ,
122
125
output : `/ab|cd/.test(str)` ,
123
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
126
+ errors : [
127
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
128
+ ] ,
124
129
} ,
125
130
{
126
131
code : `/a(?:ab|(?:.|a|b))/` ,
127
132
output : `/a(?:ab|.|a|b)/` ,
128
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
133
+ errors : [
134
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
135
+ ] ,
129
136
} ,
130
137
{
131
138
code : `/(?:[abcd]+?)/.test(str)` ,
132
139
output : `/[abcd]+?/.test(str)` ,
133
140
errors : [
134
141
{
135
- message : "Unexpected quantifier Non-capturing group." ,
142
+ message :
143
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
136
144
line : 1 ,
137
145
column : 2 ,
138
146
} ,
@@ -143,12 +151,14 @@ tester.run("no-useless-non-capturing-group", rule as any, {
143
151
output : String . raw `/0/.test(str); /\1(?:0)/.test(str); /1/.test(str); /\1(?:1)/.test(str)` ,
144
152
errors : [
145
153
{
146
- message : "Unexpected quantifier Non-capturing group." ,
154
+ message :
155
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
147
156
line : 1 ,
148
157
column : 2 ,
149
158
} ,
150
159
{
151
- message : "Unexpected quantifier Non-capturing group." ,
160
+ message :
161
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
152
162
line : 1 ,
153
163
column : 42 ,
154
164
} ,
@@ -157,7 +167,9 @@ tester.run("no-useless-non-capturing-group", rule as any, {
157
167
{
158
168
code : String . raw `/(?:a\n)/.test(str)` ,
159
169
output : String . raw `/a\n/.test(str)` ,
160
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
170
+ errors : [
171
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
172
+ ] ,
161
173
} ,
162
174
{
163
175
code : String . raw `
@@ -166,61 +178,83 @@ tester.run("no-useless-non-capturing-group", rule as any, {
166
178
output : String . raw `
167
179
const s = "a\\n"
168
180
;(new RegExp(s)).test(str)` ,
169
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
181
+ errors : [
182
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
183
+ ] ,
170
184
} ,
171
185
{
172
186
code : String . raw `
173
187
const s = "(?:a"+"\\n)"
174
188
;(new RegExp(s)).test(str)` ,
175
189
output : null ,
176
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
190
+ errors : [
191
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
192
+ ] ,
177
193
} ,
178
194
179
195
{
180
196
code : `/(?:a)/.test(str)` ,
181
197
output : `/a/.test(str)` ,
182
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
198
+ errors : [
199
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
200
+ ] ,
183
201
} ,
184
202
{
185
203
code : String ( / (?: a ) + / ) ,
186
204
output : String ( / a + / ) ,
187
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
205
+ errors : [
206
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
207
+ ] ,
188
208
} ,
189
209
{
190
210
code : String . raw `/(?:\w)/.test(str)` ,
191
211
output : String . raw `/\w/.test(str)` ,
192
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
212
+ errors : [
213
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
214
+ ] ,
193
215
} ,
194
216
{
195
217
code : String ( / (?: [ a b c ] ) * / ) ,
196
218
output : String ( / [ a b c ] * / ) ,
197
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
219
+ errors : [
220
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
221
+ ] ,
198
222
} ,
199
223
{
200
224
code : String ( / f o o (?: [ a b c ] * ) b a r / ) ,
201
225
output : String ( / f o o [ a b c ] * b a r / ) ,
202
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
226
+ errors : [
227
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
228
+ ] ,
203
229
} ,
204
230
{
205
231
code : String ( / f o o (?: b a r ) / ) ,
206
232
output : String ( / f o o b a r / ) ,
207
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
233
+ errors : [
234
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
235
+ ] ,
208
236
} ,
209
237
{
210
238
code : `/(?:a|b)/.test(str)` ,
211
239
output : `/a|b/.test(str)` ,
212
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
240
+ errors : [
241
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
242
+ ] ,
213
243
} ,
214
244
{
215
245
code : String ( / a | (?: b | c ) / ) ,
216
246
output : String ( / a | b | c / ) ,
217
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
247
+ errors : [
248
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
249
+ ] ,
218
250
} ,
219
251
{
220
252
code : String ( / a | (?: b | c ) / ) ,
221
253
output : String ( / a | b | c / ) ,
222
254
options : [ { allowTop : "always" } ] ,
223
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
255
+ errors : [
256
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
257
+ ] ,
224
258
} ,
225
259
{
226
260
code : `
@@ -238,7 +272,9 @@ tester.run("no-useless-non-capturing-group", rule as any, {
238
272
// { allowTop: "partial" }
239
273
` ,
240
274
options : [ { allowTop : "partial" } ] ,
241
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
275
+ errors : [
276
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
277
+ ] ,
242
278
} ,
243
279
{
244
280
code : `
@@ -250,7 +286,9 @@ tester.run("no-useless-non-capturing-group", rule as any, {
250
286
` ,
251
287
output : null ,
252
288
options : [ { allowTop : "never" } ] ,
253
- errors : [ "Unexpected quantifier Non-capturing group." ] ,
289
+ errors : [
290
+ "Unexpected unnecessary non-capturing group. This group can be removed without changing the behaviour of the regex." ,
291
+ ] ,
254
292
} ,
255
293
] ,
256
294
} )
0 commit comments