@builder.io/eslint-plugin-mitosis
Version:
A Mitosis plugin containing rules that help you write valid and idiomatic Mitosis code
43 lines (42 loc) • 5.56 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_var_name_same_as_state_property_1 = require("../no-var-name-same-as-state-property");
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-name-same-as-state-property', no_var_name_same_as_state_property_1.default, {
valid: [
__assign(__assign({}, opts), { code: "\n import { useStore } from '@builder.io/mitosis';\n export default function MyComponent(props) {\n const state = useStore({\n foo: \"bar\"\n })\n const foo_ = bar;\n return (\n <div />\n );\n }\n " }),
__assign(__assign({}, opts), { code: "\n import { useStore } from '@builder.io/mitosis';\n export default function MyComponent(props) {\n const state = useStore({\n foo: 'bar',\n });\n function myFunction() {\n const { foo: foo1 } = props.obj\n state.foo = foo;\n }\n return <div />;\n }\n " }),
__assign(__assign({}, opts), { code: "\n import { useStore } from '@builder.io/mitosis';\n export default function MyComponent(props) {\n const state = useStore({\n foo: \"bar\"\n })\n const foo = bar;\n return (\n <div />\n );\n }\n ", filename: 'file.jsx' }),
],
invalid: [
__assign(__assign({}, opts), { code: "\n import { useStore } from '@builder.io/mitosis';\n\n export default function MyComponent(props) {\n const state = useStore({\n foo: \"bar\"\n })\n\n const foo = bar;\n\n return (\n <div />\n );\n }\n ", errors: ['variables with the same name as a state property will shadow it'] }),
__assign(__assign({}, opts), { code: "\n import { useStore } from '@builder.io/mitosis';\n\n export default function MyComponent(props) {\n const state = useStore({\n foo: 'bar',\n\n abc() {\n const foo = 'baz';\n\n return foo;\n }\n });\n\n return <div />;\n }\n ", errors: ['variables with the same name as a state property will shadow it'] }),
__assign(__assign({}, opts), { code: "\n import { useStore } from '@builder.io/mitosis';\n\n export default function MyComponent(props) {\n const state = useStore({\n foo: 'bar',\n });\n\n function myFunction() {\n const foo = 'some value';\n state.foo = foo;\n }\n\n return <div />;\n }\n ", errors: ['variables with the same name as a state property will shadow it'] }),
__assign(__assign({}, opts), { code: "\n import { useStore } from '@builder.io/mitosis';\n\n export default function MyComponent(props) {\n const state = useStore({\n foo: 'bar',\n });\n\n function myFunction() {\n const { foo } = props.obj\n\n state.foo = foo;\n }\n\n return <div />;\n }\n ", errors: ['variables with the same name as a state property will shadow it'] }),
__assign(__assign({}, opts), { code: "\n import { useStore } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({\n response: 'null',\n saveResponse(response) {\n state.response = response;\n },\n });\n\n return (\n <div>\n Hello\n </div>\n );\n }\n ", errors: ['variables with the same name as a state property will shadow it'] }),
__assign(__assign({}, opts), { code: "\n import { useStore } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({\n response: 'null',\n saveResponse() {\n const bar = (response) => {\n return response;\n }\n },\n });\n\n return (\n <div>\n Hello\n </div>\n );\n }\n ", errors: ['variables with the same name as a state property will shadow it'] }),
__assign(__assign({}, opts), { code: "\n import { useStore } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const state = useStore({\n response: 'null',\n saveResponse() {\n \n function baz(response) {\n return response\n }\n\n },\n });\n \n return (\n <div>\n Hello\n </div>\n );\n }\n ", errors: ['variables with the same name as a state property will shadow it'] }),
],
});