@lincy/eslint-config 3.0.11 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,9 +24,9 @@ pnpm add -D eslint @lincy/eslint-config
24
24
 
25
25
  ```js
26
26
  // eslint.config.js
27
- import eslintConfig from '@lincy/eslint-config'
27
+ import lincy from '@lincy/eslint-config'
28
28
 
29
- export default eslintConfig()
29
+ export default lincy()
30
30
  ```
31
31
 
32
32
  > 通常您不需要`.eslintignore`,因为它已由预设提供。
@@ -99,47 +99,98 @@ For example:
99
99
 
100
100
  ## 定制化
101
101
 
102
- 通常你只需要导入 `eslintConfig` 预设:
102
+ 通常你只需要导入 `lincy` 预设:
103
103
 
104
+ #### esm
104
105
  ```js
105
106
  // eslint.config.js
106
- import eslintConfig from '@lincy/eslint-config'
107
+ import lincy from '@lincy/eslint-config'
107
108
 
108
- export default eslintConfig()
109
+ // or
110
+ // import { lincy } from '@lincy/eslint-config'
111
+
112
+ export default lincy()
113
+ ```
114
+
115
+ #### cjs
116
+ ```js
117
+ // eslint.config.js
118
+ const lincy = require('@lincy/eslint-config').lincy
119
+
120
+ module.exports = lincy()
109
121
  ```
110
122
 
111
123
  您可以单独配置每个功能,例如:
112
124
 
113
125
  ```js
114
126
  // eslint.config.js
115
- import eslintConfig from '@lincy/eslint-config'
116
-
117
- export default eslintConfig({
118
- stylistic: true, // enable stylistic formatting rules
119
- typescript: true,
120
- vue: true,
121
- jsonc: false,
122
- yml: false,
127
+ import lincy from '@lincy/eslint-config'
128
+
129
+ export default lincy({
130
+ // 是否启用 stylistic 格式化规则
131
+ stylistic: true, // 默认值: true
132
+ // 是否启用 typescript 规则
133
+ typescript: true, // 默认值: 检测是否安装typescript依赖
134
+ // 是否启用 vue 规则
135
+ vue: true, // 默认值: 检测是否安装vue依赖
136
+ // 是否启用 jsonc 规则
137
+ jsonc: false, // 默认值: 检测是否安装typescript依赖
138
+ // 是否启用 yaml 规则
139
+ yaml: false, // 默认值: true
140
+ // 是否启用 .gitignore 文件
141
+ gitignore: false, // 默认值: true
142
+ // 是否启用 test 规则
143
+ test: false, // 默认值: true
144
+ // 是否启用 markdown 规则
145
+ markdown: false, // 默认值: true
123
146
  })
124
147
  ```
125
148
 
126
- `eslintConfig` 工厂函数还接受任意数量的自定义配置覆盖:
149
+ `lincy` 工厂函数还接受任意数量的自定义配置覆盖:
127
150
 
128
151
  ```js
129
152
  // eslint.config.js
130
- import eslintConfig from '@lincy/eslint-config'
153
+ import { readFile } from 'node:fs/promises'
154
+ import lincy from '@lincy/eslint-config'
155
+ import plugin from '@unocss/eslint-plugin'
156
+
157
+ const autoImport = JSON.parse(
158
+ await readFile(new URL('./.eslintrc-auto-import.json', import.meta.url)),
159
+ )
131
160
 
132
- export default eslintConfig(
161
+ export default lincy(
133
162
  {
134
163
  // Configures for config
135
164
  },
136
-
137
- // From the second arguments they are ESLint Flat Configs
138
- // you can have multiple configs
165
+ // 启用 unocss
139
166
  {
140
- rules: {},
167
+ plugins: {
168
+ '@unocss': plugin,
169
+ },
170
+ rules: {
171
+ ...plugin.configs.recommended.rules,
172
+ '@unocss/order': 'off',
173
+ },
174
+ },
175
+ // 启用 auto-import 生成的 .eslintrc-auto-import.json
176
+ {
177
+ languageOptions: {
178
+ globals: {
179
+ ...autoImport.globals,
180
+ // 其他 globals
181
+ },
182
+ },
141
183
  },
184
+ // 自定义排除文件(夹)
142
185
  {
186
+ ignores: [
187
+ '**/assets',
188
+ '**/static',
189
+ ],
190
+ },
191
+ // 你还可以继续配置多个 ESLint Flat Configs
192
+ {
193
+ files: ['**/*.ts'],
143
194
  rules: {},
144
195
  },
145
196
  )
@@ -154,36 +205,34 @@ import {
154
205
  ignores,
155
206
  imports,
156
207
  javascript,
157
- javascriptStylistic,
158
208
  jsdoc,
159
209
  jsonc,
160
210
  markdown,
161
211
  node,
162
212
  sortPackageJson,
163
213
  sortTsconfig,
214
+ stylistic,
164
215
  typescript,
165
- typescriptStylistic,
166
216
  unicorn,
167
217
  vue,
168
- yml,
218
+ yaml,
169
219
  } from '@lincy/eslint-config'
170
220
 
171
221
  export default [
172
- ...ignores,
222
+ ...ignores(),
173
223
  ...javascript(),
174
- ...comments,
175
- ...node,
176
- ...jsdoc,
177
- ...imports,
178
- ...unicorn,
179
- ...javascriptStylistic,
224
+ ...comments(),
225
+ ...node(),
226
+ ...jsdoc(),
227
+ ...imports(),
228
+ ...unicorn(),
180
229
 
181
230
  ...typescript(),
182
- ...typescriptStylistic,
231
+ ...stylistic(),
183
232
 
184
233
  ...vue(),
185
- ...jsonc,
186
- ...yml,
234
+ ...jsonc(),
235
+ ...yaml(),
187
236
  ...markdown(),
188
237
  ]
189
238
  ```
