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
> Note that `.eslintignore` no longer works in Flat config, see [customization](#customization) for more details.
@@ -80,237 +78,22 @@ Add the following settings to your `.vscode/settings.json`:
80
78
"source.organizeImports":"never"
81
79
},
82
80
83
-
// Silent the stylistic rules in you IDE, but still auto fix them
84
-
"eslint.rules.customizations": [
85
-
{ "rule":"style/*", "severity":"off" },
86
-
{ "rule":"*-indent", "severity":"off" },
87
-
{ "rule":"*-spacing", "severity":"off" },
88
-
{ "rule":"*-spaces", "severity":"off" },
89
-
{ "rule":"*-order", "severity":"off" },
90
-
{ "rule":"*-dangle", "severity":"off" },
91
-
{ "rule":"*-newline", "severity":"off" },
92
-
{ "rule":"*quotes", "severity":"off" },
93
-
{ "rule":"*semi", "severity":"off" }
94
-
],
95
-
96
81
// Enable eslint for all supported languages
97
82
"eslint.validate": [
98
-
"javascript",
99
-
"javascriptreact",
100
-
"typescript",
101
-
"typescriptreact",
102
-
"vue",
103
83
"html",
104
-
"markdown",
84
+
"css",
85
+
"less",
86
+
"scss",
105
87
"json",
106
88
"jsonc",
107
-
"yaml"
89
+
"yaml",
90
+
"yml",
91
+
"markdown",
92
+
"toml"
108
93
]
109
94
}
110
95
```
111
96
112
-
## Customization
113
-
114
-
Since v1.0, we migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides a much better organization and composition.
115
-
116
-
Normally you only need to import the `coderwyd` preset:
117
-
118
-
```js
119
-
// eslint.config.js
120
-
importcoderwydfrom'@coderwyd/eslint-config'
121
-
122
-
exportdefaultcoderwyd()
123
-
```
124
-
125
-
And that's it! Or you can configure each integration individually, for example:
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
139
-
ignores: [
140
-
'./fixtures',
141
-
// ...globs
142
-
]
143
-
})
144
-
```
145
-
146
-
The `coderwyd` factory function also accepts any number of arbitrary custom config overrides:
147
-
148
-
```js
149
-
// eslint.config.js
150
-
importcoderwydfrom'@coderwyd/eslint-config'
151
-
152
-
exportdefaultcoderwyd(
153
-
{
154
-
// Configures for coderwyd's config
155
-
},
156
-
157
-
// From the second arguments they are ESLint Flat Configs
158
-
// you can have multiple configs
159
-
{
160
-
files: ['**/*.ts'],
161
-
rules: {},
162
-
},
163
-
{
164
-
rules: {},
165
-
},
166
-
)
167
-
```
168
-
169
-
Going more advanced, you can also import fine-grained configs and compose them as you wish:
170
-
171
-
```js
172
-
// eslint.config.js
173
-
import {
174
-
astro,
175
-
comments,
176
-
ignores,
177
-
imports,
178
-
javascript,
179
-
jsdoc,
180
-
jsonc,
181
-
markdown,
182
-
node,
183
-
react,
184
-
sortPackageJson,
185
-
sortTsconfig,
186
-
stylistic,
187
-
typescript,
188
-
unicorn,
189
-
vue,
190
-
yaml,
191
-
} from'@coderwyd/eslint-config'
192
-
193
-
exportdefault [
194
-
...astro(),
195
-
...react(),
196
-
...ignores(),
197
-
...javascript(),
198
-
...comments(),
199
-
...node(),
200
-
...jsdoc(),
201
-
...imports(),
202
-
...unicorn(),
203
-
...typescript(),
204
-
...stylistic(),
205
-
...vue(),
206
-
...jsonc(),
207
-
...yaml(),
208
-
...markdown(),
209
-
]
210
-
```
211
-
212
-
Check out the [configs](https://github.com/coderwyd/eslint-config/blob/main/src/configs) and [factory](https://github.com/coderwyd/eslint-config/blob/main/src/factory.ts) for more details.
213
-
214
-
## Plugins Renaming
215
-
216
-
Since flat config requires us to explicitly provide the plugin names (instead of mandatory convention from npm package name), we renamed some plugins to make overall scope more consistent and easier to write.
Certain rules would only be enabled in specific files, for example, `ts/*` rules would only be enabled in `.ts` files and `vue/*` rules would only be enabled in `.vue` files. If you want to override the rules, you need to specify the file extension:
239
-
240
-
```js
241
-
// eslint.config.js
242
-
importcoderwydfrom'@coderwyd/eslint-config'
243
-
244
-
exportdefaultcoderwyd(
245
-
{
246
-
// Enable stylistic formatting rules
247
-
// stylistic: true,
248
-
249
-
// Or customize the stylistic rules
250
-
stylistic: {
251
-
indent:2, // 4, or 'tab'
252
-
quotes:'single', // or 'double'
253
-
},
254
-
255
-
// TypeScript and Vue are auto-detected, you can also explicitly enable them:
256
-
typescript:true,
257
-
vue:true,
258
-
259
-
// Disable jsonc and yaml support
260
-
jsonc:false,
261
-
yaml:false,
262
-
},
263
-
{
264
-
// Remember to specify the file glob here, otherwise it might cause the vue plugin to handle non-vue files
265
-
files: ['**/*.vue'],
266
-
rules: {
267
-
'vue/operator-linebreak': ['error', 'before'],
268
-
},
269
-
},
270
-
{
271
-
// Without `files`, they are general rules for all files
272
-
rules: {
273
-
'style/semi': ['error', 'never'],
274
-
},
275
-
}
276
-
)
277
-
```
278
-
279
-
We also provided an `overrides` options to make it easier:
You can optionally enable the [type aware rules](https://typescript-eslint.io/linting/typed-linting/) by passing the options object to the `typescript` config:
302
-
303
-
```js
304
-
// eslint.config.js
305
-
importcoderwydfrom'@coderwyd/eslint-config'
306
-
307
-
exportdefaultcoderwyd({
308
-
typescript: {
309
-
tsconfigPath:'tsconfig.json',
310
-
},
311
-
})
312
-
```
313
-
314
97
### Lint Staged
315
98
316
99
If you want to apply lint and auto-fix before every commit, you can add the following to your `package.json`:
0 commit comments