@builder.io/eslint-plugin-mitosis
Version:
A Mitosis plugin containing rules that help you write valid and idiomatic Mitosis code
38 lines (37 loc) • 2.88 kB
JavaScript
"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_setter_with_same_name_as_state_prop_1 = require("../no-setter-with-same-name-as-state-prop");
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-setter-with-same-name-as-state-prop', no_setter_with_same_name_as_state_prop_1.default, {
valid: [
__assign(__assign({}, opts), { code: "\n import { useStore } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({\n nameFoo: 'foo',\n getName() {\n const name = props.name_ || 'hello'\n return name + ' world'\n }\n });\n \n return (\n <div>\n {state.getName()}\n </div>\n );\n }\n " }),
__assign(__assign({}, opts), { code: "\n import { useStore } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({\n getName() {\n const name = props.name || 'hello'\n return name + ' world'\n }\n });\n \n return (\n <div>\n {state.getName()}\n </div>\n );\n }\n ", filename: 'file.jsx' }),
],
invalid: [
__assign(__assign({}, opts), { code: "\nimport { useState } from \"@builder.io/mitosis\";\nimport { x } from 'lodash'\n\nexport default function MyComponent(props) {\n const state = useStore({\n a: 123,\n b: { c: 'fdsa' },\n foo: \"Steve\",\n setFoo(x) {\n state.foo = x;\n }\n });\n\n return (\n <div>\n <input\n css={{\n color: \"red\",\n }}\n value={x(name)}\n onChange={(event) => setName(event.target.value)}\n />\n Hello! I can run natively in React, Vue, Svelte, Qwik, and many more frameworks!\n </div>\n );\n}\n ", errors: [
'Cannot name a state property `setFoo` because of a collision with Mitosis-generated code for the state property `foo`. Please use a different name.',
] }),
],
});