2022-12-20 00:59:54 +02:00
|
|
|
diff --git a/lib/rules/no-useless-escape.js b/lib/rules/no-useless-escape.js
|
2023-08-11 01:14:50 +03:00
|
|
|
index 0e0f6f09f2c35f3276173c08f832cde9f2cf56a0..7dc22851715f3574d935f513c1b5e35552985711 100644
|
2022-12-20 00:59:54 +02:00
|
|
|
--- a/lib/rules/no-useless-escape.js
|
|
|
|
+++ b/lib/rules/no-useless-escape.js
|
2023-08-11 01:14:50 +03:00
|
|
|
@@ -65,13 +65,31 @@ module.exports = {
|
2022-12-20 00:59:54 +02:00
|
|
|
escapeBackslash: "Replace the `\\` with `\\\\` to include the actual backslash character."
|
|
|
|
},
|
2023-08-11 01:14:50 +03:00
|
|
|
|
2022-12-20 00:59:54 +02:00
|
|
|
- schema: []
|
|
|
|
+ schema: [{
|
|
|
|
+ type: "object",
|
|
|
|
+ properties: {
|
|
|
|
+ extra: {
|
|
|
|
+ type: "string",
|
|
|
|
+ default: ""
|
|
|
|
+ },
|
|
|
|
+ extraCharClass: {
|
|
|
|
+ type: "string",
|
|
|
|
+ default: ""
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ additionalProperties: false
|
|
|
|
+ }]
|
|
|
|
},
|
2023-08-11 01:14:50 +03:00
|
|
|
|
2022-12-20 00:59:54 +02:00
|
|
|
create(context) {
|
|
|
|
+ const options = context.options[0] || {};
|
2023-08-11 01:14:50 +03:00
|
|
|
+ const { extra, extraCharClass } = options;
|
|
|
|
const sourceCode = context.sourceCode;
|
|
|
|
const parser = new RegExpParser();
|
|
|
|
|
|
|
|
+ const NON_CHARCLASS_ESCAPES = union(REGEX_NON_CHARCLASS_ESCAPES, new Set(extra));
|
|
|
|
+ const CHARCLASS_ESCAPES = union(REGEX_GENERAL_ESCAPES, new Set(extraCharClass));
|
2022-12-20 00:59:54 +02:00
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Reports a node
|
|
|
|
* @param {ASTNode} node The node to report
|
2023-08-11 01:14:50 +03:00
|
|
|
@@ -200,9 +218,9 @@ module.exports = {
|
|
|
|
let allowedEscapes;
|
|
|
|
|
|
|
|
if (characterClassStack.length) {
|
|
|
|
- allowedEscapes = unicodeSets ? REGEX_CLASSSET_CHARACTER_ESCAPES : REGEX_GENERAL_ESCAPES;
|
|
|
|
+ allowedEscapes = unicodeSets ? REGEX_CLASSSET_CHARACTER_ESCAPES : CHARCLASS_ESCAPES;
|
|
|
|
} else {
|
|
|
|
- allowedEscapes = REGEX_NON_CHARCLASS_ESCAPES;
|
|
|
|
+ allowedEscapes = NON_CHARCLASS_ESCAPES;
|
|
|
|
}
|
|
|
|
if (allowedEscapes.has(escapedChar)) {
|
|
|
|
return;
|