eslint-plugin-crisp 1.5.11 → 1.5.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-crisp",
3
- "version": "1.5.11",
3
+ "version": "1.5.12",
4
4
  "description": "Custom ESLint Rules for Crisp",
5
5
  "author": "Crisp IM SAS",
6
6
  "main": "index.js",
@@ -21,20 +21,66 @@ function isUppercaseConstant(declaration) {
21
21
  );
22
22
  }
23
23
 
24
+ function isRegexExpression(node) {
25
+ if (!node) {
26
+ return false;
27
+ }
28
+
29
+ if (
30
+ (node.type === "Literal" && node.regex != null) ||
31
+ node.type === "RegExpLiteral"
32
+ ) {
33
+ return true;
34
+ }
35
+
36
+ if (
37
+ node.type === "NewExpression" &&
38
+ node.callee.type === "Identifier" &&
39
+ node.callee.name === "RegExp"
40
+ ) {
41
+ return true;
42
+ }
43
+
44
+ if (node.type === "ArrayExpression") {
45
+ return node.elements.some(isRegexExpression);
46
+ }
47
+
48
+ if (node.type === "ObjectExpression") {
49
+ return node.properties.some((property) => {
50
+ if (property.type === "Property") {
51
+ return isRegexExpression(property.value);
52
+ }
53
+
54
+ if (property.type === "SpreadElement") {
55
+ return isRegexExpression(property.argument);
56
+ }
57
+
58
+ return false;
59
+ });
60
+ }
61
+
62
+ if (node.type === "SpreadElement") {
63
+ return isRegexExpression(node.argument);
64
+ }
65
+
66
+ if (
67
+ node.type === "TSAsExpression" ||
68
+ node.type === "TSTypeAssertion" ||
69
+ node.type === "TSNonNullExpression"
70
+ ) {
71
+ return isRegexExpression(node.expression);
72
+ }
73
+
74
+ return false;
75
+ }
76
+
24
77
  function isRegex(node) {
25
- if (node.type !== "VariableDeclaration") {
78
+ if (!node || node.type !== "VariableDeclaration") {
26
79
  return false;
27
80
  }
28
81
 
29
82
  for (const declaration of node.declarations) {
30
- if (declaration.init.type === "Literal" && declaration.init.regex != null) {
31
- return true;
32
- }
33
-
34
- if (
35
- declaration.init.type === "NewExpression" &&
36
- declaration.init.callee.name === "RegExp"
37
- ) {
83
+ if (isRegexExpression(declaration.init)) {
38
84
  return true;
39
85
  }
40
86
  }