@lvce-editor/eslint-plugin-regex 11.2.0 → 12.0.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.
- package/dist/index.js +16 -16
- package/package.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const isFunctionNode = node => {
|
|
2
|
-
return
|
|
2
|
+
return ['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression'].includes(node.type);
|
|
3
3
|
};
|
|
4
4
|
const isInsideFunction = node => {
|
|
5
5
|
let current = node.parent;
|
|
@@ -30,37 +30,37 @@ const hasOnlyStaticRegexArguments = node => {
|
|
|
30
30
|
return node.arguments.every(isStaticRegexArgument);
|
|
31
31
|
};
|
|
32
32
|
const meta = {
|
|
33
|
-
type: 'suggestion',
|
|
34
33
|
docs: {
|
|
35
34
|
description: 'Enforce hoisting regexes to module scope'
|
|
36
35
|
},
|
|
37
36
|
messages: {
|
|
38
37
|
hoistRegex: 'Regex should be hoisted.'
|
|
39
|
-
}
|
|
38
|
+
},
|
|
39
|
+
type: 'suggestion'
|
|
40
40
|
};
|
|
41
41
|
const create = context => {
|
|
42
42
|
return {
|
|
43
|
-
|
|
44
|
-
if (node.
|
|
43
|
+
CallExpression(node) {
|
|
44
|
+
if (node.callee?.type === 'Identifier' && node.callee.name === 'RegExp' && isInsideFunction(node) && hasOnlyStaticRegexArguments(node)) {
|
|
45
45
|
context.report({
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
messageId: 'hoistRegex',
|
|
47
|
+
node
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
|
-
|
|
52
|
-
if (node.
|
|
51
|
+
Literal(node) {
|
|
52
|
+
if (node.regex && isInsideFunction(node)) {
|
|
53
53
|
context.report({
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
messageId: 'hoistRegex',
|
|
55
|
+
node
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
|
-
|
|
59
|
+
NewExpression(node) {
|
|
60
60
|
if (node.callee?.type === 'Identifier' && node.callee.name === 'RegExp' && isInsideFunction(node) && hasOnlyStaticRegexArguments(node)) {
|
|
61
61
|
context.report({
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
messageId: 'hoistRegex',
|
|
63
|
+
node
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
}
|
|
@@ -74,14 +74,14 @@ const hoistRegex = {
|
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
const plugin = {
|
|
77
|
+
configs: {},
|
|
77
78
|
meta: {
|
|
78
79
|
name: 'regex',
|
|
79
80
|
version: '0.0.1'
|
|
80
81
|
},
|
|
81
82
|
rules: {
|
|
82
83
|
'hoist-regex': hoistRegex
|
|
83
|
-
}
|
|
84
|
-
configs: {}
|
|
84
|
+
}
|
|
85
85
|
};
|
|
86
86
|
const recommended = [{
|
|
87
87
|
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/eslint-plugin-regex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/lvce-editor/eslint-config.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"keywords": [],
|
|
11
10
|
"license": "MIT",
|
|
12
|
-
"description": ""
|
|
11
|
+
"description": "ESLint rules for regex usage."
|
|
13
12
|
}
|