Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add responsiveVariants to ignoredKeys by default #336

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/rules/classnames-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ If you use some utility library like [@netlify/classnames-template-literals](htt

For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.

### `ignoredKeys` (default: `["compoundVariants", "defaultVariants"]`)
### `ignoredKeys` (default: `["compoundVariants", "defaultVariants", "responsiveVariants"]`)

Using libraries like `cva`, some of its object keys are not meant to contain classnames in its value(s).
You can specify which key(s) won't be parsed by the plugin using this setting.
For example, `cva` has `compoundVariants` and `defaultVariants`.
For example, `cva` has `compoundVariants` and `defaultVariants`. Also, `tailwind-variants` has `responsiveVariants`.
NB: As `compoundVariants` can have classnames inside its `class` property, you can also use a callee to make sure this inner part gets parsed while its parent is ignored.

### `config` (default: generated by `tailwindcss/lib/lib/load-config`)
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/enforces-negative-arbitrary-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ If you use some utility library like [@netlify/classnames-template-literals](htt

For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.

### `ignoredKeys` (default: `["compoundVariants", "defaultVariants"]`)
### `ignoredKeys` (default: `["compoundVariants", "defaultVariants", "responsiveVariants"]`)

Using libraries like `cva`, some of its object keys are not meant to contain classnames in its value(s).
You can specify which key(s) won't be parsed by the plugin using this setting.
For example, `cva` has `compoundVariants` and `defaultVariants`.
For example, `cva` has `compoundVariants` and `defaultVariants`. Also, `tailwind-variants` has `responsiveVariants`.
NB: As `compoundVariants` can have classnames inside its `class` property, you can also use a callee to make sure this inner part gets parsed while its parent is ignored.

### `config` (default: generated by `tailwindcss/lib/lib/load-config`)
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/enforces-shorthand.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ If you use some utility library like [@netlify/classnames-template-literals](htt

For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.

### `ignoredKeys` (default: `["compoundVariants", "defaultVariants"]`)
### `ignoredKeys` (default: `["compoundVariants", "defaultVariants", "responsiveVariants"]`)

Using libraries like `cva`, some of its object keys are not meant to contain classnames in its value(s).
You can specify which key(s) won't be parsed by the plugin using this setting.
For example, `cva` has `compoundVariants` and `defaultVariants`.
For example, `cva` has `compoundVariants` and `defaultVariants`. Also, `tailwind-variants` has `responsiveVariants`.
NB: As `compoundVariants` can have classnames inside its `class` property, you can also use a callee to make sure this inner part gets parsed while its parent is ignored.

### `config` (default: generated by `tailwindcss/lib/lib/load-config`)
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/migration-from-tailwind-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ If you use some utility library like [@netlify/classnames-template-literals](htt

For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.

### `ignoredKeys` (default: `["compoundVariants", "defaultVariants"]`)
### `ignoredKeys` (default: `["compoundVariants", "defaultVariants", "responsiveVariants"]`)

Using libraries like `cva`, some of its object keys are not meant to contain classnames in its value(s).
You can specify which key(s) won't be parsed by the plugin using this setting.
For example, `cva` has `compoundVariants` and `defaultVariants`.
For example, `cva` has `compoundVariants` and `defaultVariants`. Also, `tailwind-variants` has `responsiveVariants`.
NB: As `compoundVariants` can have classnames inside its `class` property, you can also use a callee to make sure this inner part gets parsed while its parent is ignored.

### `config` (default: generated by `tailwindcss/lib/lib/load-config`)
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-arbitrary-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ If you use some utility library like [@netlify/classnames-template-literals](htt

For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.

### `ignoredKeys` (default: `["compoundVariants", "defaultVariants"]`)
### `ignoredKeys` (default: `["compoundVariants", "defaultVariants", "responsiveVariants"]`)

Using libraries like `cva`, some of its object keys are not meant to contain classnames in its value(s).
You can specify which key(s) won't be parsed by the plugin using this setting.
For example, `cva` has `compoundVariants` and `defaultVariants`.
For example, `cva` has `compoundVariants` and `defaultVariants`. Also, `tailwind-variants` has `responsiveVariants`.
NB: As `compoundVariants` can have classnames inside its `class` property, you can also use a callee to make sure this inner part gets parsed while its parent is ignored.

### `config` (default: generated by `tailwindcss/lib/lib/load-config`)
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-contradicting-classname.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ If you use some utility library like [@netlify/classnames-template-literals](htt

For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.

### `ignoredKeys` (default: `["compoundVariants", "defaultVariants"]`)
### `ignoredKeys` (default: `["compoundVariants", "defaultVariants", "responsiveVariants"]`)

Using libraries like `cva`, some of its object keys are not meant to contain classnames in its value(s).
You can specify which key(s) won't be parsed by the plugin using this setting.
For example, `cva` has `compoundVariants` and `defaultVariants`.
For example, `cva` has `compoundVariants` and `defaultVariants`. Also, `tailwind-variants` has `responsiveVariants`.
NB: As `compoundVariants` can have classnames inside its `class` property, you can also use a callee to make sure this inner part gets parsed while its parent is ignored.

### `config` (default: generated by `tailwindcss/lib/lib/load-config`)
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-custom-classname.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ If you use some utility library like [@netlify/classnames-template-literals](htt

For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.

### `ignoredKeys` (default: `["compoundVariants", "defaultVariants"]`)
### `ignoredKeys` (default: `["compoundVariants", "defaultVariants", "responsiveVariants"]`)

Using libraries like `cva`, some of its object keys are not meant to contain classnames in its value(s).
You can specify which key(s) won't be parsed by the plugin using this setting.
For example, `cva` has `compoundVariants` and `defaultVariants`.
For example, `cva` has `compoundVariants` and `defaultVariants`. Also, `tailwind-variants` has `responsiveVariants`.
NB: As `compoundVariants` can have classnames inside its `class` property, you can also use a callee to make sure this inner part gets parsed while its parent is ignored.

### `config` (default: generated by `tailwindcss/lib/lib/load-config`)
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-unnecessary-arbitrary-value.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ If you use some utility library like [@netlify/classnames-template-literals](htt

For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.

### `ignoredKeys` (default: `["compoundVariants", "defaultVariants"]`)
### `ignoredKeys` (default: `["compoundVariants", "defaultVariants", "responsiveVariants"]`)

Using libraries like `cva`, some of its object keys are not meant to contain classnames in its value(s).
You can specify which key(s) won't be parsed by the plugin using this setting.
For example, `cva` has `compoundVariants` and `defaultVariants`.
For example, `cva` has `compoundVariants` and `defaultVariants`. Also, `tailwind-variants` has `responsiveVariants`.
NB: As `compoundVariants` can have classnames inside its `class` property, you can also use a callee to make sure this inner part gets parsed while its parent is ignored.

### `config` (default: generated by `tailwindcss/lib/lib/load-config`)
Expand Down
2 changes: 1 addition & 1 deletion lib/util/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getOption(context, name) {
case 'callees':
return ['classnames', 'clsx', 'ctl', 'cva', 'tv'];
case 'ignoredKeys':
return ['compoundVariants', 'defaultVariants'];
return ['compoundVariants', 'defaultVariants', 'responsiveVariants'];
case 'classRegex':
return '^class(Name)?$';
case 'config':
Expand Down
72 changes: 72 additions & 0 deletions tests/lib/rules/no-custom-classname.js
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,41 @@ ruleTester.run("no-custom-classname", rule, {
},
],
},
{
code: `
// https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/323
const button = tv(
{
base: "cursor-pointer transition duration-300 ease-in-out disabled:cursor-not-allowed disabled:brightness-50",
defaultVariants: {
color: "green",
size: "md",
},
variants: {
color: {
green:
"bg-green-600 text-zinc-100 hover:bg-green-700 focus:bg-green-700",
red: "bg-red-600 text-zinc-100 hover:bg-red-700 focus:bg-red-700",
sky: "bg-sky-600 text-zinc-100 hover:bg-sky-700 focus:bg-sky-700",
},
size: {
lg: "rounded-md px-6 py-3 text-lg",
md: "rounded-md px-4 py-2 text-base",
sm: "rounded px-2 py-1 text-sm",
},
},
},
{
responsiveVariants: ["sm", "md"],
},
)
`,
options: [
{
callees: ["tv"],
},
],
},
{
code: `
const obj = { a: 12 };
Expand Down Expand Up @@ -1476,6 +1511,43 @@ ruleTester.run("no-custom-classname", rule, {
],
errors: generateErrors("yolo custom"),
},
{
code: `
// https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/323
const button = tv(
{
base: "sushi cursor-pointer transition duration-300 ease-in-out disabled:cursor-not-allowed disabled:brightness-50",
defaultVariants: {
color: "green",
size: "md",
},
variants: {
color: {
green:
"bg-green-600 text-zinc-100 hover:bg-green-700 focus:bg-green-700",
red: "bg-red-600 text-zinc-100 hover:bg-red-700 focus:bg-red-700",
sky: "bg-sky-600 text-zinc-100 hover:bg-sky-700 focus:bg-sky-700",
},
size: {
lg: "rounded-md px-6 py-3 text-lg",
md: "rounded-md px-4 py-2 text-base",
sm: "rounded px-2 py-1 text-sm",
},
},
},
{
responsiveVariants: ["sm", "md"],
},
);
`,
options: [
{
callees: ["tv"],
},
],
// Before #323 is resolved, sm and md in responsiveVariants are also detected as Custom ClassName
errors: generateErrors("sushi"),
},
{
code: `<div className="px-1\u3000py-2">Full-width space between classes</div>`,
errors: generateErrors("px-1\u3000py-2"),
Expand Down