/** * Tests for: prefer-tailwind * * Encourages using Tailwind className over inline style attributes. */ import { RuleTester } from "@typescript-eslint/rule-tester"; import { describe, it, afterAll } from "vitest"; import rule from "./index.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("prefer-tailwind", rule, { valid: [ // ============================================ // TAILWIND ONLY (no style attribute) // ============================================ { name: "all elements use className only", code: ` function Component() { return ( <>

); } `, }, { name: "using class attribute (HTML)", code: ` function Component() { return ( <>

); } `, }, // ============================================ // BOTH STYLE AND CLASSNAME (acceptable) // ============================================ { name: "elements with both style and className are fine", code: ` function Component() { const dynamicColor = 'red'; return ( <>

); } `, }, { name: "mix of className-only and className+style", code: ` function Component() { return ( <>

); } `, }, // ============================================ // BELOW THRESHOLD (not enough elements) // ============================================ { name: "too few styled elements to analyze (default minElements=3)", code: ` function Component() { return ( <>

); } `, }, { name: "single style-only element in file", code: `
`, }, // ============================================ // LOW RATIO (below threshold) // ============================================ { name: "style ratio below threshold (1 style-only out of 4 = 25%)", code: ` function Component() { return ( <>

); } `, }, { name: "exactly at threshold (30%) should not warn", code: ` function Component() { return ( <>