1010
1111const RegExpValidator = require ( "@eslint-community/regexpp" ) . RegExpValidator ;
1212const validator = new RegExpValidator ( ) ;
13- const validFlags = / [ d g i m s u y ] / gu;
13+ const validFlags = / [ d g i m s u v y ] / gu;
1414const undefined1 = void 0 ;
1515
1616//------------------------------------------------------------------------------
@@ -108,12 +108,14 @@ module.exports = {
108108 /**
109109 * Check syntax error in a given pattern.
110110 * @param {string } pattern The RegExp pattern to validate.
111- * @param {boolean } uFlag The Unicode flag.
111+ * @param {Object } flags The RegExp flags to validate.
112+ * @param {boolean } [flags.unicode] The Unicode flag.
113+ * @param {boolean } [flags.unicodeSets] The UnicodeSets flag.
112114 * @returns {string|null } The syntax error.
113115 */
114- function validateRegExpPattern ( pattern , uFlag ) {
116+ function validateRegExpPattern ( pattern , flags ) {
115117 try {
116- validator . validatePattern ( pattern , undefined1 , undefined1 , uFlag ) ;
118+ validator . validatePattern ( pattern , undefined1 , undefined1 , flags ) ;
117119 return null ;
118120 } catch ( err ) {
119121 return err . message ;
@@ -131,10 +133,19 @@ module.exports = {
131133 }
132134 try {
133135 validator . validateFlags ( flags ) ;
134- return null ;
135136 } catch {
136137 return `Invalid flags supplied to RegExp constructor '${ flags } '` ;
137138 }
139+
140+ /*
141+ * `regexpp` checks the combination of `u` and `v` flags when parsing `Pattern` according to `ecma262`,
142+ * but this rule may check only the flag when the pattern is unidentifiable, so check it here.
143+ * https://tc39.es/ecma262/multipage/text-processing.html#sec-parsepattern
144+ */
145+ if ( flags . includes ( "u" ) && flags . includes ( "v" ) ) {
146+ return "Regex 'u' and 'v' flags cannot be used together" ;
147+ }
148+ return null ;
138149 }
139150
140151 return {
@@ -166,8 +177,12 @@ module.exports = {
166177
167178 // If flags are unknown, report the regex only if its pattern is invalid both with and without the "u" flag
168179 flags === null
169- ? validateRegExpPattern ( pattern , true ) && validateRegExpPattern ( pattern , false )
170- : validateRegExpPattern ( pattern , flags . includes ( "u" ) )
180+ ? (
181+ validateRegExpPattern ( pattern , { unicode : true , unicodeSets : false } ) &&
182+ validateRegExpPattern ( pattern , { unicode : false , unicodeSets : true } ) &&
183+ validateRegExpPattern ( pattern , { unicode : false , unicodeSets : false } )
184+ )
185+ : validateRegExpPattern ( pattern , { unicode : flags . includes ( "u" ) , unicodeSets : flags . includes ( "v" ) } )
171186 ) ;
172187
173188 if ( message ) {
0 commit comments