Skip to content

Commit

Permalink
fix: iterateCharacterSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jul 24, 2023
1 parent 4a92050 commit 90b618e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/rules/no-misleading-character-class.js
Expand Up @@ -18,7 +18,7 @@ const { isValidWithUnicodeFlag } = require("./utils/regular-expressions");
*
* CharacterClassRange syntax can steal a part of character sequence,
* so this function reverts CharacterClassRange syntax and restore the sequence.
* @param {regexpp.AST.CharacterClassElement[]} nodes The node list to iterate character sequences.
* @param {import('@eslint-community/regexpp').AST.CharacterClassElement[]} nodes The node list to iterate character sequences.
* @returns {IterableIterator<number[]>} The list of character sequences.
*/
function *iterateCharacterSequence(nodes) {
Expand All @@ -37,6 +37,9 @@ function *iterateCharacterSequence(nodes) {
break;

case "CharacterSet":
case "CharacterClass": // [[]] nesting character class
case "ClassStringDisjunction": // \q{...}
case "ExpressionCharacterClass": // [A--B]
if (seq.length > 0) {
yield seq;
seq = [];
Expand Down
5 changes: 4 additions & 1 deletion tests/lib/rules/no-misleading-character-class.js
Expand Up @@ -74,7 +74,10 @@ ruleTester.run("no-misleading-character-class", rule, {

// ES2024
{ code: "var r = /[πŸ‘]/v", parserOptions: { ecmaVersion: 2024 } },
{ code: String.raw`var r = /^[\q{πŸ‘ΆπŸ»}]$/v`, parserOptions: { ecmaVersion: 2024 } }
{ code: String.raw`var r = /^[\q{πŸ‘ΆπŸ»}]$/v`, parserOptions: { ecmaVersion: 2024 } },
{ code: String.raw`var r = /[πŸ‡―\q{abc}πŸ‡΅]/v`, parserOptions: { ecmaVersion: 2024 } },
{ code: "var r = /[πŸ‡―[A]πŸ‡΅]/v", parserOptions: { ecmaVersion: 2024 } },
{ code: "var r = /[πŸ‡―[A--B]πŸ‡΅]/v", parserOptions: { ecmaVersion: 2024 } }
],
invalid: [

Expand Down

0 comments on commit 90b618e

Please sign in to comment.