[!IMPORTANT] This plugin is a community project and is NOT officially supported by Tailwind Labs.
Format tailwind classes without prettier-plugin-tailwindcss
in class
, className
, cn
, cva
, clsx
and twMerge
.
In my workflow, I use Prettier and Biome differently across various projects. Sometimes, I donβt use either. However, I still want the capability to sort classes, regardless of the project's formatting setup.
prettier-plugin-tailwindcss
.useSortedClass
(still a work in progress).This project provides a way to achieve similar class sorting functionality.
The plugin works with tsx treesitter grammars and provides the following features:
Technically this should work with any other html inherited languages, but need to include relevant treesitter .scm files for it to work. For now, i am using tsx, so it will work with tsx only. Feel free to contribute for more treesitter .scm matching for various filetype like astro, vue, ...
className
, cn
, cva
, clsx
and twMerge
within single repo
or monorepo
className
, cn
, clsx
, twMerge
[!NOTE] Language services like autocompletion, diagnostics and hover are already provided by tailwindcss-language-server.
v0.0.14
(can be installed using Mason)tsx
and your other languages treesitter grammars (using nvim-treesitter)prettier-plugin-tailwindcss
in tailwind config[!TIP] If you are not familiar with neovim LSP ecosystem check out nvim-lspconfig to learn how to setup the LSP.
Using lazy.nvim:
-- tailwind-autosort.lua
return {
"y3owk1n/tailwind-autosort.nvim",
version = "*", -- remove this if you want to follow `main` branch
event = "VeryLazy",
dependencies = { "nvim-treesitter/nvim-treesitter" },
---@type TailwindAutoSort.Config
opts = {} -- your configuration
}
If you are using other package managers you need to call setup
:
require("tailwind-autosort").setup({
-- your configuration
})
Here is the default configuration:
---@class TailwindAutoSort.Config
---@field enable_autocmd? boolean
---@field notify_line_changed? boolean
{
-- enabling autocommand will let tailwind-autosort to update the text at 'BufWritePre'
-- If your editor does format on save after write, it should work together
enable_autocmd = true,
-- This option will notify you number of lines that is affected via vim.notify
notify_line_changed = true,
}
Available commands:
TailwindAutoSortRun
: sorts all classes in the current buffer without saving.TailwindAutoSortResetCache
: reset the cache that saves tailwind config path
and has prettier-plugin-tailwindcss
, useful when you want to change project without re-opening neovim.Here are some related projects:
Read the documentation carefully before submitting any issue.
Feature and pull requests are welcome.