eslint-plugin-mpx 0.2.29 → 0.2.31
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/lib/rules/valid-initdata.js +16 -3
- package/package.json +2 -2
|
@@ -128,6 +128,7 @@ module.exports = {
|
|
|
128
128
|
}
|
|
129
129
|
},
|
|
130
130
|
create(context) {
|
|
131
|
+
const sourceCode = context.getSourceCode()
|
|
131
132
|
// 收集一下initData的属性
|
|
132
133
|
const propsSet = new Set([])
|
|
133
134
|
// 收集computed属性
|
|
@@ -186,13 +187,25 @@ module.exports = {
|
|
|
186
187
|
node.value.value &&
|
|
187
188
|
node.value.value.startsWith('{{')
|
|
188
189
|
if (isattr) {
|
|
189
|
-
|
|
190
|
+
// 使用 sourceCode.getText() 获取完整的属性值文本,支持多行
|
|
191
|
+
const text = sourceCode.getText(node.value)
|
|
192
|
+
const reg = /(?<={{).*?(?=}})/s // 添加 s flag 支持多行匹配
|
|
193
|
+
const match = text.match(reg)
|
|
194
|
+
|
|
195
|
+
// 如果无法匹配到有效的表达式,跳过检查
|
|
196
|
+
if (!match) {
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 提取表达式内容并去除多余的空白字符
|
|
201
|
+
const expression = match[0].trim()
|
|
202
|
+
|
|
190
203
|
checkInInitData(
|
|
191
204
|
computedSet,
|
|
192
205
|
propsSet,
|
|
193
206
|
context,
|
|
194
207
|
node,
|
|
195
|
-
|
|
208
|
+
expression,
|
|
196
209
|
hasInitData
|
|
197
210
|
)
|
|
198
211
|
checkInitData(
|
|
@@ -201,7 +214,7 @@ module.exports = {
|
|
|
201
214
|
hasInitData,
|
|
202
215
|
context,
|
|
203
216
|
node,
|
|
204
|
-
|
|
217
|
+
expression
|
|
205
218
|
)
|
|
206
219
|
}
|
|
207
220
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-mpx",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.31",
|
|
4
4
|
"description": "Official ESLint plugin for Mpx.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"eslint-utils": "^2.1.0",
|
|
53
|
-
"mpx-eslint-parser": "^0.0.
|
|
53
|
+
"mpx-eslint-parser": "^0.0.20",
|
|
54
54
|
"natural-compare": "^1.4.0",
|
|
55
55
|
"semver": "^7.3.2"
|
|
56
56
|
},
|