@weapp-vite/eslint 0.2.9 → 0.2.11
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.mjs +35 -2
- package/package.json +6 -5
package/dist/index.mjs
CHANGED
|
@@ -269,6 +269,38 @@ function findWevuCompatibilityEntry(upstream, api, surface) {
|
|
|
269
269
|
return wevuCompatibilityCatalog.find((item) => item.upstream === upstream && item.api === api && (!surface || item.surfaces.includes(surface)));
|
|
270
270
|
}
|
|
271
271
|
//#endregion
|
|
272
|
+
//#region src/runtimeReceiver.ts
|
|
273
|
+
/** 只在接收者有静态证据时选择实例规则;同名业务方法和未知值不归因于内建 API。 */
|
|
274
|
+
function resolveBuiltinReceiver(context, node, seen = /* @__PURE__ */ new Set()) {
|
|
275
|
+
if (!node || seen.has(node)) return;
|
|
276
|
+
seen.add(node);
|
|
277
|
+
if (node.type === "ArrayExpression") return "Array";
|
|
278
|
+
if (node.type === "Literal" && typeof node.value === "string" || node.type === "TemplateLiteral") return "String";
|
|
279
|
+
if ([
|
|
280
|
+
"TSAsExpression",
|
|
281
|
+
"TSSatisfiesExpression",
|
|
282
|
+
"TSNonNullExpression",
|
|
283
|
+
"ChainExpression"
|
|
284
|
+
].includes(node.type)) return resolveBuiltinReceiver(context, node.expression, seen);
|
|
285
|
+
if (node.type !== "Identifier") return;
|
|
286
|
+
let scope = context.sourceCode.getScope(node);
|
|
287
|
+
while (scope) {
|
|
288
|
+
const variable = scope.set?.get(node.name);
|
|
289
|
+
if (variable?.defs?.length) {
|
|
290
|
+
if (variable.defs.length !== 1 || variable.references.some((ref) => ref.isWrite() && !ref.init)) return;
|
|
291
|
+
const definition = variable.defs[0];
|
|
292
|
+
if (definition.type === "Variable" && definition.parent?.kind === "const") return resolveBuiltinReceiver(context, definition.node.init, seen);
|
|
293
|
+
if (definition.type === "Parameter") {
|
|
294
|
+
const annotation = definition.name.typeAnnotation?.typeAnnotation;
|
|
295
|
+
if (annotation?.type === "TSStringKeyword") return "String";
|
|
296
|
+
if (annotation?.type === "TSArrayType" || annotation?.type === "TSTupleType") return "Array";
|
|
297
|
+
}
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
scope = scope.upper;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
272
304
|
//#region src/miniProgramRuntime.ts
|
|
273
305
|
const entry = (value) => value;
|
|
274
306
|
/**
|
|
@@ -417,7 +449,7 @@ function createRuntimeApiRule(entries) {
|
|
|
417
449
|
const globals = new Map(entries.filter((item) => item.kind === "global").map((item) => [item.api, item]));
|
|
418
450
|
const staticMethods = new Map(entries.filter((item) => item.kind === "static-method").map((item) => [item.api, item]));
|
|
419
451
|
const instanceMethods = /* @__PURE__ */ new Map();
|
|
420
|
-
for (const item of entries.filter((item) => item.kind === "instance-method")) instanceMethods.set(item.api
|
|
452
|
+
for (const item of entries.filter((item) => item.kind === "instance-method")) instanceMethods.set(item.api, item);
|
|
421
453
|
return {
|
|
422
454
|
meta: {
|
|
423
455
|
type: "problem",
|
|
@@ -450,7 +482,8 @@ function createRuntimeApiRule(entries) {
|
|
|
450
482
|
return;
|
|
451
483
|
}
|
|
452
484
|
}
|
|
453
|
-
const
|
|
485
|
+
const receiver = resolveBuiltinReceiver(context, node.object);
|
|
486
|
+
const instanceEntry = receiver && instanceMethods.get(`${receiver}.prototype.${property}`);
|
|
454
487
|
if (instanceEntry && node.parent?.type === "CallExpression" && node.parent.callee === node) report(context, node, instanceEntry);
|
|
455
488
|
}
|
|
456
489
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/eslint",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.11",
|
|
5
5
|
"description": "Wevu compatibility ESLint plugin and recommended configuration",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -57,17 +57,18 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@typescript-eslint/parser": "^8.71.
|
|
61
|
-
"eslint": "^10.
|
|
60
|
+
"@typescript-eslint/parser": "^8.71.2",
|
|
61
|
+
"eslint": "^10.13.0",
|
|
62
62
|
"typescript": "^6.0.3",
|
|
63
|
-
"vitest": "^5.0.
|
|
63
|
+
"vitest": "^5.0.5",
|
|
64
64
|
"vue-eslint-parser": "^10.4.1"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"dev": "tsdown -w --sourcemap",
|
|
68
68
|
"build": "tsdown",
|
|
69
69
|
"test": "vitest run --config ./vitest.config.ts",
|
|
70
|
-
"test:types": "
|
|
70
|
+
"test:types": "pnpm run test:types:check",
|
|
71
|
+
"test:types:check": "cd test-d/compatibility-eslint-public-types && tsd",
|
|
71
72
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
72
73
|
"release": "pnpm publish",
|
|
73
74
|
"lint": "eslint .",
|