You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+91-15Lines changed: 91 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,47 +69,53 @@ You can can the same information on your favorite command line software as well.
69
69
70
70
## Installation
71
71
72
-
### 1. Install `eslint`
72
+
### 1. Install `eslint` and `eslint-plugin-tailwindcss`
73
73
74
74
You'll first need to install [ESLint](http://eslint.org):
75
75
76
76
```
77
-
$ npm i -D eslint
77
+
$ npm i -D eslint eslint-plugin-tailwindcss
78
+
78
79
```
79
80
80
-
Then, create you `.eslintrc.js` file
81
+
### 2. Create Configuration file
82
+
83
+
#### `.eslintrc`
84
+
85
+
Use .eslintrc.* file to configure rules in ESLint < v9. See also: https://eslint.org/docs/latest/use/configure/.
81
86
82
87
```js
83
88
module.exports= {
84
89
root:true,
90
+
extends: ["plugin:tailwindcss/recommended"],
85
91
};
86
92
```
87
93
88
-
### 2. Install `eslint-plugin-tailwindcss`
94
+
If you would like to know about configuration, Learn more in [ESLint docs](https://eslint.org/docs/latest/use/configure/configuration-files)
89
95
90
-
```
91
-
$ npm i -D eslint-plugin-tailwindcss
92
-
```
93
96
94
-
Edit your `.eslintrc` file to use our [`recommended` preset](https://github.com/francoismassart/eslint-plugin-tailwindcss/blob/master/lib/index.js#L24) to get reasonable defaults:
97
+
#### `eslint.config.js`
98
+
99
+
Use `eslint.config.js` file to configure rules. This is the default in ESLint v9, but can be used starting from ESLint v8.57.0. See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.
95
100
96
101
```js
97
-
module.exports= {
98
-
root:true,
99
-
extends: ["plugin:tailwindcss/recommended"],
100
-
};
101
-
```
102
+
importtailwindfrom"eslint-plugin-tailwindcss";
102
103
103
-
> If you do not use our preset you will need to specify individual rules and add extra configuration...
104
+
exportdefault [
105
+
...tailwind.configs["flat/recommended"],
106
+
];
107
+
```
104
108
105
-
Learn more about [Configuring Rules in ESLint](https://eslint.org/docs/user-guide/configuring/rules).
109
+
If you would like to know about configuration, Learn more in [ESLint docs](https://eslint.org/docs/latest/use/configure/configuration-files-new)
106
110
107
111
### 3. Configure ESLint parsers
108
112
109
113
Depending on the languages you are using in your project you must tell which parser will analyze your source files.
110
114
111
115
Our recommendations:
112
116
117
+
#### For `.eslintrc`
118
+
113
119
- For `js[x]`, `react`, `ts[x]`:
114
120
- Install the parser: `npm i -D @typescript-eslint/parser`
115
121
- Assign it to your files in `eslintrc`:
@@ -146,6 +152,42 @@ Our recommendations:
146
152
147
153
> We removed the default parsers which were added to `v3.8.2` because it created negative impact on dependencies resolution, bundle size increase and possible conflicts with existing configurations.
148
154
155
+
#### For `eslint.config.js`
156
+
157
+
- For `js[x]`, `ts[x]`:
158
+
- Install the parser:`npm i -D @eslint/js typescript-eslint`
159
+
- Assign it to your files in`eslint.config.js`:
160
+
```js
161
+
import js from "@eslint/js";
162
+
import ts from "typescript-eslint";
163
+
import tailwind from "eslint-plugin-tailwindcss";
164
+
165
+
export default [
166
+
// add eslint built-in
167
+
js.configs.recommended,
168
+
// add `typescript-eslint` flat config simply
169
+
// if you would like use more another configuration,
170
+
// see the section: https://typescript-eslint.io/getting-started#details
171
+
...ts.configs.recommended,
172
+
...tailwind.configs["flat/recommended"],
173
+
];
174
+
```
175
+
- For `vue.js`:
176
+
- Install the parser:`npm i -D eslint-plugin-vue`
177
+
- Assign it to your files in`eslint.config.js`:
178
+
```js
179
+
import vue from "eslint-plugin-vue";
180
+
import tailwind from "eslint-plugin-tailwindcss";
181
+
182
+
export default [
183
+
// add `eslint-plugin-vue` flat config simply
184
+
// if you would like use more another configuration,
185
+
// see the section: https://eslint.vuejs.org/user-guide/#bundle-configurations-eslint-config-js
186
+
...vue.configs["flat/recommended"],
187
+
...tailwind.configs["flat/recommended"],
188
+
];
189
+
```
190
+
149
191
### 4. Add a npm script
150
192
151
193
In your `package.json` add one or more script(s) to run eslint targeting your source files:
@@ -174,6 +216,8 @@ You should define the [shared settings](https://eslint.org/docs/user-guide/confi
174
216
175
217
All these settings already have nice default values that are explained in the documentation.
176
218
219
+
#### For `.eslintrc`
220
+
177
221
FYI, here are the `default` values:
178
222
179
223
```json5
@@ -201,6 +245,38 @@ FYI, here are the `default` values:
201
245
}
202
246
```
203
247
248
+
#### For `eslint.config.js`
249
+
250
+
```js
251
+
import tailwind from "eslint-plugin-tailwindcss";
252
+
253
+
export default [
254
+
...tailwind.configs["flat/recommended"],
255
+
{
256
+
settings: {
257
+
tailwindcss: {
258
+
// These are the default values but feel free to customize
259
+
callees: ["classnames", "clsx", "ctl"],
260
+
config: "tailwind.config.js", // returned from `loadConfig()` utility if not provided
261
+
cssFiles: [
262
+
"**/*.css",
263
+
"!**/node_modules",
264
+
"!**/.*",
265
+
"!**/dist",
266
+
"!**/build",
267
+
],
268
+
cssFilesRefreshRate: 5_000,
269
+
removeDuplicates: true,
270
+
skipClassAttribute: false,
271
+
whitelist: [],
272
+
tags: [], // can be set to e.g. ['tw'] for use in tw`bg-blue`
273
+
classRegex: "^class(Name)?$", // can be modified to support custom attributes. E.g. "^tw$" for `twin.macro`
274
+
},
275
+
},
276
+
}
277
+
];
278
+
```
279
+
204
280
The plugin will look for each setting inthis order and stops searching as soon as it finds the settings:
0 commit comments