/** * Tests for: no-any-in-props * * Tests the detection of 'any' type in React component props. */ import { RuleTester } from "@typescript-eslint/rule-tester"; import { describe, it, afterAll } from "vitest"; import rule from "./no-any-in-props.js"; RuleTester.afterAll = afterAll; RuleTester.describe = describe; RuleTester.it = it; const ruleTester = new RuleTester({ languageOptions: { ecmaVersion: 2022, sourceType: "module", parserOptions: { ecmaFeatures: { jsx: true }, }, }, }); ruleTester.run("no-any-in-props", rule, { valid: [ // ============================================ // PROPERLY TYPED PROPS // ============================================ { name: "function with typed props object", code: `function Button(props: { label: string }) { return ; }`, }, { name: "function with destructured typed props", code: `function Button({ label }: { label: string }) { return ; }`, }, { name: "arrow function with typed props", code: `const Button = (props: { label: string }) => ;`, }, { name: "component with multiple props", code: `function Card({ title, content }: { title: string; content: React.ReactNode }) { return
{title}{content}
; }`, }, // ============================================ // USING UNKNOWN TYPE // ============================================ { name: "using unknown for dynamic data", code: `function DataDisplay(props: { data: unknown }) { return
{String(props.data)}
; }`, }, { name: "using unknown in array", code: `function List(props: { items: unknown[] }) { return