You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.9 KiB
50 lines
1.9 KiB
2 years ago
|
diff --git a/lib/rules/no-useless-escape.js b/lib/rules/no-useless-escape.js
|
||
1 year ago
|
index 0e0f6f09f2c35f3276173c08f832cde9f2cf56a0..7dc22851715f3574d935f513c1b5e35552985711 100644
|
||
2 years ago
|
--- a/lib/rules/no-useless-escape.js
|
||
|
+++ b/lib/rules/no-useless-escape.js
|
||
1 year ago
|
@@ -65,13 +65,31 @@ module.exports = {
|
||
2 years ago
|
escapeBackslash: "Replace the `\\` with `\\\\` to include the actual backslash character."
|
||
|
},
|
||
1 year ago
|
|
||
2 years ago
|
- schema: []
|
||
|
+ schema: [{
|
||
|
+ type: "object",
|
||
|
+ properties: {
|
||
|
+ extra: {
|
||
|
+ type: "string",
|
||
|
+ default: ""
|
||
|
+ },
|
||
|
+ extraCharClass: {
|
||
|
+ type: "string",
|
||
|
+ default: ""
|
||
|
+ },
|
||
|
+ },
|
||
|
+ additionalProperties: false
|
||
|
+ }]
|
||
|
},
|
||
1 year ago
|
|
||
2 years ago
|
create(context) {
|
||
|
+ const options = context.options[0] || {};
|
||
1 year ago
|
+ 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));
|
||
2 years ago
|
+
|
||
|
/**
|
||
|
* Reports a node
|
||
|
* @param {ASTNode} node The node to report
|
||
1 year ago
|
@@ -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;
|