UNPKG

@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.33 kB
"use strict"; 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_var_declaration_in_jsx_1 = require("../no-var-declaration-in-jsx"); 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-var-declaration-in-jsx', no_var_declaration_in_jsx_1.default, { valid: [ __assign(__assign({}, opts), { code: "\n export default function MyComponent(props) {\n return (\n <div>\n {a.map(x =>{\n return <span>{x}</span>\n })}\n </div>\n );\n }\n " }), __assign(__assign({}, opts), { code: "\n export default function MyComponent(props) {\n return (\n <div someProp={a.find(b => {\n const {x} = b;\n return x < 1;\n })} />\n );\n }\n " }), __assign(__assign({}, opts), { code: "\n export default function MyComponent(props) {\n return (\n <div>\n {a.map(x =>{\n const foo = \"bar\";\n return <span>{x}</span>\n })}\n </div>\n );\n }\n ", filename: 'file.jsx' }), ], invalid: [ __assign(__assign({}, opts), { code: "\n export default function MyComponent(props) {\n return (\n <div>\n {a.map(x =>{\n const foo = \"bar\";\n return <span>{x}</span>\n })}\n </div>\n );\n }\n ", errors: ['Variable declaration inside jsx is ignored during compilation'] }), ], });