UNPKG

@builder.io/eslint-plugin-mitosis

Version:

A Mitosis plugin containing rules that help you write valid and idiomatic Mitosis code

45 lines (44 loc) 1.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var types = require("@babel/types"); var isMitosisPath_1 = require("../helpers/isMitosisPath"); // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ var rule = { meta: { type: 'suggestion', docs: { description: '<Show> is preferred over ternary expressions', 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 = { ConditionalExpression: function (node) { if (types.isJSXAttribute(node.parent.parent) && types.isJSXExpressionContainer(node.parent)) return; if (types.isExpressionStatement(node.parent)) return; context.report({ node: node, message: 'Ternary expression support is minimal. Please use the Mitosis `<Show>` component instead.', }); }, }; return listener; }, }; exports.default = rule;