@kirklin/eslint-config 2.4.0 → 2.6.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
@@ -33,7 +33,7 @@
33
33
  - Opinionated, but [very customizable](#customization)
34
34
  - [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
35
35
  - Optional [React](#react), [Svelte](#svelte), [UnoCSS](#unocss), [Astro](#astro), [Solid](#solid) support
36
- - Optional [formatters](#formatters) support for formatting CSS, HTML, etc.
36
+ - Optional [formatters](#formatters) support for formatting CSS, HTML, XML, etc.
37
37
  - **Style principle**: Minimal for reading, stable for diff, consistent
38
38
  - Sorted imports, dangling commas
39
39
  - Single quotes, no semi
@@ -51,7 +51,7 @@
51
51
  We provided a CLI tool to help you set up your project, or migrate from the legacy config to the new flat config with one command.
52
52
 
53
53
  ```bash
54
- npx @kirklin/eslint-config@latest
54
+ pnpm dlx @kirklin/eslint-config@latest
55
55
  ```
56
56
 
57
57
  ### Manual Install
@@ -119,7 +119,12 @@ For example:
119
119
  }
120
120
  ```
121
121
 
122
- ## VS Code support (auto fix on save)
122
+ ## IDE Support (auto fix on save)
123
+
124
+ <details>
125
+ <summary>🟦 VS Code support</summary>
126
+
127
+ <br>
123
128
 
124
129
  Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
125
130
 
@@ -127,9 +132,6 @@ Add the following settings to your `.vscode/settings.json`:
127
132
 
128
133
  ```jsonc
129
134
  {
130
- // Enable the ESlint flat config support
131
- "eslint.experimental.useFlatConfig": true,
132
-
133
135
  // Disable the default formatter, use eslint instead
134
136
  "prettier.enable": false,
135
137
  "editor.formatOnSave": false,
@@ -142,16 +144,16 @@ Add the following settings to your `.vscode/settings.json`:
142
144
 
143
145
  // Silent the stylistic rules in you IDE, but still auto fix them
144
146
  "eslint.rules.customizations": [
145
- { "rule": "style/*", "severity": "off" },
146
- { "rule": "format/*", "severity": "off" },
147
- { "rule": "*-indent", "severity": "off" },
148
- { "rule": "*-spacing", "severity": "off" },
149
- { "rule": "*-spaces", "severity": "off" },
150
- { "rule": "*-order", "severity": "off" },
151
- { "rule": "*-dangle", "severity": "off" },
152
- { "rule": "*-newline", "severity": "off" },
153
- { "rule": "*quotes", "severity": "off" },
154
- { "rule": "*semi", "severity": "off" }
147
+ { "rule": "style/*", "severity": "off", "fixable": true },
148
+ { "rule": "format/*", "severity": "off", "fixable": true },
149
+ { "rule": "*-indent", "severity": "off", "fixable": true },
150
+ { "rule": "*-spacing", "severity": "off", "fixable": true },
151
+ { "rule": "*-spaces", "severity": "off", "fixable": true },
152
+ { "rule": "*-order", "severity": "off", "fixable": true },
153
+ { "rule": "*-dangle", "severity": "off", "fixable": true },
154
+ { "rule": "*-newline", "severity": "off", "fixable": true },
155
+ { "rule": "*quotes", "severity": "off", "fixable": true },
156
+ { "rule": "*semi", "severity": "off", "fixable": true }
155
157
  ],
156
158
 
157
159
  // Enable eslint for all supported languages
@@ -167,12 +169,104 @@ Add the following settings to your `.vscode/settings.json`:
167
169
  "jsonc",
168
170
  "yaml",
169
171
  "toml",
172
+ "xml",
170
173
  "gql",
171
- "graphql"
174
+ "graphql",
175
+ "astro",
176
+ "svelte",
177
+ "css",
178
+ "less",
179
+ "scss",
180
+ "pcss",
181
+ "postcss"
172
182
  ]
173
183
  }
174
184
  ```
175
185
 
186
+ </details>
187
+
188
+ <details>
189
+ <summary>🟩 Neovim Support</summary>
190
+
191
+ <br>
192
+
193
+ Update your configuration to use the following:
194
+
195
+ ```lua
196
+ local customizations = {
197
+ { rule = 'style/*', severity = 'off', fixable = true },
198
+ { rule = 'format/*', severity = 'off', fixable = true },
199
+ { rule = '*-indent', severity = 'off', fixable = true },
200
+ { rule = '*-spacing', severity = 'off', fixable = true },
201
+ { rule = '*-spaces', severity = 'off', fixable = true },
202
+ { rule = '*-order', severity = 'off', fixable = true },
203
+ { rule = '*-dangle', severity = 'off', fixable = true },
204
+ { rule = '*-newline', severity = 'off', fixable = true },
205
+ { rule = '*quotes', severity = 'off', fixable = true },
206
+ { rule = '*semi', severity = 'off', fixable = true },
207
+ }
208
+
209
+ local lspconfig = require('lspconfig')
210
+ -- Enable eslint for all supported languages
211
+ lspconfig.eslint.setup(
212
+ {
213
+ filetypes = {
214
+ "javascript",
215
+ "javascriptreact",
216
+ "javascript.jsx",
217
+ "typescript",
218
+ "typescriptreact",
219
+ "typescript.tsx",
220
+ "vue",
221
+ "html",
222
+ "markdown",
223
+ "json",
224
+ "jsonc",
225
+ "yaml",
226
+ "toml",
227
+ "xml",
228
+ "gql",
229
+ "graphql",
230
+ "astro",
231
+ "svelte",
232
+ "css",
233
+ "less",
234
+ "scss",
235
+ "pcss",
236
+ "postcss"
237
+ },
238
+ settings = {
239
+ -- Silent the stylistic rules in you IDE, but still auto fix them
240
+ rulesCustomizations = customizations,
241
+ },
242
+ }
243
+ )
244
+ ```
245
+
246
+ ### Neovim format on save
247
+
248
+ There's few ways you can achieve format on save in neovim:
249
+
250
+ - `nvim-lspconfig` has a `EslintFixAll` command predefined, you can create a autocmd to call this command after saving file.
251
+
252
+ ```lua
253
+ lspconfig.eslint.setup({
254
+ --- ...
255
+ on_attach = function(client, bufnr)
256
+ vim.api.nvim_create_autocmd("BufWritePre", {
257
+ buffer = bufnr,
258
+ command = "EslintFixAll",
259
+ })
260
+ end,
261
+ })
262
+ ```
263
+
264
+ - Use [conform.nvim](https://github.com/stevearc/conform.nvim).
265
+ - Use [none-ls](https://github.com/nvimtools/none-ls.nvim)
266
+ - Use [nvim-lint](https://github.com/mfussenegger/nvim-lint)
267
+
268
+ </details>
269
+
176
270
  ## Customization
177
271
 
178
272
  Since v1.0, we migrated to [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new). It provides much better organization and composition.
@@ -193,6 +287,9 @@ And that's it! Or you can configure each integration individually, for example:
193
287
  import kirklin from "@kirklin/eslint-config";
194
288
 
195
289
  export default kirklin({
290
+ // Type of the project. 'lib' for libraries, the default is 'app'
291
+ type: "lib",
292
+
196
293
  // Enable stylistic formatting rules
197
294
  // stylistic: true,
198
295
 
@@ -202,7 +299,7 @@ export default kirklin({
202
299
  quotes: "double", // or 'single'
203
300
  },
204
301
 
205
- // TypeScript and Vue are auto-detected, you can also explicitly enable them:
302
+ // TypeScript and Vue are autodetected, you can also explicitly enable them:
206
303
  typescript: true,
207
304
  vue: true,
208
305
 
@@ -305,7 +402,7 @@ Since flat config requires us to explicitly provide the plugin names (instead of
305
402
  | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
306
403
  | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
307
404
  | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
308
- | `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
405
+ | `test/*` | `vitest/*` | [@vitest/eslint-plugin](https://github.com/vitest-dev/eslint-plugin-vitest) |
309
406
  | `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
310
407
 
311
408
  When you want to override rules, or disable them inline, you need to update to the new prefix:
@@ -325,7 +422,26 @@ type foo = { bar: 2 }
325
422
  >
326
423
  > Feel free to open issues if you want to combine this config with some other config presets but faced naming collisions. I am happy to figure out a way to make them work. But at this moment I have no plan to revert the renaming.
327
424
 
328
- Since v2.9.0, this preset will automatically rename the plugins also for your custom configs. You can use the original prefix to override the rules directly.
425
+ Since v2.3.0, this preset will automatically rename the plugins also for your custom configs. You can use the original prefix to override the rules directly.
426
+
427
+ <details>
428
+ <summary>Change back to original prefix</summary>
429
+
430
+ If you really want to use the original prefix, you can revert the plugin renaming by:
431
+
432
+ ```ts
433
+ import kirklin from "@kirklin/eslint-config";
434
+
435
+ export default kirklin()
436
+ .renamePlugins({
437
+ ts: "@typescript-eslint",
438
+ yaml: "yml",
439
+ node: "n"
440
+ // ...
441
+ });
442
+ ```
443
+
444
+ </details>
329
445
 
330
446
  ### Rules Overrides
331
447
 
@@ -600,7 +716,7 @@ You can add the trigger comment one line above the code you want to transform, f
600
716
  /// to-function
601
717
  const foo = async (msg: string): void => {
602
718
  console.log(msg)
603
- };
719
+ }
604
720
  ```
605
721
 
606
722
  Will be transformed to this when you hit save with your editor or run `eslint . --fix`:
@@ -716,6 +832,8 @@ This project is based on [@antfu/eslint-config](https://github.com/antfu/eslint-
716
832
 
717
833
  - [kirklin/dotfiles](https://github.com/kirklin/dotfiles) - My dotfiles
718
834
  - [kirklin/vscode-settings](https://github.com/kirklin/vscode-settings) - My VS Code settings
835
+ - [kirklin/boot-ts](https://github.com/kirklin/boot-ts) - My starter template for TypeScript library
836
+ - [kirklin/boot-vue](https://github.com/kirklin/boot-vue) - My starter template for Vue & Vite app
719
837
 
720
838
  ## License
721
839
 
package/README.zh-cn.md CHANGED
@@ -37,7 +37,7 @@
37
37
  - 使用[ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
38
38
  - 默认情况下遵守`.gitignore`
39
39
  - 可选的[React](#react), [Svelte](#svelte), [UnoCSS](#unocss), [Astro](#astro), [Solid](#solid)支持
40
- - 可选的[格式化程序](#formatters)支持CSS,HTML等。
40
+ - 可选的[格式化程序](#formatters)支持CSS,HTML,XML等。
41
41
  - **样式原则**:最小化阅读,稳定的差异性,保持一致性
42
42
 
43
43
  > [!IMPORTANT]
@@ -50,7 +50,7 @@
50
50
  我们提供了一个命令行工具,帮助您快速设置项目,或者通过一个命令从旧的配置迁移到新的平面配置。
51
51
 
52
52
  ```bash
53
- npx @kirklin/eslint-config@latest
53
+ pnpm dlx @kirklin/eslint-config@latest
54
54
  ```
55
55
 
56
56
  ### 手动安装
@@ -118,20 +118,20 @@ For example:
118
118
  }
119
119
  ```
120
120
 
121
- ## VS Code支持(自动修复)
121
+ ## IDE 支持(保存时自动修复)
122
122
 
123
- 为了在Visual Studio Code中实现保存时自动修复代码的功能,您需要安装ESLint扩展并配置相应的设置。以下是详细的步骤和说明:
123
+ <details>
124
+ <summary>🟦 VS Code 支持</summary>
125
+
126
+ <br>
124
127
 
125
- 1. 安装 [VS Code ESLint扩展](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
128
+ 安装 [VS Code ESLint 插件](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
126
129
 
127
- 2. 在您的项目根目录下,创建或编辑`.vscode`文件夹中的`settings.json`文件,添加以下配置:
130
+ `.vscode/settings.json` 中添加以下设置:
128
131
 
129
132
  ```jsonc
130
133
  {
131
- // 启用ESLint flat config支持
132
- "eslint.experimental.useFlatConfig": true,
133
-
134
- // 禁用默认的格式化程序,改用ESLint进行格式化
134
+ // 禁用默认格式化器,使用 eslint 代替
135
135
  "prettier.enable": false,
136
136
  "editor.formatOnSave": false,
137
137
 
@@ -141,21 +141,21 @@ For example:
141
141
  "source.organizeImports": "never"
142
142
  },
143
143
 
144
- // 在IDE中隐藏样式规则的提示,但仍然自动修复它们
144
+ // 在IDE中静默样式规则,但仍然自动修复
145
145
  "eslint.rules.customizations": [
146
- { "rule": "style/*", "severity": "off" },
147
- { "rule": "format/*", "severity": "off" },
148
- { "rule": "*-indent", "severity": "off" },
149
- { "rule": "*-spacing", "severity": "off" },
150
- { "rule": "*-spaces", "severity": "off" },
151
- { "rule": "*-order", "severity": "off" },
152
- { "rule": "*-dangle", "severity": "off" },
153
- { "rule": "*-newline", "severity": "off" },
154
- { "rule": "*quotes", "severity": "off" },
155
- { "rule": "*semi", "severity": "off" }
146
+ { "rule": "style/*", "severity": "off", "fixable": true },
147
+ { "rule": "format/*", "severity": "off", "fixable": true },
148
+ { "rule": "*-indent", "severity": "off", "fixable": true },
149
+ { "rule": "*-spacing", "severity": "off", "fixable": true },
150
+ { "rule": "*-spaces", "severity": "off", "fixable": true },
151
+ { "rule": "*-order", "severity": "off", "fixable": true },
152
+ { "rule": "*-dangle", "severity": "off", "fixable": true },
153
+ { "rule": "*-newline", "severity": "off", "fixable": true },
154
+ { "rule": "*quotes", "severity": "off", "fixable": true },
155
+ { "rule": "*semi", "severity": "off", "fixable": true }
156
156
  ],
157
157
 
158
- // 为所有支持的语言启用ESLint
158
+ // 为所有支持的语言启用 eslint
159
159
  "eslint.validate": [
160
160
  "javascript",
161
161
  "javascriptreact",
@@ -168,12 +168,104 @@ For example:
168
168
  "jsonc",
169
169
  "yaml",
170
170
  "toml",
171
+ "xml",
171
172
  "gql",
172
- "graphql"
173
+ "graphql",
174
+ "astro",
175
+ "svelte",
176
+ "css",
177
+ "less",
178
+ "scss",
179
+ "pcss",
180
+ "postcss"
173
181
  ]
174
182
  }
175
183
  ```
176
184
 
185
+ </details>
186
+
187
+ <details>
188
+ <summary>🟩 Neovim 支持</summary>
189
+
190
+ <br>
191
+
192
+ 更新你的配置,使用以下内容:
193
+
194
+ ```lua
195
+ local customizations = {
196
+ { rule = 'style/*', severity = 'off', fixable = true },
197
+ { rule = 'format/*', severity = 'off', fixable = true },
198
+ { rule = '*-indent', severity = 'off', fixable = true },
199
+ { rule = '*-spacing', severity = 'off', fixable = true },
200
+ { rule = '*-spaces', severity = 'off', fixable = true },
201
+ { rule = '*-order', severity = 'off', fixable = true },
202
+ { rule = '*-dangle', severity = 'off', fixable = true },
203
+ { rule = '*-newline', severity = 'off', fixable = true },
204
+ { rule = '*quotes', severity = 'off', fixable = true },
205
+ { rule = '*semi', severity = 'off', fixable = true },
206
+ }
207
+
208
+ local lspconfig = require('lspconfig')
209
+ -- 为所有支持的语言启用 eslint
210
+ lspconfig.eslint.setup(
211
+ {
212
+ filetypes = {
213
+ "javascript",
214
+ "javascriptreact",
215
+ "javascript.jsx",
216
+ "typescript",
217
+ "typescriptreact",
218
+ "typescript.tsx",
219
+ "vue",
220
+ "html",
221
+ "markdown",
222
+ "json",
223
+ "jsonc",
224
+ "yaml",
225
+ "toml",
226
+ "xml",
227
+ "gql",
228
+ "graphql",
229
+ "astro",
230
+ "svelte",
231
+ "css",
232
+ "less",
233
+ "scss",
234
+ "pcss",
235
+ "postcss"
236
+ },
237
+ settings = {
238
+ -- 在IDE中静默样式规则,但仍然自动修复
239
+ rulesCustomizations = customizations,
240
+ },
241
+ }
242
+ )
243
+ ```
244
+
245
+ ### Neovim 保存时格式化
246
+
247
+ 在 Neovim 中实现保存时格式化有几种方法:
248
+
249
+ - `nvim-lspconfig` 预定义了 `EslintFixAll` 命令,你可以创建一个 autocmd,在保存文件后调用该命令。
250
+
251
+ ```lua
252
+ lspconfig.eslint.setup({
253
+ --- ...
254
+ on_attach = function(client, bufnr)
255
+ vim.api.nvim_create_autocmd("BufWritePre", {
256
+ buffer = bufnr,
257
+ command = "EslintFixAll",
258
+ })
259
+ end,
260
+ })
261
+ ```
262
+
263
+ - 使用 [conform.nvim](https://github.com/stevearc/conform.nvim)。
264
+ - 使用 [none-ls](https://github.com/nvimtools/none-ls.nvim)。
265
+ - 使用 [nvim-lint](https://github.com/mfussenegger/nvim-lint)。
266
+
267
+ </details>
268
+
177
269
  ## 自定义
178
270
 
179
271
  从v1.0开始,我们迁移到了[ESLint Flat 配置](https://eslint.org/docs/latest/use/configure/configuration-files-new)。它提供了更好的组织和组合。
@@ -194,6 +286,9 @@ export default kirklin();
194
286
  import kirklin from "@kirklin/eslint-config";
195
287
 
196
288
  export default kirklin({
289
+ // 项目类型。'lib' 表示库,默认是 'app'
290
+ type: "lib",
291
+
197
292
  // 启用风格格式规则
198
293
  // stylistic: true,
199
294
 
@@ -306,7 +401,7 @@ export default combine(
306
401
  | `yaml/*` | `yml/*` | [eslint-plugin-yml](https://github.com/ota-meshi/eslint-plugin-yml) |
307
402
  | `ts/*` | `@typescript-eslint/*` | [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) |
308
403
  | `style/*` | `@stylistic/*` | [@stylistic/eslint-plugin](https://github.com/eslint-stylistic/eslint-stylistic) |
309
- | `test/*` | `vitest/*` | [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest) |
404
+ | `test/*` | `vitest/*` | [@vitest/eslint-plugin](https://github.com/vitest-dev/eslint-plugin-vitest) |
310
405
  | `test/*` | `no-only-tests/*` | [eslint-plugin-no-only-tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests) |
311
406
 
312
407
  当您想要覆盖规则或在内联中禁用它们时,您需要更新新前缀:
@@ -328,6 +423,25 @@ type foo = { bar: 2 }
328
423
 
329
424
  从 v2.3.0 版本开始,这个预设将自动重命名插件,也适用于您的自定义配置。您可以使用原始前缀直接覆盖规则。
330
425
 
426
+ <details>
427
+ <summary>恢复原始前缀</summary>
428
+
429
+ 如果你确实想使用原始前缀,可以通过以下方式还原插件重命名:
430
+
431
+ ```ts
432
+ import kirklin from "@kirklin/eslint-config";
433
+
434
+ export default kirklin()
435
+ .renamePlugins({
436
+ ts: "@typescript-eslint",
437
+ yaml: "yml",
438
+ node: "n"
439
+ // ...
440
+ });
441
+ ```
442
+
443
+ </details>
444
+
331
445
  ### 规则覆盖
332
446
 
333
447
  某些规则仅在特定文件中启用,例如, `ts/*` 规则仅在 `.ts` 文件中启用, `vue/*` 规则仅在 `.vue` 文件中启用。如果要覆盖规则,需要指定文件扩展名:
@@ -384,7 +498,7 @@ export default kirklin({
384
498
 
385
499
  ### 配置组合器
386
500
 
387
- 从 v2.3.0 版本开始,工厂函数 `kirklin()` 返回了一个来自 `eslint-flat-config-utils` 的 [`FlatConfigComposer` 对象](https://github.com/antfu/eslint-flat-config-utils#composer)。您可以链式调用方法,以更加灵活地组合配置。
501
+ 从 v2.3.0 版本开始,工厂函数 `kirklin()` 返回了一个来自 `eslint-flat-config-utils` 的 [`FlatConfigComposer` 对象](https://github.com/kirklin/eslint-flat-config-utils#composer)。您可以链式调用方法,以更加灵活地组合配置。
388
502
 
389
503
  ```js
390
504
  // eslint.config.js
@@ -718,6 +832,8 @@ This project is based on [@antfu/eslint-config](https://github.com/antfu/eslint-
718
832
 
719
833
  - [kirklin/dotfiles](https://github.com/kirklin/dotfiles) - My dotfiles
720
834
  - [kirklin/vscode-settings](https://github.com/kirklin/vscode-settings) - My VS Code settings
835
+ - [kirklin/boot-ts](https://github.com/kirklin/boot-ts) - My starter template for TypeScript library
836
+ - [kirklin/boot-vue](https://github.com/kirklin/boot-vue) - My starter template for Vue & Vite app
721
837
 
722
838
  ## License
723
839