1.0.0 ⢠Published 4 months ago
eslint-plugin-tailwind-rules v1.0.0
eslint-plugin-tailwind-rules
š« ESLint plugin to prevent using px
font sizes in Tailwind CSS. Use rem
or em
instead for better accessibility and responsiveness.
Installation
To install the plugin, run the following command:
npm install --save-dev eslint-plugin-tailwind-rules
Configuration
Once installed, you need to add the plugin to your ESLint configuration.
- In
.eslintrc.js
(or your preferred ESLint config file, such as.eslintrc.json
oreslint.config.js
):
module.exports = {
plugins: ["tailwind-rules"], // Add the plugin
rules: {
"tailwind-rules/no-px-font-size": "warn", // Enable the rule
},
};
- In
.eslintrc.json
:
{
"plugins": ["tailwind-rules"],
"rules": {
"tailwind-rules/no-px-font-size": "warn"
}
}
Rule Options
"tailwind-rules/no-px-font-size": "warn"
: This will trigger a warning whenpx
units are used in Tailwind class names."tailwind-rules/no-px-font-size": "error"
: This will trigger an error whenpx
units are used in Tailwind class names."tailwind-rules/no-px-font-size": "off"
: This will disable the rule.
Example
ā
Correct Usage (using rem
or em
):
<p class="text-[1rem]">This is correct ā
</p>
<p class="text-[1.2rem]">Another correct example ā
</p>
ā Incorrect Usage (using px
):
<p class="text-[16px]">This is incorrect ā</p>
<p class="text-[14px]">Another incorrect example ā</p>
Why use this plugin?
- Accessibility:
rem
(relative to root font size) ensures better scaling for accessibility, as it adapts to the user's settings. - Responsiveness: Using relative units like
rem
andem
makes the layout more flexible and adaptive to different screen sizes and user preferences.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! If you find a bug or want to suggest a feature, feel free to open an issue or submit a pull request.
Links
1.0.0
4 months ago