diff --git a/.eslintrc.js b/.eslintrc.js index 0d0e082404cf..3ebd7093214d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -445,6 +445,8 @@ const base = { 'regexp/confusing-quantifier': 'error', // enforce consistent escaping of control characters 'regexp/control-character-escape': 'error', + // enforce consistent usage of hexadecimal escape + 'regexp/hexadecimal-escape': ['error', 'never'], // enforce into your favorite case 'regexp/letter-case': ['error', { caseInsensitive: 'lowercase', @@ -459,7 +461,7 @@ const base = { // disallow duplicate characters in the RegExp character class 'regexp/no-dupe-characters-character-class': 'error', // disallow duplicate disjunctions - 'regexp/no-dupe-disjunctions': 'error', + 'regexp/no-dupe-disjunctions': ['error', { report: 'all' }], // disallow alternatives without elements 'regexp/no-empty-alternative': 'error', // disallow empty group @@ -468,8 +470,6 @@ const base = { 'regexp/no-empty-lookarounds-assertion': 'error', // disallow escape backspace `([\b])` 'regexp/no-escape-backspace': 'error', - // enforce consistent usage of hexadecimal escape - 'regexp/hexadecimal-escape': ['error', 'never'], // disallow invisible raw character 'regexp/no-invisible-character': 'error', // disallow lazy quantifiers at the end of an expression @@ -486,6 +486,8 @@ const base = { 'regexp/no-optional-assertion': 'error', // disallow backreferences that reference a group that might not be matched 'regexp/no-potentially-useless-backreference': 'error', + // disallow standalone backslashes + 'regexp/no-standalone-backslash': 'error', // disallow trivially nested assertions 'regexp/no-trivially-nested-assertion': 'error', // disallow nested quantifiers that can be rewritten as one quantifier @@ -510,10 +512,14 @@ const base = { 'regexp/no-useless-non-capturing-group': 'error', // disallow unnecessary quantifier non-greedy (`?`) 'regexp/no-useless-non-greedy': 'error', + // disallow quantifiers that can be removed + 'regexp/no-useless-quantifier': 'error', // disallow unnecessary range of characters by using a hyphen 'regexp/no-useless-range': 'error', // disallow unnecessary `{n,m}`` quantifier 'regexp/no-useless-two-nums-quantifier': 'error', + // disallow quantifiers with a maximum of zero + 'regexp/no-zero-quantifier': 'error', // disallow the alternatives of lookarounds that end with a non-constant quantifier 'regexp/optimal-lookaround-quantifier': 'error', // enforces elements order in character class diff --git a/package.json b/package.json index a649ea739dd8..9231885604f8 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "eslint-plugin-jsonc": "^1.2.1", "eslint-plugin-node": "^11.1.0", "eslint-plugin-qunit": "^6.1.0", - "eslint-plugin-regexp": "~0.9.0", + "eslint-plugin-regexp": "~0.10.0", "eslint-plugin-sonarjs": "~0.7.0", "eslint-plugin-unicorn": "^31.0.0", "jsonc-eslint-parser": "^1.0.1", diff --git a/packages/core-js/internals/regexp-exec.js b/packages/core-js/internals/regexp-exec.js index 69869e5959cc..2841e29e08a0 100644 --- a/packages/core-js/internals/regexp-exec.js +++ b/packages/core-js/internals/regexp-exec.js @@ -1,4 +1,6 @@ 'use strict'; +/* eslint-disable regexp/no-assertion-capturing-group, regexp/no-empty-group, regexp/no-lazy-ends -- testing */ +/* eslint-disable regexp/no-useless-quantifier -- testing */ var regexpFlags = require('./regexp-flags'); var stickyHelpers = require('./regexp-sticky-helpers'); var shared = require('./shared'); @@ -19,7 +21,6 @@ var UPDATES_LAST_INDEX_WRONG = (function () { var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y || stickyHelpers.BROKEN_CARET; // nonparticipating capturing group, copied from es5-shim's String#split patch. -// eslint-disable-next-line regexp/no-assertion-capturing-group, regexp/no-empty-group, regexp/no-lazy-ends -- testing var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined; var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED || UNSUPPORTED_Y; diff --git a/tests/compat/tests.js b/tests/compat/tests.js index f7fa120f88f7..75ed49eb3bc3 100644 --- a/tests/compat/tests.js +++ b/tests/compat/tests.js @@ -1,4 +1,4 @@ -/* eslint-disable radix -- required for testing */ +/* eslint-disable radix, regexp/no-assertion-capturing-group, regexp/no-lazy-ends, regexp/no-useless-quantifier -- required for testing */ var GLOBAL = Function('return this')(); var WHITESPACES = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002' + '\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'; @@ -763,7 +763,7 @@ GLOBAL.tests = { re1.exec('a'); re2.exec('a'); return re1.lastIndex === 0 && re2.lastIndex === 0 - // eslint-disable-next-line regexp/no-assertion-capturing-group, regexp/no-empty-group, regexp/no-lazy-ends -- required for testing + // eslint-disable-next-line regexp/no-empty-group -- required for testing && /()??/.exec('')[1] === undefined && reSticky.exec('abc')[0] === 'a' && reSticky.exec('abc') === null