A VS Code extension that automatically sorts Tailwind CSS classes using RustyWind or the built-in experimental internal sorter.
When using the default RustyWind sorter, the extension can detect and sort Tailwind classes within specified function calls. By default, it supports:
cn
(for class-variance-authority + tailwind-merge pattern)cva
(class-variance-authority)clsx
You can add your own function names through the tailwindSorter.tailwindFunctions
setting.
Example usage with the cn
function:
className={cn(
"flex items-center text-nowrap",
isActive && "font-bold",
isPending && "pointer-events-none"
)}
Version 1.2.0 introduces AST-based class detection for more reliable and comprehensive Tailwind class sorting. The extension now properly handles:
className={`px-4 ${condition ? "pt-2" : "pb-2"}`}
className={cn("px-4", condition && "pt-2")}
className={condition ? "px-4" : "py-2"}
className={cn({ "px-4": isActive })}
border-(--custom-color)
This provides much more reliable sorting across complex component structures.
Version 1.3.0 introduces an experimental built-in Rust-based WebAssembly sorter as an alternative to using RustyWind. The internal sorter provides class sorting functionality without requiring any external dependencies.
tailwindFunctions
setting; instead identifies potential Tailwind classes based on patternsTo enable the internal sorter:
true
The status bar indicator will display "Tailwind Sorter (Internal)" when the internal sorter is active.
The extension can now function in two modes:
🚨 RustyWind is required but NOT included when using the default sorter. If you're using the default sorting mode, you must install RustyWind separately.
yarn add rustywind --dev
yarn add -g rustywind
When the internal sorter is enabled, there are no external dependencies required. Simply enable it in the settings to start using it immediately.
This extension contributes the following settings:
"tailwindSorter.enable": {
"type": "boolean",
"default": true,
"description": "Enable/disable Tailwind class sorting"
},
"tailwindSorter.includeFiles": {
"type": "array",
"default": [
"**/*.{js,jsx,ts,tsx,html}"
],
"description": "Files to include for class sorting"
},
"tailwindSorter.languageIds": {
"type": "array",
"default": ["typescript", "typescriptreact", "javascript", "javascriptreact", "html"],
"description": "Language IDs for which this extension should be active"
}
"tailwindSorter.customBinaryPath": {
"type": "string",
"default": "",
"description": "Custom path to RustyWind binary. Supports workspace variables like ${workspaceFolder}."
},
"tailwindSorter.debug": {
"type": "boolean",
"default": false,
"description": "Enable debug logging in the output channel"
},
"tailwindSorter.tailwindFunctions": {
"type": "array",
"default": ["cn", "cva", "clsx"],
"description": "List of function names that contain Tailwind classes as arguments"
}
"tailwindSorter.internalSorter.enabled": {
"type": "boolean",
"default": false,
"description": "Use the experimental internal Tailwind class sorter instead of Rustywind"
},
"tailwindSorter.internalSorter.debug": {
"type": "boolean",
"default": false,
"description": "Enable additional debug logging for the internal sorter"
},
"tailwindSorter.internalSorter.removeDuplicateClasses": {
"type": "boolean",
"default": true,
"description": "Remove duplicate Tailwind classes, keeping only the last occurrence (only applies when using internal sorter)"
},
"tailwindSorter.internalSorter.normalizeWhitespace": {
"type": "boolean",
"default": true,
"description": "Normalize whitespace between classes (only applies when using internal sorter)"
}
The extension provides the following commands:
If using the default RustyWind sorter and RustyWind is not installed, the extension will display an error message notifying you that it is required. Ensure that you have installed RustyWind either globally or locally in your project for this mode to function correctly.
# Clone the repository
git clone https://github.com/Digital-Magistery-Software/tailwind-class-sorter.git
# Install dependencies
yarn install
# Build the extension (WASM + TypeScript)
yarn build
The yarn build
command will:
build:wasm
script which uses wasm-pack to compile the Rust code to WebAssemblywasm
directoryyarn build:wasm
to rebuild the WebAssembly componentyarn compile
to rebuild the TypeScript code (or use yarn watch
for continuous compilation)F5
in VS Code to launch the extension in debug modeThis project is licensed under the MIT License.