š« ESLint plugin to prevent using px
font sizes in Tailwind CSS. Use rem
or em
instead for better accessibility and responsiveness.
To install the plugin, run the following command:
npm install --save-dev eslint-plugin-tailwind-rules
Once installed, you need to add the plugin to your ESLint configuration.
.eslintrc.js
(or your preferred ESLint config file, such as .eslintrc.json
or eslint.config.js
):module.exports = {
plugins: ["tailwind-rules"], // Add the plugin
rules: {
"tailwind-rules/no-px-font-size": "warn", // Enable the rule
},
};
.eslintrc.json
:{
"plugins": ["tailwind-rules"],
"rules": {
"tailwind-rules/no-px-font-size": "warn"
}
}
"tailwind-rules/no-px-font-size": "warn"
: This will trigger a warning when px
units are used in Tailwind class names."tailwind-rules/no-px-font-size": "error"
: This will trigger an error when px
units are used in Tailwind class names."tailwind-rules/no-px-font-size": "off"
: This will disable the rule.rem
or em
):<p class="text-[1rem]">This is correct ā
</p>
<p class="text-[1.2rem]">Another correct example ā
</p>
px
):<p class="text-[16px]">This is incorrect ā</p>
<p class="text-[14px]">Another incorrect example ā</p>
rem
(relative to root font size) ensures better scaling for accessibility, as it adapts to the user's settings.rem
and em
makes the layout more flexible and adaptive to different screen sizes and user preferences.This project is licensed under the MIT License - see the LICENSE file for details.
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.