File tree Expand file tree Collapse file tree 9 files changed +84
-0
lines changed Expand file tree Collapse file tree 9 files changed +84
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
27
27
| [ es-x/no-json-modules] ( ./no-json-modules.md ) | disallow JSON Modules. | |
28
28
| [ es-x/no-promise-try] ( ./no-promise-try.md ) | disallow ` Promise.try ` function. | |
29
29
| [ es-x/no-regexp-duplicate-named-capturing-groups] ( ./no-regexp-duplicate-named-capturing-groups.md ) | disallow RegExp duplicate named capturing groups. | |
30
+ | [ es-x/no-regexp-escape] ( ./no-regexp-escape.md ) | disallow ` RegExp.escape ` function. | |
30
31
| [ es-x/no-regexp-modifiers] ( ./no-regexp-modifiers.md ) | disallow RegExp Modifiers. | |
31
32
| [ es-x/no-set-prototype-difference] ( ./no-set-prototype-difference.md ) | disallow the ` Set.prototype.difference ` method. | |
32
33
| [ es-x/no-set-prototype-intersection] ( ./no-set-prototype-intersection.md ) | disallow the ` Set.prototype.intersection ` method. | |
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : " es-x/no-regexp-escape"
3
+ description : " disallow `RegExp.escape` function"
4
+ ---
5
+
6
+ # es-x/no-regexp-escape
7
+ > disallow ` RegExp.escape ` function
8
+
9
+ - ❗ <badge text =" This rule has not been released yet. " vertical =" middle " type =" error " > *** This rule has not been released yet.*** </badge >
10
+ - ✅ The following configurations enable this rule: [ no-new-in-esnext]
11
+
12
+ This rule reports ES2025 [ ` RegExp.escape ` ] ( https://github.com/tc39/proposal-regex-escaping ) as errors.
13
+
14
+ ## 💡 Examples
15
+
16
+ ⛔ Examples of ** incorrect** code for this rule:
17
+
18
+ <eslint-playground type =" bad " >
19
+
20
+ ``` js
21
+ /* eslint es-x/no-regexp-escape: error */
22
+ RegExp .escape (s)
23
+ ```
24
+
25
+ </eslint-playground >
26
+
27
+ ## 📚 References
28
+
29
+ - [ Rule source] ( https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-regexp-escape.js )
30
+ - [ Test source] ( https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-regexp-escape.js )
31
+
32
+ [ no-new-in-esnext ] : ../configs/index.md#no-new-in-esnext
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ module.exports = {
28
28
"es-x/no-json-modules" : "error" ,
29
29
"es-x/no-promise-try" : "error" ,
30
30
"es-x/no-regexp-duplicate-named-capturing-groups" : "error" ,
31
+ "es-x/no-regexp-escape" : "error" ,
31
32
"es-x/no-regexp-modifiers" : "error" ,
32
33
"es-x/no-set-prototype-difference" : "error" ,
33
34
"es-x/no-set-prototype-intersection" : "error" ,
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ module.exports = {
24
24
"es-x/no-json-modules" : "error" ,
25
25
"es-x/no-promise-try" : "error" ,
26
26
"es-x/no-regexp-duplicate-named-capturing-groups" : "error" ,
27
+ "es-x/no-regexp-escape" : "error" ,
27
28
"es-x/no-regexp-modifiers" : "error" ,
28
29
"es-x/no-set-prototype-difference" : "error" ,
29
30
"es-x/no-set-prototype-intersection" : "error" ,
Original file line number Diff line number Diff line change @@ -382,6 +382,7 @@ module.exports = {
382
382
"no-reflect" : require ( "./rules/no-reflect" ) ,
383
383
"no-regexp-d-flag" : require ( "./rules/no-regexp-d-flag" ) ,
384
384
"no-regexp-duplicate-named-capturing-groups" : require ( "./rules/no-regexp-duplicate-named-capturing-groups" ) ,
385
+ "no-regexp-escape" : require ( "./rules/no-regexp-escape" ) ,
385
386
"no-regexp-lookbehind-assertions" : require ( "./rules/no-regexp-lookbehind-assertions" ) ,
386
387
"no-regexp-modifiers" : require ( "./rules/no-regexp-modifiers" ) ,
387
388
"no-regexp-named-capture-groups" : require ( "./rules/no-regexp-named-capture-groups" ) ,
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @author Yosuke Ota
3
+ * See LICENSE file in root directory for full license.
4
+ */
5
+ "use strict"
6
+
7
+ const {
8
+ defineStaticPropertiesHandler,
9
+ } = require ( "../util/define-static-properties-handler" )
10
+
11
+ module . exports = {
12
+ meta : {
13
+ docs : {
14
+ description : "disallow `RegExp.escape` function" ,
15
+ category : "ES2025" ,
16
+ recommended : false ,
17
+ url : "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-regexp-escape.html" ,
18
+ } ,
19
+ fixable : null ,
20
+ messages : {
21
+ forbidden : "ES2025 '{{name}}' is forbidden." ,
22
+ } ,
23
+ schema : [ ] ,
24
+ type : "problem" ,
25
+ } ,
26
+ create ( context ) {
27
+ return defineStaticPropertiesHandler ( context , {
28
+ RegExp : [ "escape" ] ,
29
+ } )
30
+ } ,
31
+ }
Original file line number Diff line number Diff line change @@ -185,6 +185,8 @@ const WELLKNOWN_GLOBALS = {
185
185
prototypeType : "RegExp" ,
186
186
/** @type {Record<import('./types').RegExpProperty,TypeInfo|undefined> } */
187
187
properties : {
188
+ escape : { type : "Function" , return : { type : "String" } } ,
189
+
188
190
"$&" : { type : "String" } ,
189
191
"$'" : { type : "String" } ,
190
192
"$`" : { type : "String" } ,
Original file line number Diff line number Diff line change @@ -395,6 +395,7 @@ const regexpProperties = new Set([
395
395
...functionPrototypeProperties ,
396
396
397
397
// https://tc39.es/ecma262/multipage/text-processing.html#sec-properties-of-the-regexp-constructor
398
+ "escape" ,
398
399
"prototype" ,
399
400
// [ %Symbol.species% ]
400
401
Original file line number Diff line number Diff line change
1
+ "use strict"
2
+
3
+ const RuleTester = require ( "../../tester" )
4
+ const rule = require ( "../../../lib/rules/no-regexp-escape.js" )
5
+
6
+ new RuleTester ( ) . run ( "no-regexp-escape" , rule , {
7
+ valid : [ "RegExp.$1" ] ,
8
+ invalid : [
9
+ {
10
+ code : "RegExp.escape" ,
11
+ errors : [ "ES2025 'RegExp.escape' is forbidden." ] ,
12
+ } ,
13
+ ] ,
14
+ } )
You can’t perform that action at this time.
0 commit comments