| pageClass | sidebarDepth | title | description | frameworks | since |
|---|---|---|---|---|---|
rule-details |
0 |
tailwind-variants/require-variants-call-styles-name |
enforce that when calling a function returned by tailwind-variants (tv()), the result is assigned to a variable named styles (or a configurable name) |
agnostic |
v0.1.0 |
enforce that when calling a function returned by tailwind-variants (
tv()), the result is assigned to a variable namedstyles(or a configurable name)
This rule enforces that when you call a function returned by tv() (from tailwind-variants), the result must be assigned to a variable named styles (by default), or to a custom name if configured. This helps ensure consistency and clarity in codebases using tailwind-variants.
{
"tailwind-variants/require-variants-call-styles-name": [
"error",
{
"name": "styles"
}
]
}// ✓ GOOD
const buttonVariants = tv({});
const styles = buttonVariants();// ✓ GOOD
const buttonVariants = tv({});
const variants = buttonVariants();// ✗ BAD
const buttonVariants = tv({});
const styles = buttonVariants();Assigning the result of calling a function returned by tv() to any variable name other than the configured one is not allowed.
// ✗ BAD
const buttonVariants = tv({});
const button = buttonVariants();
const myStyles = buttonVariants();// ✓ GOOD
const buttonVariants = tv({});
const styles = buttonVariants();This rule provides auto-fix functionality. When a variable name assigned from calling a variant function does not match the configured value, the fixer will automatically replace the name.
Before:
const buttonVariants = tv({});
const button = buttonVariants();After auto-fix (with default name):
const buttonVariants = tv({});
const styles = buttonVariants();This rule was introduced in eslint-plugin-tailwind-variants v0.1.0