UNPKG

@builder.io/eslint-plugin-mitosis

Version:

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

42 lines (41 loc) 3.12 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 ref_no_current_1 = require("../ref-no-current"); 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('ref-no-current', ref_no_current_1.default, { valid: [ __assign(__assign({}, opts), { code: "\n import { useRef } from '@builder.io/mitosis';\n\n export default function MyComponent(props) {\n const inputRef = useRef();\n const myFn = ()=>{\n inputRef.focus();\n }\n return (\n <div />\n );\n }\n " }), __assign(__assign({}, opts), { code: "\n import { useRef } from '@builder.io/mitosis';\n\n export default function MyComponent(props) {\n const someRef = useRef();\n const myFn = ()=>{\n someRef = 1;\n }\n return (\n <div />\n );\n }\n " }), __assign(__assign({}, opts), { code: "\n import { useRef } from '@builder.io/mitosis';\n\n export default function MyComponent(props) {\n const inputRef = useRef();\n const myFn = ()=>{\n inputRef.current.focus();\n }\n return (\n <div />\n );\n }\n ", filename: 'file.jsx' }), ], invalid: [ __assign(__assign({}, opts), { code: "\n import { useRef } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const inputRef = useRef();\n \n const myFn = ()=>{\n inputRef.current.focus(); \n }\n \n return (\n <div />\n );\n }\n ", errors: [ 'property "current" doesn\'t exists on refs. you can call methods directly on them e.g: inputRef.focus(), or assign them a value e.g: inputRef = 1;', ] }), __assign(__assign({}, opts), { code: "\n import { useRef as useR } from \"@builder.io/mitosis\";\n\n export default function MyComponent(props) {\n const inputRef = useR();\n \n const myFn = ()=>{\n inputRef.current.focus(); \n }\n \n return (\n <div />\n );\n }\n ", errors: [ 'property "current" doesn\'t exists on refs. you can call methods directly on them e.g: inputRef.focus(), or assign them a value e.g: inputRef = 1;', ] }), ], });