You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+91-2Lines changed: 91 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,9 +21,11 @@ module.exports = {
21
21
}
22
22
```
23
23
24
-
## Resolving your Tailwind configuration
24
+
## Options
25
25
26
-
To ensure that the class sorting is taking into consideration any of your project's Tailwind customizations, it needs access to your [Tailwind configuration file](https://tailwindcss.com/docs/configuration) (`tailwind.config.js`).
26
+
### Customizing your Tailwind config path
27
+
28
+
To ensure that the class sorting takes into consideration any of your project's Tailwind customizations, it needs access to your [Tailwind configuration file](https://tailwindcss.com/docs/configuration) (`tailwind.config.js`).
27
29
28
30
By default the plugin will look for this file in the same directory as your Prettier configuration file. However, if your Tailwind configuration is somewhere else, you can specify this using the `tailwindConfig` option in your Prettier configuration.
29
31
@@ -38,6 +40,93 @@ module.exports = {
38
40
39
41
If a local configuration file cannot be found the plugin will fallback to the default Tailwind configuration.
40
42
43
+
## Sorting non-standard attributes
44
+
45
+
By default this plugin only sorts classes in the `class` attribute as well as any framework-specific equivalents like `class`, `className`, `:class`, `[ngClass]`, etc.
46
+
47
+
You can sort additional attributes using the `tailwindAttributes` option, which takes an array of attribute names:
48
+
49
+
```js
50
+
// prettier.config.js
51
+
module.exports= {
52
+
tailwindAttributes: ['myClassList'],
53
+
}
54
+
```
55
+
56
+
With this configuration, any classes found in the `myClassList` attribute will be sorted:
In addition to sorting classes in attributes, you can also sort classes in strings provided to function calls. This is useful when working with libraries like [clsx](https://github.com/lukeed/clsx) or [cva](https://cva.style/).
71
+
72
+
You can sort classes in function calls using the `tailwindFunctions` option, which takes a list of function names:
73
+
74
+
```js
75
+
// prettier.config.js
76
+
module.exports= {
77
+
tailwindFunctions: ['clsx'],
78
+
}
79
+
```
80
+
81
+
With this configuration, any classes in `clsx()` function calls will be sorted:
This plugin uses Prettier APIs that can only be used by one plugin at a time, making it incompatible with other Prettier plugins implemented the same way. To solve this we've added explicit per-plugin workarounds that enable compatibility with the following Prettier plugins:
0 commit comments