-
Notifications
You must be signed in to change notification settings - Fork 144
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
Allow sorting of custom attributes, functions, and tagged template literals #155
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It works when only running the fixtures but not the other tests. Not sure why.
Thanks for all your work building on top of my initial idea! ❤️ I like the direction you guys took it - especially how the custom attributes are more generic now and not limited to only React/JSX props 👍 |
reinink
changed the title
Enable sorting of custom attributes, functions, and tagged template literals
Allow sorting of custom attributes, functions, and tagged template literals
May 9, 2023
This was referenced May 9, 2023
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR builds on #127 to add support for sorting custom attributes, functions, and tagged template literals.
To do this we've added two new options to the plugin,
tailwindAttributes
andtailwindFunctions
, which together enable sorting of classes in custom attributes, tagged template literals, and functions that take class lists as arguments.Sorting classes in custom attributes
When using libraries that offer abstractions over
class
orclassName
, or when building your own components that take multiple lists of classes as props, you may want to sort classes in custom attributes. To do this you can specify a list of additional attributes in thetailwindAttributes
option in your Prettier configuration file.For example, you can enable sorting of
tw
attributes like this:Or, if you have a component that takes class lists for different parts of the component, you can enable sorting of those attributes like this:
Sorting classes in tagged template literals
This plugin also enables sorting of classes using tagged template literals. To enable this you specify a list of tag names in the
tailwindFunctions
option in your Prettier configuration file.Tagged template literals are especially useful in React Native where libraries often expose tags as a way to build stylesheets and style components using classes like we do in the browser. Now, with the above config, we can now sort classes in tagged template literals tagged with
tw
, like this:Sorting classes in function calls
The third place where this plugin enables sorting of classes is in function calls. This is useful when you have a function that takes a list of classes as an argument. For example, the very popular
clsx
package provides a powerful abstraction to generating a class string built from arrays, objects, and strings. To enable this you add these functions to thetailwindFunctions
option in your Prettier configuration file.This, in turn, enables sorting of classes in function calls like this, even when not embedded directly inside the
className
attribute:Closes #133
Closes #127
Closes #126
Closes #121