Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit183b459

Browse files
feat: add error message for duplicate flags inno-invalid-regexp (#18837)
* feat: add error message to duplicate flags* update error message
1 parentf6fdef9 commit183b459

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

‎lib/rules/no-invalid-regexp.js‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,16 @@ module.exports = {
126126
* Check syntax error in a given flags.
127127
*@param {string|null} flags The RegExp flags to validate.
128128
*@param {string|null} flagsToCheck The RegExp invalid flags.
129+
*@param {string} allFlags all valid and allowed flags.
129130
*@returns {string|null} The syntax error.
130131
*/
131-
functionvalidateRegExpFlags(flags,flagsToCheck){
132-
constflagsToReport=[];
132+
functionvalidateRegExpFlags(flags,flagsToCheck,allFlags){
133+
constduplicateFlags=[];
133134

134-
if(typeofflags==="string"){
135-
for(constflagofflags){
136-
if(flagsToCheck.includes(flag)){
137-
flagsToReport.push(flag);
135+
if(typeofflagsToCheck==="string"){
136+
for(constflagofflagsToCheck){
137+
if(allFlags.includes(flag)){
138+
duplicateFlags.push(flag);
138139
}
139140
}
140141
}
@@ -148,11 +149,15 @@ module.exports = {
148149
return"Regex 'u' and 'v' flags cannot be used together";
149150
}
150151

152+
if(duplicateFlags.length>0){
153+
return`Duplicate flags ('${duplicateFlags.join("")}') supplied to RegExp constructor`;
154+
}
155+
151156
if(!flagsToCheck){
152157
returnnull;
153158
}
154159

155-
return`Invalid flags supplied to RegExp constructor '${flagsToReport.join("")}'`;
160+
return`Invalid flags supplied to RegExp constructor '${flagsToCheck}'`;
156161
}
157162

158163
return{
@@ -171,7 +176,7 @@ module.exports = {
171176
});
172177
}
173178

174-
letmessage=validateRegExpFlags(flags,flagsToCheck);
179+
letmessage=validateRegExpFlags(flags,flagsToCheck,allFlags);
175180

176181
if(message){
177182
report(node,message);

‎tests/lib/rules/no-invalid-regexp.js‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ ruleTester.run("no-invalid-regexp", rule, {
218218
options:[{allowConstructorFlags:["a"]}],
219219
errors:[{
220220
messageId:"regexMessage",
221-
data:{message:"Invalid flags supplied to RegExp constructor 'aa'"},
221+
data:{message:"Duplicate flags('a')supplied to RegExp constructor"},
222222
type:"NewExpression"
223223
}]
224224
},
@@ -227,7 +227,7 @@ ruleTester.run("no-invalid-regexp", rule, {
227227
options:[{allowConstructorFlags:["a","a"]}],
228228
errors:[{
229229
messageId:"regexMessage",
230-
data:{message:"Invalid flags supplied to RegExp constructor 'aa'"},
230+
data:{message:"Duplicate flags('a')supplied to RegExp constructor"},
231231
type:"NewExpression"
232232
}]
233233
},
@@ -245,7 +245,7 @@ ruleTester.run("no-invalid-regexp", rule, {
245245
options:[{allowConstructorFlags:["a","z"]}],
246246
errors:[{
247247
messageId:"regexMessage",
248-
data:{message:"Invalid flags supplied to RegExp constructor 'aa'"},
248+
data:{message:"Duplicate flags('a')supplied to RegExp constructor"},
249249
type:"NewExpression"
250250
}]
251251
},
@@ -254,7 +254,7 @@ ruleTester.run("no-invalid-regexp", rule, {
254254
options:[{allowConstructorFlags:["a","z"]}],
255255
errors:[{
256256
messageId:"regexMessage",
257-
data:{message:"Invalid flags supplied to RegExp constructor 'zz'"},
257+
data:{message:"Duplicate flags('z')supplied to RegExp constructor"},
258258
type:"NewExpression"
259259
}]
260260
},
@@ -263,7 +263,7 @@ ruleTester.run("no-invalid-regexp", rule, {
263263
options:[{allowConstructorFlags:["a"]}],
264264
errors:[{
265265
messageId:"regexMessage",
266-
data:{message:"Invalid flags supplied to RegExp constructor 'aa'"},
266+
data:{message:"Duplicate flags('a')supplied to RegExp constructor"},
267267
type:"NewExpression"
268268
}]
269269
},
@@ -272,7 +272,16 @@ ruleTester.run("no-invalid-regexp", rule, {
272272
options:[{allowConstructorFlags:["u"]}],
273273
errors:[{
274274
messageId:"regexMessage",
275-
data:{message:"Invalid flags supplied to RegExp constructor 'uu'"},
275+
data:{message:"Duplicate flags ('u') supplied to RegExp constructor"},
276+
type:"NewExpression"
277+
}]
278+
},
279+
{
280+
code:"new RegExp('.', 'ouo');",
281+
options:[{allowConstructorFlags:["u"]}],
282+
errors:[{
283+
messageId:"regexMessage",
284+
data:{message:"Invalid flags supplied to RegExp constructor 'oo'"},
276285
type:"NewExpression"
277286
}]
278287
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp