Allow sorting of custom attributes, functions, and tagged template literals#155
Merged
thecrypticace merged 25 commits intomainfrom May 9, 2023
Merged
Allow sorting of custom attributes, functions, and tagged template literals#155thecrypticace merged 25 commits intomainfrom
thecrypticace merged 25 commits intomainfrom
Conversation
It works when only running the fixtures but not the other tests. Not sure why.
Contributor
|
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 👍 |
This was referenced May 9, 2023
Closed
bronisMateusz
pushed a commit
to bronisMateusz/prettier-plugin-tailwindcss-drupal
that referenced
this pull request
Apr 16, 2025
…terals (tailwindlabs#155) * Add opt-in customization features * Update fixtures * wip * wip * wip * wip * wip * Move parsers/printers/options to bottom of the file * Make fixture formatting async * Run fixture tests in parallel * wip * remove concurrency It works when only running the fixtures but not the other tests. Not sure why. * wip * Tweak prettier config * Simplify fixture * Fix CS * Update readme * Merge defaults instead of replacing them * move fixture * Add Vue fixture * Update changelog * Update options docs in readme * Tweak readme * Show sorted classes in readme * Tweak changelog --------- Co-authored-by: _nderscore <[email protected]> Co-authored-by: Jonathan Reinink <[email protected]>
This file contains hidden or 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
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,
tailwindAttributesandtailwindFunctions, 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
classorclassName, 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 thetailwindAttributesoption in your Prettier configuration file.For example, you can enable sorting of
twattributes 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
tailwindFunctionsoption 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
clsxpackage provides a powerful abstraction to generating a class string built from arrays, objects, and strings. To enable this you add these functions to thetailwindFunctionsoption in your Prettier configuration file.This, in turn, enables sorting of classes in function calls like this, even when not embedded directly inside the
classNameattribute:Closes #133
Closes #127
Closes #126
Closes #121