Implement getClassOrder
instead of sortClassList
#7459
Merged
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 implements a
getClassOrder
instead ofsortClassList
.Had a conversation with @bradlc and while sorting in Tailwind itself works, it can happen that instead of placing unknown classes in the front that you want to put it in the back. This is an option that we can expose in the
prettier-plugin-tailwindcss
if we event want to do that. But if we want those options in Tailwind itself then we have to keep an options object into account or even more unknown complex scenarios.So instead we will expose a
getSortOrder
that will return a list of tuples with the className and the order it appears in the final css when we generate it.Now the
prettier-plugin-tailwindcss
can sort the classes based on configuration settings in the plugin and using the information we expose via thegetClassOrder
.When a class is passed to the function that doesn't exist, then the sort value will be set to
null
.If we in the future want to change the sort algorithm internally, then we can expose the same list but maybe with different numbers as long as they stay in order.
Remaining questions:
Is the nameRenamed it togetSortOrder
good, or do we prefer something likegetClassOrder
(similar to the already existinggetClassList
)?getClassOrder