@builder.io/eslint-plugin-mitosis
Version:
A Mitosis plugin containing rules that help you write valid and idiomatic Mitosis code
57 lines (56 loc) • 2.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var ts_pattern_1 = require("ts-pattern");
var hooks_1 = require("../constants/hooks");
var isMitosisPath_1 = require("../helpers/isMitosisPath");
var noOp_1 = require("../helpers/noOp");
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
var rule = {
meta: {
type: 'problem',
docs: {
description: 'disallow assigning useStore() to a variable with name other than state.',
recommended: true,
},
},
create: function (context) {
// variables should be defined here
var filename = context.getFilename();
if (!(0, isMitosisPath_1.default)(filename))
return {};
// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------
// any helper functions should go here or else delete this section
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
//
var listener = {
CallExpression: function (node) {
(0, ts_pattern_1.match)(node)
.with({
callee: {
name: hooks_1.HOOKS.STORE,
},
parent: {
type: 'VariableDeclarator',
id: {
name: (0, ts_pattern_1.not)('state'),
},
},
}, function (node) {
context.report({
node: node.parent.id,
message: "".concat(hooks_1.HOOKS.STORE, " should be exclusively assigned to a variable called state"),
});
})
.otherwise(noOp_1.default);
},
};
return listener;
},
};
exports.default = rule;