989bd36eeb
Co-authored-by: Ven <vendicated@riseup.net>
45 lines
1.9 KiB
Diff
45 lines
1.9 KiB
Diff
diff --git a/lib/rules/no-useless-escape.js b/lib/rules/no-useless-escape.js
|
|
index 2046a148a17fd1d5f3a4bbc9f45f7700259d11fa..f4898c6b57355a4fd72c43a9f32bf1a36a6ccf4a 100644
|
|
--- a/lib/rules/no-useless-escape.js
|
|
+++ b/lib/rules/no-useless-escape.js
|
|
@@ -97,12 +97,30 @@ module.exports = {
|
|
escapeBackslash: "Replace the `\\` with `\\\\` to include the actual backslash character."
|
|
},
|
|
|
|
- schema: []
|
|
+ schema: [{
|
|
+ type: "object",
|
|
+ properties: {
|
|
+ extra: {
|
|
+ type: "string",
|
|
+ default: ""
|
|
+ },
|
|
+ extraCharClass: {
|
|
+ type: "string",
|
|
+ default: ""
|
|
+ },
|
|
+ },
|
|
+ additionalProperties: false
|
|
+ }]
|
|
},
|
|
|
|
create(context) {
|
|
+ const options = context.options[0] || {};
|
|
+ const { extra, extraCharClass } = options || ''
|
|
const sourceCode = context.getSourceCode();
|
|
|
|
+ const NON_CHARCLASS_ESCAPES = union(REGEX_NON_CHARCLASS_ESCAPES, new Set(extra))
|
|
+ const CHARCLASS_ESCAPES = union(REGEX_GENERAL_ESCAPES, new Set(extraCharClass))
|
|
+
|
|
/**
|
|
* Reports a node
|
|
* @param {ASTNode} node The node to report
|
|
@@ -238,7 +256,7 @@ module.exports = {
|
|
.filter(charInfo => charInfo.escaped)
|
|
|
|
// Filter out characters that are valid to escape, based on their position in the regular expression.
|
|
- .filter(charInfo => !(charInfo.inCharClass ? REGEX_GENERAL_ESCAPES : REGEX_NON_CHARCLASS_ESCAPES).has(charInfo.text))
|
|
+ .filter(charInfo => !(charInfo.inCharClass ? CHARCLASS_ESCAPES : NON_CHARCLASS_ESCAPES).has(charInfo.text))
|
|
|
|
// Report all the remaining characters.
|
|
.forEach(charInfo => report(node, charInfo.index, charInfo.text));
|