UNPKG

eslint-plugin-miniprogram

Version:
56 lines 2.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var utils_1 = __importDefault(require("eslint-plugin-vue/lib/utils")); var camelCase_1 = __importDefault(require("lodash/camelCase")); var kebabCase_1 = __importDefault(require("lodash/kebabCase")); var snakeCase_1 = __importDefault(require("lodash/snakeCase")); var CASE_MAPPINGS = { camel: camelCase_1.default, kebab: kebabCase_1.default, snake: snakeCase_1.default }; var EVENT_LISTEN = /^(bind|catch|capture-bind|capture-catch):?/; exports.attributeEventNameCase = { meta: { type: "suggestion", docs: { description: "Check event name case", category: "WeChat Mini Program Best Practices", recommended: false, url: "https://github.com/airbnb/eslint-plugin-miniprogram" }, schema: [ { enum: ["camel", "kebab", "snake"] } ] }, create: function (context) { var optionCase = context.options[0] || "camel"; var mapping = CASE_MAPPINGS[optionCase]; if (!mapping) { throw new TypeError("Case type not found"); } return utils_1.default.defineTemplateBodyVisitor(context, { VAttribute: function (node) { var name = node.key.rawName; if (!EVENT_LISTEN.test(name)) { return; } var eventName = name.replace(EVENT_LISTEN, ""); if (mapping(eventName) === eventName) { return; } context.report({ node: node.key, loc: node.loc, message: "Event `" + name + "` should be " + optionCase + " case `" + name.replace(eventName, mapping(eventName)) + "`" }); } }); } }; //# sourceMappingURL=attribute-event-name-case.js.map