@@ -196,13 +245,13 @@ export default [
196
245
 
197
246
  由于平面配置支持显式提供了插件名称,因此我们重命名了一些插件以使它们更加一致并隐藏实现细节。
198
247
 
199
- | Original Prefix | New Prefix | Source Plugin |
200
- | --------------- | ---------- | ------------- |
201
- | `i/*` | `import/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
202
- | `n/*` | `node` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n)
203
- | `@typescript-eslint/*` | `ts/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
204
- | `@stylistic/js` | `style/*` | [@stylistic/eslint-plugin-js](https://github.com/eslint-stylistic/eslint-stylistic) |
205
- | `@stylistic/ts` | `style-ts/` | [@stylistic/eslint-plugin-ts](https://github.com/eslint-stylistic/eslint-stylistic) |
248
+ | New Prefix | Original Prefix | Source Plugin |
249
+ | --- | --- | --- |
250
+ | `import/*` | `i/*` | [eslint-plugin-i](https://github.com/un-es/eslint-plugin-i) |
251
+ | `node/*` | `n/*` | [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) |
252
+ | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
253
+ | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
254
+ | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
206
255
 
207
256
  当您想要覆盖规则或内联禁用它们时,您需要更新到新的前缀:
208
257
 
@@ -212,15 +261,69 @@ export default [
212
261
  type foo = { bar: 2 }
213
262
  ```
214
263
 
264
+ ### Rules Overrides
265
+
266
+ 某些规则仅在特定文件中启用,例如,“ts/*”规则仅在“.ts”文件中启用,“vue/*”规则仅在“.vue”文件中启用。 如果要覆盖规则,则需要指定文件扩展名:
267
+
268
+ ```js
269
+ // eslint.config.js
270
+ import antfu from '@antfu/eslint-config'
271
+
272
+ export default antfu(
273
+ { vue: true, typescript: true },
274
+ {
275
+ // 记得在这里指定文件 glob,否则可能会导致 vue 插件处理非 vue 文件
276
+ files: ['**/*.vue'],
277
+ rules: {
278
+ 'vue/operator-linebreak': ['error', 'before'],
279
+ },
280
+ },
281
+ {
282
+ // 如果没有 `files`,它们是所有文件的通用规则
283
+ rules: {
284
+ 'style/semi': ['error', 'never'],
285
+ },
286
+ }
287
+ )
288
+ ```
289
+
290
+ 还可以使用“overrides”选项以使其更容易:
291
+
292
+ ```js
293
+ // eslint.config.js
294
+ import antfu from '@antfu/eslint-config'
295
+
296
+ export default antfu({
297
+ overrides: {
298
+ vue: {
299
+ 'vue/operator-linebreak': ['error', 'before'],
300
+ },
301
+ typescript: {
302
+ 'ts/consistent-type-definitions': ['error', 'interface'],
303
+ },
304
+ javascript: {},
305
+ stylistic: {
306
+ 'antfu/consistent-list-newline': 'off',
307
+ },
308
+ yaml: {},
309
+ ignores: [
310
+ '**/assets',
311
+ '**/static',
312
+ ]
313
+ // ...
314
+ }
315
+ })
316
+ ```
317
+
215
318
  ### Type Aware Rules
216
319
 
217
320
  您可以选择通过将选项对象传递给“typescript”配置来启用[类型感知规则](https://typescript-eslint.io/linting/typed-linting/):
218
321
 
219
322
  ```js
220
323
  // eslint.config.js
221
- import eslintConfig from '@lincy/eslint-config'
324
+ import lincy from '@lincy/eslint-config'
222
325
 
223
- export default eslintConfig({
326
+ export default lincy({
224
327
  typescript: {
225
328
  tsconfigPath: 'tsconfig.json',
226
329
  },