@lvce-editor/eslint-plugin-regex 6.0.0 → 6.2.0

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.
Files changed (2) hide show
  1. package/dist/index.js +20 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11,6 +11,24 @@ const isInsideFunction = node => {
11
11
  }
12
12
  return false;
13
13
  };
14
+ const isStaticRegexArgument = node => {
15
+ if (!node) {
16
+ return true;
17
+ }
18
+ if (node.type === 'Literal') {
19
+ return true;
20
+ }
21
+ if (node.type === 'TemplateLiteral') {
22
+ return node.expressions.length === 0;
23
+ }
24
+ return false;
25
+ };
26
+ const hasOnlyStaticRegexArguments = node => {
27
+ if (!node.arguments || node.arguments.length === 0) {
28
+ return true;
29
+ }
30
+ return node.arguments.every(isStaticRegexArgument);
31
+ };
14
32
  const meta = {
15
33
  type: 'suggestion',
16
34
  docs: {
@@ -31,7 +49,7 @@ const create = context => {
31
49
  }
32
50
  },
33
51
  NewExpression(node) {
34
- if (node.callee?.type === 'Identifier' && node.callee.name === 'RegExp' && isInsideFunction(node)) {
52
+ if (node.callee?.type === 'Identifier' && node.callee.name === 'RegExp' && isInsideFunction(node) && hasOnlyStaticRegexArguments(node)) {
35
53
  context.report({
36
54
  node,
37
55
  messageId: 'hoistRegex'
@@ -39,7 +57,7 @@ const create = context => {
39
57
  }
40
58
  },
41
59
  CallExpression(node) {
42
- if (node.callee?.type === 'Identifier' && node.callee.name === 'RegExp' && isInsideFunction(node)) {
60
+ if (node.callee?.type === 'Identifier' && node.callee.name === 'RegExp' && isInsideFunction(node) && hasOnlyStaticRegexArguments(node)) {
43
61
  context.report({
44
62
  node,
45
63
  messageId: 'hoistRegex'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/eslint-plugin-regex",
3
- "version": "6.0.0",
3
+ "version": "6.2.0",
4
4
  "main": "dist/index.js",
5
5
  "repository": {
6
6
  "type": "git",