UNPKG

eslint-plugin-miniprogram

Version:
42 lines 1.6 kB
"use strict"; /** * @fileoverview Disallow the use of wx.xxSync API */ Object.defineProperty(exports, "__esModule", { value: true }); //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ // whitelisted because there's only sync version var whitelist = ["getLaunchOptionsSync", "getAccountInfoSync"]; exports.isSyncApi = function (propertyName) { return propertyName && propertyName.endsWith("Sync") && !whitelist.find(function (i) { return i === propertyName; }); }; exports.noWxSyncApi = { meta: { type: "suggestion", docs: { description: "Disallow the use of wx.xxSync API", category: "WeChat Mini Program Best Practices", recommended: false, url: "https://github.com/airbnb/eslint-plugin-miniprogram" }, schema: [] }, create: function (context) { return { MemberExpression: function (node) { var objectName = node.object.name; var propertyName = node.property.name; if (objectName === "wx" && !node.computed && exports.isSyncApi(propertyName)) { context.report({ node: node, message: "wx." + propertyName + " may cause performance issue. Use wx." + propertyName.replace(/Sync$/, "") + " instead." }); } } }; } }; //# sourceMappingURL=no-wx-sync-api.js.map