UNPKG

@builder.io/eslint-plugin-mitosis

Version:

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

36 lines (35 loc) 1.88 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_state_destructuring_1 = require("../no-state-destructuring"); 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-state-destructuring', no_state_destructuring_1.default, { valid: [ __assign(__assign({}, opts), { code: "\n export default function MyComponent() {\n const state = useStore({ foo: '1' });\n \n onMount(() => {\n const foo = state.foo;\n });\n } \n " }), __assign(__assign({}, opts), { code: "\n export default function MyComponent() {\n const state = useStore({ foo: '1' });\n \n onMount(() => {\n const { foo } = state;\n });\n }\n ", filename: 'file.jsx' }), ], invalid: [ __assign(__assign({}, opts), { code: "\n export default function MyComponent() {\n const state = useStore({ foo: '1' });\n \n onMount(() => {\n const { foo } = state;\n });\n }\n ", errors: ["destructuring state isn't allowed: use standard assignment instead"] }), ], });