Provides elm-review rules to sort and organize Tailwind CSS classes in Elm files for improved readability.
Tailwind.SortAndGroupClasses - Reports unsorted Tailwind classes and provides automatic fixes to organize them into logical groups.module ReviewConfig exposing (config)
import Tailwind.SortAndGroupClasses
import Review.Rule exposing (Rule)
config : List Rule
config =
[ Tailwind.SortAndGroupClasses.rule
]This rule organizes Tailwind CSS classes in Attr.class declarations by:
Attr.class declarations by categoryAttr.class calls: when an attribute list has two or more Attr.class calls, they're combined, regrouped, and moved ahead of any other attributes (which keep their original relative order)dark:hover:bg-gray-700) and the important modifier (!mt-4 / mt-4!)Html.div
[ Attr.class "text-gray-700 mt-4 flex p-2 bg-white rounded-lg hover:bg-gray-50 items-center justify-between w-full shadow-sm border border-gray-200"
]
[]Html.div
[ Attr.class "flex"
, Attr.class "w-full"
, Attr.class "items-center justify-between"
, Attr.class "p-2"
, Attr.class "mt-4"
, Attr.class "text-gray-700"
, Attr.class "bg-white hover:bg-gray-50"
, Attr.class "border border-gray-200 rounded-lg"
, Attr.class "shadow-sm"
]
[]The rendered HTML produces the exact same classes - multiple Attr.class declarations concatenate into a single class attribute.
Classes are sorted into these groups (in order):
block, flex, grid, hidden, table, list-item, etc.)absolute, relative, top-*, z-*, etc.)box-border, box-content)w-*, h-*, max-w-*, etc.)overflow-*, visible, invisible)flex-*, grow-*, shrink-*, basis-*, order-*)grid-cols-*, col-span-*, etc.)justify-*, items-*, content-*, self-*, place-*)gap-*, space-*)p-*, px-*, py-*, etc.)m-*, mx-*, my-*, etc.)text-* size/alignment, font-*, leading-*, align-*, etc.)text-red-*, text-gray-*, etc.)bg-*)border-*, rounded-*, divide-*)ring-*, outline-*)shadow-*)opacity-*)blur-*, brightness-*, filter, filter-none, etc.)scale-*, rotate-*, translate-*)transition-*, duration-*, animate-*)cursor-*, select-*, pointer-events-*, accent-*, appearance-*, etc.)fill-*, stroke-*)sr-only, not-sr-only)Note that Alignment (8, flex/grid alignment) is a distinct group from Flexbox (6) and Grid (7) — flex items-center justify-between becomes two separate Attr.class calls (flex in Layout & Display, items-center justify-between in Alignment), not one merged call. This keeps grouping fully mechanical: every class always lands in exactly one of the 24 categories above, with no case-by-case judgment calls about what "reads better" combined.
Within each group, classes are sorted alphabetically. Variant prefixes are handled by sorting based on the base class, with this prefix order: unprefixed first, then breakpoints (sm, md, lg, xl, 2xl), then states (hover, focus, active, disabled, or any other single-word variant), then dark mode. Stacked variants (e.g. dark:hover:bg-gray-700) are ranked by breakpoint, then dark, then state, regardless of the order the prefixes are written in. The important modifier (!mt-4 or mt-4!) doesn't affect grouping or ordering.
You can try the example configuration above out by running the following command:
elm-review --template cekrem/elm-review-tailwind/exampleSee AI_DISCLOSURE.md.