Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
prettier-plugin-tailwindcss
Advanced tools
The prettier-plugin-tailwindcss npm package is a plugin for Prettier, the code formatter, that sorts Tailwind CSS classes automatically. It ensures that your Tailwind CSS classes are ordered consistently according to the recommended order from the Tailwind CSS documentation. This can help improve readability and maintainability of your code.
Sorting Tailwind CSS classes
This plugin will reorder the classes to follow the default Tailwind CSS order, for example, positioning classes like 'flex' and 'justify-center' would come before display and box model classes like 'p-4' and 'bg-red-500'.
"<div class='bg-red-500 p-4 flex justify-center'>Hello World</div>"
Headwind is a Visual Studio Code extension that also sorts Tailwind CSS classes automatically. It is similar to prettier-plugin-tailwindcss but is specifically designed for VS Code and does not require Prettier.
This package is a typed utility function to combine Tailwind CSS classes. While it does not sort classes, it provides a way to conditionally join class names together, which can be useful in conjunction with a sorting tool.
tailwind-merge is a utility to merge Tailwind CSS classes without duplicates and with optimized class precedence. It does not sort classes but ensures that the final class string is optimized for Tailwind CSS.
A Prettier plugin for Tailwind CSS v3.0+ that automatically sorts classes based on our recommended class order.
To get started, just install prettier-plugin-tailwindcss
as a dev-dependency:
npm install -D prettier prettier-plugin-tailwindcss
This plugin follows Prettier’s autoloading convention, so as long as you’ve got Prettier set up in your project, it’ll start working automatically as soon as it’s installed.
Note that plugin autoloading is not supported when using certain package managers, such as pnpm or Yarn PnP. In this case you may need to add the plugin to your Prettier config explicitly:
// prettier.config.js
module.exports = {
plugins: [require('prettier-plugin-tailwindcss')],
}
To ensure that the class sorting is taking into consideration any of your project's Tailwind customizations, it needs access to your Tailwind configuration file (tailwind.config.js
).
By default the plugin will look for this file in the same directory as your Prettier configuration file. However, if your Tailwind configuration is somewhere else, you can specify this using the tailwindConfig
option in your Prettier configuration.
Note that paths are resolved relative to the Prettier configuration file.
// prettier.config.js
module.exports = {
tailwindConfig: './styles/tailwind.config.js',
}
If a local configuration file cannot be found the plugin will fallback to the default Tailwind configuration.
This plugin uses Prettier APIs that can only be used by one plugin at a time, making it incompatible with other Prettier plugins implemented the same way. To solve this we've added explicit per-plugin workarounds that enable compatibility with the following Prettier plugins:
@prettier/plugin-php
@prettier/plugin-pug
@shopify/prettier-plugin-liquid
@trivago/prettier-plugin-sort-imports
prettier-plugin-astro
prettier-plugin-css-order
prettier-plugin-import-sort
prettier-plugin-jsdoc
prettier-plugin-organize-attributes
prettier-plugin-organize-imports
prettier-plugin-style-order
prettier-plugin-svelte
prettier-plugin-twig-melody
One limitation with this approach is that prettier-plugin-tailwindcss
must be loaded last, meaning Prettier auto-loading needs to be disabled. You can do this by setting the pluginSearchDirs
option to false
and then listing each of your Prettier plugins in the plugins
array:
// .prettierrc
{
// ..
"plugins": [
"prettier-plugin-svelte",
"prettier-plugin-organize-imports",
"prettier-plugin-tailwindcss" // MUST come last
],
"pluginSearchDirs": false
}
FAQs
A Prettier plugin for sorting Tailwind CSS classes.
We found that prettier-plugin-tailwindcss demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.