@builder.io/eslint-plugin-mitosis
Version:
A Mitosis plugin containing rules that help you write valid and idiomatic Mitosis code
37 lines (36 loc) • 2.06 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
var eslint_1 = require("eslint");
var no_conditional_logic_in_component_render_1 = require("../no-conditional-logic-in-component-render");
var opts = {
filename: 'component.lite.tsx',
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
ecmaFeatures: {
jsx: true, // Allows for the parsing of JSX
},
},
};
var ruleTester = new eslint_1.RuleTester();
ruleTester.run('no-conditional-logic-in-component-render', no_conditional_logic_in_component_render_1.default, {
valid: [
__assign(__assign({}, opts), { code: "\n export default function MyComponent(props) {\n return (\n <div />\n );\n }\n " }),
__assign(__assign({}, opts), { code: "\n export default function MyComponent(props) {\n useEffect(()=>{\n if (x > 5){\n return foo;\n }\n }, [])\n return (\n <div />\n );\n }\n " }),
__assign(__assign({}, opts), { code: "\n export default function MyComponent(props) {\n if (x > 5) return <div />;\n return (\n <div />\n );\n }\n ", filename: 'file.jsx' }),
],
invalid: [
__assign(__assign({}, opts), { code: "\n export default function MyComponent(props) {\n if (x > 5) return <div />;\n return (\n <div />\n );\n }\n ", errors: ['Conditional logic inside components is invalid'] }),
],
});