Enable this rule if you do not want to accept using classnames that are not defined in Tailwind CSS.
Examples of incorrect code for this rule:
<div class="w-12 my-custom">my-custom is not defined in Tailwind CSS!</div>
Examples of correct code for this rule:
<div class="container box-content lg:box-border">
Only Tailwind CSS classnames
</div>
...
"tailwindcss/no-custom-classname": [<enabled>, {
"callees": Array<string>,
"config": <string>|<object>,
"cssFiles": Array<string>,
"cssFilesRefreshRate": <number>,
"tags": Array<string>,
"whitelist": Array<string>,
}]
...
If you use some utility library like @netlify/classnames-template-literals, you can add its name to the list to make sure it gets parsed by this rule.
For best results, gather the declarative classnames together, avoid mixing conditional classnames in between, move them at the end.
By default the plugin will try to load the file tailwind.config.js
at the root of your project.
This allows the plugin to use your customized colors
, spacing
, screens
...
You can provide another path or filename for your Tailwind CSS config file like "config/tailwind.js"
.
If the external file cannot be loaded (e.g. incorrect path or deleted file), an empty object {}
will be used instead.
It is also possible to directly inject a configuration as plain object
like { prefix: "tw-", theme: { ... } }
.
Finally, the plugin will merge the provided configuration with Tailwind CSS's default configuration.
By default the plugin will now look for any css
files while ignoring files in special folders (node_modules/
, dist/
, build/
folders as well as hidden folders prefixed by a dot e.g. .git/
).
Each css
files will be processed in order to extract the declared classnames in order to accept them.
If you are experiencing performance issues with this plugin, make sure to provide this setting and restrict its value to only parse the correct subset of CSS files. Read more about such cases in PR#92 and PR#93.
The plugin read and parses CSS files which can be a time consuming process depending on your files.
By default, it runs the process if files were updated for at least 5 seconds (5_000
ms) but you can increase this setting to enhance performances while reducing the update interval.
Optional, if you are using tagged templates, you should provide the tags in this array.
The whitelist
is empty by default but you can add custom regular expressions to this array to avoid getting warnings or errors while using your custom classes.
For example, imagine we are using the following custom classnames: skin-summer
, skin-xmas
, custom-1
, custom-2
, custom-3
.
The whitelist
options should be set to:
['skin\\-(summer|xmas)', 'custom\\-[1-3]']
- or if you don't like regular expressions (but you should):
['skin\\-summer', 'skin\\-xmas', 'custom\\-1', 'custom\\-2', 'custom\\-3']
This rule will not fix the issue but will let you know about the issue.