UNPKG

@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.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var ts_pattern_1 = require("ts-pattern"); var isMitosisPath_1 = require("../helpers/isMitosisPath"); var noOp_1 = require("../helpers/noOp"); // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ var rule = { meta: { type: 'problem', docs: { description: 'disallow conditional logic in component render.', 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 = { IfStatement: function (node) { (0, ts_pattern_1.match)(node) .with({ type: 'IfStatement', parent: { type: 'BlockStatement', parent: { type: 'FunctionDeclaration', parent: { type: 'ExportDefaultDeclaration', }, }, }, }, function (node) { context.report({ node: node, message: 'Conditional logic inside components is invalid', }); }) .otherwise(noOp_1.default); }, }; return listener; }, }; exports.default = rule;