@coderwyd/eslint-config 4.2.0 → 4.2.2

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/dist/index.js CHANGED
@@ -1,1961 +1,1742 @@
1
- // src/configs/command.ts
1
+ import process from "node:process";
2
2
  import createCommand from "eslint-plugin-command/config";
3
+ import pluginComments from "@eslint-community/eslint-plugin-eslint-comments";
4
+ import pluginAntfu from "eslint-plugin-antfu";
5
+ import pluginDeMorgan from "eslint-plugin-de-morgan";
6
+ import * as pluginImport from "eslint-plugin-import-x";
7
+ import pluginNode from "eslint-plugin-n";
8
+ import pluginPerfectionist from "eslint-plugin-perfectionist";
9
+ import pluginUnicorn from "eslint-plugin-unicorn";
10
+ import pluginUnusedImports from "eslint-plugin-unused-imports";
11
+ import globals from "globals";
12
+ import { fileURLToPath } from "node:url";
13
+ import { getPackageInfoSync, isPackageExists } from "local-pkg";
14
+ import prettierRules from "eslint-config-prettier";
15
+ import { configs } from "eslint-plugin-regexp";
16
+
17
+ //#region src/configs/command.ts
3
18
  function command() {
4
- return [
5
- {
6
- ...createCommand(),
7
- name: "coderwyd/command/rules"
8
- }
9
- ];
19
+ return [{
20
+ ...createCommand(),
21
+ name: "coderwyd/command/rules"
22
+ }];
10
23
  }
11
24
 
12
- // src/plugins/index.ts
13
- import { default as default2 } from "@eslint-community/eslint-plugin-eslint-comments";
14
- import { default as default3 } from "eslint-plugin-antfu";
15
- import { default as default4 } from "eslint-plugin-de-morgan";
16
- import * as pluginImport from "eslint-plugin-import-x";
17
- import { default as default5 } from "eslint-plugin-n";
18
- import { default as default6 } from "eslint-plugin-perfectionist";
19
- import { default as default7 } from "eslint-plugin-unicorn";
20
- import { default as default8 } from "eslint-plugin-unused-imports";
21
-
22
- // src/configs/comments.ts
25
+ //#endregion
26
+ //#region src/configs/comments.ts
23
27
  function comments() {
24
- return [
25
- {
26
- name: "coderwyd/eslint-comments/rules",
27
- plugins: {
28
- "eslint-comments": default2
29
- },
30
- rules: {
31
- "eslint-comments/no-aggregating-enable": "error",
32
- "eslint-comments/no-duplicate-disable": "error",
33
- "eslint-comments/no-unlimited-disable": "error",
34
- "eslint-comments/no-unused-enable": "error"
35
- }
36
- }
37
- ];
28
+ return [{
29
+ name: "coderwyd/eslint-comments/rules",
30
+ plugins: { "eslint-comments": pluginComments },
31
+ rules: {
32
+ "eslint-comments/no-aggregating-enable": "error",
33
+ "eslint-comments/no-duplicate-disable": "error",
34
+ "eslint-comments/no-unlimited-disable": "error",
35
+ "eslint-comments/no-unused-enable": "error"
36
+ }
37
+ }];
38
38
  }
39
39
 
40
- // src/configs/de-morgan.ts
40
+ //#endregion
41
+ //#region src/configs/de-morgan.ts
41
42
  function deMorgan() {
42
- return [
43
- {
44
- name: "coderwyd/de-morgan/rules",
45
- plugins: {
46
- "de-morgan": default4
47
- },
48
- rules: {
49
- "de-morgan/no-negated-conjunction": "error",
50
- "de-morgan/no-negated-disjunction": "error"
51
- }
52
- }
53
- ];
43
+ return [{
44
+ name: "coderwyd/de-morgan/rules",
45
+ plugins: { "de-morgan": pluginDeMorgan },
46
+ rules: {
47
+ "de-morgan/no-negated-conjunction": "error",
48
+ "de-morgan/no-negated-disjunction": "error"
49
+ }
50
+ }];
54
51
  }
55
52
 
56
- // src/constants/glob.ts
57
- var GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
58
- var GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
59
- var GLOB_TS = "**/*.?([cm])ts";
60
- var GLOB_DTS = "**/*.d.?([cm])ts";
61
- var GLOB_TSX = "**/*.?([cm])tsx";
62
- var GLOB_VUE = "**/*.vue";
63
- var GLOB_ASTRO_TS = "**/*.astro/*.ts";
64
- var GLOB_SVELTE = "**/*.svelte";
65
- var GLOB_JSON = "**/*.json";
66
- var GLOB_JSON5 = "**/*.json5";
67
- var GLOB_JSONC = "**/*.jsonc";
68
- var GLOB_MARKDOWN = "**/*.md";
69
- var GLOB_YAML = "**/*.y?(a)ml";
70
- var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
71
- var GLOB_TESTS = [
72
- `**/__tests__/**/*.${GLOB_SRC_EXT}`,
73
- `**/*.spec.${GLOB_SRC_EXT}`,
74
- `**/*.test.${GLOB_SRC_EXT}`,
75
- `**/*.bench.${GLOB_SRC_EXT}`,
76
- `**/*.benchmark.${GLOB_SRC_EXT}`
53
+ //#endregion
54
+ //#region src/constants/glob.ts
55
+ const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
56
+ const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
57
+ const GLOB_TS = "**/*.?([cm])ts";
58
+ const GLOB_DTS = "**/*.d.?([cm])ts";
59
+ const GLOB_TSX = "**/*.?([cm])tsx";
60
+ const GLOB_VUE = "**/*.vue";
61
+ const GLOB_ASTRO_TS = "**/*.astro/*.ts";
62
+ const GLOB_SVELTE = "**/*.svelte";
63
+ const GLOB_JSON = "**/*.json";
64
+ const GLOB_JSON5 = "**/*.json5";
65
+ const GLOB_JSONC = "**/*.jsonc";
66
+ const GLOB_MARKDOWN = "**/*.md";
67
+ const GLOB_YAML = "**/*.y?(a)ml";
68
+ const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
69
+ const GLOB_TESTS = [
70
+ `**/__tests__/**/*.${GLOB_SRC_EXT}`,
71
+ `**/*.spec.${GLOB_SRC_EXT}`,
72
+ `**/*.test.${GLOB_SRC_EXT}`,
73
+ `**/*.bench.${GLOB_SRC_EXT}`,
74
+ `**/*.benchmark.${GLOB_SRC_EXT}`
77
75
  ];
78
- var GLOB_EXCLUDE = [
79
- "**/node_modules",
80
- "**/dist",
81
- "**/package-lock.json",
82
- "**/yarn.lock",
83
- "**/pnpm-lock.yaml",
84
- "**/bun.lockb",
85
- "**/output",
86
- "**/coverage",
87
- "**/temp",
88
- "**/.temp",
89
- "**/tmp",
90
- "**/.tmp",
91
- "**/.history",
92
- "**/.vitepress/cache",
93
- "**/.nuxt",
94
- "**/.next",
95
- "**/.svelte-kit",
96
- "**/.vercel",
97
- "**/.changeset",
98
- "**/.idea",
99
- "**/.cache",
100
- "**/.output",
101
- "**/.vite-inspect",
102
- "**/.yarn",
103
- "**/vite.config.*.timestamp-*",
104
- "**/CHANGELOG*.md",
105
- "**/*.min.*",
106
- "**/LICENSE*",
107
- "**/__snapshots__",
108
- "**/auto-import?(s).d.ts",
109
- "**/components.d.ts"
76
+ const GLOB_EXCLUDE = [
77
+ "**/node_modules",
78
+ "**/dist",
79
+ "**/package-lock.json",
80
+ "**/yarn.lock",
81
+ "**/pnpm-lock.yaml",
82
+ "**/bun.lockb",
83
+ "**/output",
84
+ "**/coverage",
85
+ "**/temp",
86
+ "**/.temp",
87
+ "**/tmp",
88
+ "**/.tmp",
89
+ "**/.history",
90
+ "**/.vitepress/cache",
91
+ "**/.nuxt",
92
+ "**/.next",
93
+ "**/.svelte-kit",
94
+ "**/.vercel",
95
+ "**/.changeset",
96
+ "**/.idea",
97
+ "**/.cache",
98
+ "**/.output",
99
+ "**/.vite-inspect",
100
+ "**/.yarn",
101
+ "**/vite.config.*.timestamp-*",
102
+ "**/CHANGELOG*.md",
103
+ "**/*.min.*",
104
+ "**/LICENSE*",
105
+ "**/__snapshots__",
106
+ "**/auto-import?(s).d.ts",
107
+ "**/components.d.ts"
110
108
  ];
111
109
 
112
- // src/configs/ignores.ts
110
+ //#endregion
111
+ //#region src/configs/ignores.ts
113
112
  function ignores(userIgnores = []) {
114
- return [
115
- {
116
- ignores: [...GLOB_EXCLUDE, ...userIgnores],
117
- name: "coderwyd/ignores"
118
- }
119
- ];
113
+ return [{
114
+ ignores: [...GLOB_EXCLUDE, ...userIgnores],
115
+ name: "coderwyd/ignores"
116
+ }];
120
117
  }
121
118
 
122
- // src/configs/imports.ts
119
+ //#endregion
120
+ //#region src/configs/imports.ts
123
121
  function imports() {
124
- return [
125
- {
126
- name: "coderwyd/imports/rules",
127
- plugins: {
128
- antfu: default3,
129
- import: pluginImport
130
- },
131
- rules: {
132
- "antfu/import-dedupe": "error",
133
- "antfu/no-import-dist": "error",
134
- "antfu/no-import-node-modules-by-path": "error",
135
- "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
136
- "import/first": "error",
137
- "import/no-duplicates": "error",
138
- "import/no-mutable-exports": "error",
139
- "import/no-named-default": "error",
140
- "import/no-self-import": "error",
141
- "import/no-webpack-loader-syntax": "error"
142
- }
143
- }
144
- ];
122
+ return [{
123
+ name: "coderwyd/imports/rules",
124
+ plugins: {
125
+ antfu: pluginAntfu,
126
+ import: pluginImport
127
+ },
128
+ rules: {
129
+ "antfu/import-dedupe": "error",
130
+ "antfu/no-import-dist": "error",
131
+ "antfu/no-import-node-modules-by-path": "error",
132
+ "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
133
+ "import/first": "error",
134
+ "import/newline-after-import": ["error", { count: 1 }],
135
+ "import/no-duplicates": "error",
136
+ "import/no-mutable-exports": "error",
137
+ "import/no-named-default": "error",
138
+ "import/no-self-import": "error",
139
+ "import/no-webpack-loader-syntax": "error"
140
+ }
141
+ }];
145
142
  }
146
143
 
147
- // src/configs/javascript.ts
148
- import globals from "globals";
144
+ //#endregion
145
+ //#region src/configs/javascript.ts
149
146
  function javascript(options = {}) {
150
- const { isInEditor: isInEditor2 = false, overrides = {} } = options;
151
- return [
152
- {
153
- languageOptions: {
154
- ecmaVersion: 2022,
155
- globals: {
156
- ...globals.browser,
157
- ...globals.es2021,
158
- ...globals.node,
159
- document: "readonly",
160
- navigator: "readonly",
161
- window: "readonly"
162
- },
163
- parserOptions: {
164
- ecmaFeatures: {
165
- jsx: true
166
- },
167
- ecmaVersion: 2022,
168
- sourceType: "module"
169
- },
170
- sourceType: "module"
171
- },
172
- linterOptions: {
173
- reportUnusedDisableDirectives: true
174
- },
175
- name: "coderwyd/javascript/setup"
176
- },
177
- {
178
- name: "coderwyd/javascript/rules",
179
- plugins: {
180
- "unused-imports": default8
181
- },
182
- rules: {
183
- "accessor-pairs": [
184
- "error",
185
- { enforceForClassMembers: true, setWithoutGet: true }
186
- ],
187
- "antfu/no-top-level-await": "error",
188
- "antfu/top-level-function": "error",
189
- "array-callback-return": "error",
190
- "block-scoped-var": "error",
191
- "constructor-super": "error",
192
- "default-case-last": "error",
193
- "dot-notation": ["error", { allowKeywords: true }],
194
- eqeqeq: ["error", "smart"],
195
- "for-direction": "error",
196
- "getter-return": "error",
197
- "new-cap": [
198
- "error",
199
- { capIsNew: false, newIsCap: true, properties: true }
200
- ],
201
- "no-alert": "error",
202
- "no-array-constructor": "error",
203
- "no-async-promise-executor": "error",
204
- "no-caller": "error",
205
- "no-case-declarations": "error",
206
- "no-class-assign": "error",
207
- "no-compare-neg-zero": "error",
208
- "no-cond-assign": ["error", "always"],
209
- "no-console": ["error", { allow: ["warn", "error"] }],
210
- "no-const-assign": "error",
211
- "no-constant-binary-expression": "error",
212
- "no-constant-condition": "error",
213
- "no-control-regex": "error",
214
- "no-debugger": "error",
215
- "no-delete-var": "error",
216
- "no-dupe-args": "error",
217
- "no-dupe-class-members": "error",
218
- "no-dupe-keys": "error",
219
- "no-duplicate-case": "error",
220
- "no-empty": ["error", { allowEmptyCatch: true }],
221
- "no-empty-character-class": "error",
222
- "no-empty-pattern": "error",
223
- "no-eval": "error",
224
- "no-ex-assign": "error",
225
- "no-extend-native": "error",
226
- "no-extra-bind": "error",
227
- "no-extra-boolean-cast": "error",
228
- "no-fallthrough": "error",
229
- "no-func-assign": "error",
230
- "no-global-assign": "error",
231
- "no-implied-eval": "error",
232
- "no-import-assign": "error",
233
- "no-invalid-regexp": "error",
234
- "no-irregular-whitespace": "error",
235
- "no-iterator": "error",
236
- "no-labels": ["error", { allowLoop: false, allowSwitch: false }],
237
- "no-lone-blocks": "error",
238
- "no-loss-of-precision": "error",
239
- "no-misleading-character-class": "error",
240
- "no-multi-str": "error",
241
- "no-new": "error",
242
- "no-new-func": "error",
243
- "no-new-native-nonconstructor": "error",
244
- "no-new-wrappers": "error",
245
- "no-obj-calls": "error",
246
- "no-object-constructor": "error",
247
- "no-octal": "error",
248
- "no-octal-escape": "error",
249
- "no-proto": "error",
250
- "no-prototype-builtins": "error",
251
- "no-redeclare": ["error", { builtinGlobals: false }],
252
- "no-regex-spaces": "error",
253
- "no-restricted-globals": [
254
- "error",
255
- { message: "Use `globalThis` instead.", name: "global" },
256
- { message: "Use `globalThis` instead.", name: "self" }
257
- ],
258
- "no-restricted-properties": [
259
- "error",
260
- {
261
- message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
262
- property: "__proto__"
263
- },
264
- {
265
- message: "Use `Object.defineProperty` instead.",
266
- property: "__defineGetter__"
267
- },
268
- {
269
- message: "Use `Object.defineProperty` instead.",
270
- property: "__defineSetter__"
271
- },
272
- {
273
- message: "Use `Object.getOwnPropertyDescriptor` instead.",
274
- property: "__lookupGetter__"
275
- },
276
- {
277
- message: "Use `Object.getOwnPropertyDescriptor` instead.",
278
- property: "__lookupSetter__"
279
- }
280
- ],
281
- "no-restricted-syntax": [
282
- "error",
283
- "TSEnumDeclaration[const=true]",
284
- "TSExportAssignment"
285
- ],
286
- "no-self-assign": ["error", { props: true }],
287
- "no-self-compare": "error",
288
- "no-sequences": "error",
289
- "no-shadow-restricted-names": "error",
290
- "no-sparse-arrays": "error",
291
- "no-template-curly-in-string": "error",
292
- "no-this-before-super": "error",
293
- "no-throw-literal": "error",
294
- "no-undef": "error",
295
- "no-undef-init": "error",
296
- "no-unexpected-multiline": "error",
297
- "no-unmodified-loop-condition": "error",
298
- "no-unneeded-ternary": ["error", { defaultAssignment: false }],
299
- "no-unreachable": "error",
300
- "no-unreachable-loop": "error",
301
- "no-unsafe-finally": "error",
302
- "no-unsafe-negation": "error",
303
- "no-unused-expressions": [
304
- "error",
305
- {
306
- allowShortCircuit: true,
307
- allowTaggedTemplates: true,
308
- allowTernary: true
309
- }
310
- ],
311
- "no-unused-vars": "off",
312
- "no-use-before-define": [
313
- "error",
314
- { classes: false, functions: false, variables: true }
315
- ],
316
- "no-useless-backreference": "error",
317
- "no-useless-call": "error",
318
- "no-useless-catch": "error",
319
- "no-useless-computed-key": "error",
320
- "no-useless-constructor": "error",
321
- "no-useless-rename": "error",
322
- "no-useless-return": "error",
323
- "no-var": "error",
324
- "no-with": "error",
325
- "object-shorthand": [
326
- "error",
327
- "always",
328
- {
329
- avoidQuotes: true,
330
- ignoreConstructors: false
331
- }
332
- ],
333
- "one-var": ["error", { initialized: "never" }],
334
- "prefer-arrow-callback": [
335
- "error",
336
- {
337
- allowNamedFunctions: false,
338
- allowUnboundThis: true
339
- }
340
- ],
341
- "prefer-const": [
342
- "error",
343
- {
344
- destructuring: "all",
345
- ignoreReadBeforeAssign: true
346
- }
347
- ],
348
- "prefer-exponentiation-operator": "error",
349
- // 'prefer-promise-reject-errors': 'error',
350
- "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
351
- "prefer-rest-params": "error",
352
- "prefer-spread": "error",
353
- "prefer-template": "error",
354
- "require-await": "error",
355
- "require-yield": "error",
356
- "symbol-description": "error",
357
- "unicode-bom": ["error", "never"],
358
- "unused-imports/no-unused-imports": isInEditor2 ? "off" : "error",
359
- "unused-imports/no-unused-vars": [
360
- "error",
361
- {
362
- args: "after-used",
363
- argsIgnorePattern: "^_",
364
- ignoreRestSiblings: true,
365
- vars: "all",
366
- varsIgnorePattern: "^_"
367
- }
368
- ],
369
- "use-isnan": [
370
- "error",
371
- { enforceForIndexOf: true, enforceForSwitchCase: true }
372
- ],
373
- "valid-typeof": ["error", { requireStringLiterals: true }],
374
- "vars-on-top": "error",
375
- yoda: ["error", "never"],
376
- ...overrides
377
- }
378
- }
379
- ];
147
+ const { isInEditor: isInEditor$1 = false, overrides = {} } = options;
148
+ return [{
149
+ languageOptions: {
150
+ ecmaVersion: 2022,
151
+ globals: {
152
+ ...globals.browser,
153
+ ...globals.es2021,
154
+ ...globals.node,
155
+ document: "readonly",
156
+ navigator: "readonly",
157
+ window: "readonly"
158
+ },
159
+ parserOptions: {
160
+ ecmaFeatures: { jsx: true },
161
+ ecmaVersion: 2022,
162
+ sourceType: "module"
163
+ },
164
+ sourceType: "module"
165
+ },
166
+ linterOptions: { reportUnusedDisableDirectives: true },
167
+ name: "coderwyd/javascript/setup"
168
+ }, {
169
+ name: "coderwyd/javascript/rules",
170
+ plugins: { "unused-imports": pluginUnusedImports },
171
+ rules: {
172
+ "accessor-pairs": ["error", {
173
+ enforceForClassMembers: true,
174
+ setWithoutGet: true
175
+ }],
176
+ "antfu/no-top-level-await": "error",
177
+ "antfu/top-level-function": "error",
178
+ "array-callback-return": "error",
179
+ "block-scoped-var": "error",
180
+ "constructor-super": "error",
181
+ "default-case-last": "error",
182
+ "dot-notation": ["error", { allowKeywords: true }],
183
+ eqeqeq: ["error", "smart"],
184
+ "for-direction": "error",
185
+ "getter-return": "error",
186
+ "new-cap": ["error", {
187
+ capIsNew: false,
188
+ newIsCap: true,
189
+ properties: true
190
+ }],
191
+ "no-alert": "error",
192
+ "no-array-constructor": "error",
193
+ "no-async-promise-executor": "error",
194
+ "no-caller": "error",
195
+ "no-case-declarations": "error",
196
+ "no-class-assign": "error",
197
+ "no-compare-neg-zero": "error",
198
+ "no-cond-assign": ["error", "always"],
199
+ "no-console": ["error", { allow: ["warn", "error"] }],
200
+ "no-const-assign": "error",
201
+ "no-constant-binary-expression": "error",
202
+ "no-constant-condition": "error",
203
+ "no-control-regex": "error",
204
+ "no-debugger": "error",
205
+ "no-delete-var": "error",
206
+ "no-dupe-args": "error",
207
+ "no-dupe-class-members": "error",
208
+ "no-dupe-keys": "error",
209
+ "no-duplicate-case": "error",
210
+ "no-empty": ["error", { allowEmptyCatch: true }],
211
+ "no-empty-character-class": "error",
212
+ "no-empty-pattern": "error",
213
+ "no-eval": "error",
214
+ "no-ex-assign": "error",
215
+ "no-extend-native": "error",
216
+ "no-extra-bind": "error",
217
+ "no-extra-boolean-cast": "error",
218
+ "no-fallthrough": "error",
219
+ "no-func-assign": "error",
220
+ "no-global-assign": "error",
221
+ "no-implied-eval": "error",
222
+ "no-import-assign": "error",
223
+ "no-invalid-regexp": "error",
224
+ "no-irregular-whitespace": "error",
225
+ "no-iterator": "error",
226
+ "no-labels": ["error", {
227
+ allowLoop: false,
228
+ allowSwitch: false
229
+ }],
230
+ "no-lone-blocks": "error",
231
+ "no-loss-of-precision": "error",
232
+ "no-misleading-character-class": "error",
233
+ "no-multi-str": "error",
234
+ "no-new": "error",
235
+ "no-new-func": "error",
236
+ "no-new-native-nonconstructor": "error",
237
+ "no-new-wrappers": "error",
238
+ "no-obj-calls": "error",
239
+ "no-object-constructor": "error",
240
+ "no-octal": "error",
241
+ "no-octal-escape": "error",
242
+ "no-proto": "error",
243
+ "no-prototype-builtins": "error",
244
+ "no-redeclare": ["error", { builtinGlobals: false }],
245
+ "no-regex-spaces": "error",
246
+ "no-restricted-globals": [
247
+ "error",
248
+ {
249
+ message: "Use `globalThis` instead.",
250
+ name: "global"
251
+ },
252
+ {
253
+ message: "Use `globalThis` instead.",
254
+ name: "self"
255
+ }
256
+ ],
257
+ "no-restricted-properties": [
258
+ "error",
259
+ {
260
+ message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
261
+ property: "__proto__"
262
+ },
263
+ {
264
+ message: "Use `Object.defineProperty` instead.",
265
+ property: "__defineGetter__"
266
+ },
267
+ {
268
+ message: "Use `Object.defineProperty` instead.",
269
+ property: "__defineSetter__"
270
+ },
271
+ {
272
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
273
+ property: "__lookupGetter__"
274
+ },
275
+ {
276
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
277
+ property: "__lookupSetter__"
278
+ }
279
+ ],
280
+ "no-restricted-syntax": [
281
+ "error",
282
+ "TSEnumDeclaration[const=true]",
283
+ "TSExportAssignment"
284
+ ],
285
+ "no-self-assign": ["error", { props: true }],
286
+ "no-self-compare": "error",
287
+ "no-sequences": "error",
288
+ "no-shadow-restricted-names": "error",
289
+ "no-sparse-arrays": "error",
290
+ "no-template-curly-in-string": "error",
291
+ "no-this-before-super": "error",
292
+ "no-throw-literal": "error",
293
+ "no-undef": "error",
294
+ "no-undef-init": "error",
295
+ "no-unexpected-multiline": "error",
296
+ "no-unmodified-loop-condition": "error",
297
+ "no-unneeded-ternary": ["error", { defaultAssignment: false }],
298
+ "no-unreachable": "error",
299
+ "no-unreachable-loop": "error",
300
+ "no-unsafe-finally": "error",
301
+ "no-unsafe-negation": "error",
302
+ "no-unused-expressions": ["error", {
303
+ allowShortCircuit: true,
304
+ allowTaggedTemplates: true,
305
+ allowTernary: true
306
+ }],
307
+ "no-unused-vars": "off",
308
+ "no-use-before-define": ["error", {
309
+ classes: false,
310
+ functions: false,
311
+ variables: true
312
+ }],
313
+ "no-useless-backreference": "error",
314
+ "no-useless-call": "error",
315
+ "no-useless-catch": "error",
316
+ "no-useless-computed-key": "error",
317
+ "no-useless-constructor": "error",
318
+ "no-useless-rename": "error",
319
+ "no-useless-return": "error",
320
+ "no-var": "error",
321
+ "no-with": "error",
322
+ "object-shorthand": [
323
+ "error",
324
+ "always",
325
+ {
326
+ avoidQuotes: true,
327
+ ignoreConstructors: false
328
+ }
329
+ ],
330
+ "one-var": ["error", { initialized: "never" }],
331
+ "prefer-arrow-callback": ["error", {
332
+ allowNamedFunctions: false,
333
+ allowUnboundThis: true
334
+ }],
335
+ "prefer-const": ["error", {
336
+ destructuring: "all",
337
+ ignoreReadBeforeAssign: true
338
+ }],
339
+ "prefer-exponentiation-operator": "error",
340
+ "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
341
+ "prefer-rest-params": "error",
342
+ "prefer-spread": "error",
343
+ "prefer-template": "error",
344
+ "require-await": "error",
345
+ "require-yield": "error",
346
+ "symbol-description": "error",
347
+ "unicode-bom": ["error", "never"],
348
+ "unused-imports/no-unused-imports": isInEditor$1 ? "off" : "error",
349
+ "unused-imports/no-unused-vars": ["error", {
350
+ args: "after-used",
351
+ argsIgnorePattern: "^_",
352
+ ignoreRestSiblings: true,
353
+ vars: "all",
354
+ varsIgnorePattern: "^_"
355
+ }],
356
+ "use-isnan": ["error", {
357
+ enforceForIndexOf: true,
358
+ enforceForSwitchCase: true
359
+ }],
360
+ "valid-typeof": ["error", { requireStringLiterals: true }],
361
+ "vars-on-top": "error",
362
+ yoda: ["error", "never"],
363
+ ...overrides
364
+ }
365
+ }];
380
366
  }
381
367
 
382
- // src/shared/index.ts
383
- import process from "node:process";
384
- import { fileURLToPath } from "node:url";
385
- import { getPackageInfoSync, isPackageExists } from "local-pkg";
386
- var scopeUrl = fileURLToPath(new URL(".", import.meta.url));
387
- var isCwdInScope = isPackageExists("@coderwyd/eslint-config");
388
- async function combine(...configs2) {
389
- const resolved = await Promise.all(configs2);
390
- return resolved.flat();
368
+ //#endregion
369
+ //#region src/shared/index.ts
370
+ const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
371
+ const isCwdInScope = isPackageExists("@coderwyd/eslint-config");
372
+ /**
373
+ * Combine array and non-array configs into a single array.
374
+ */
375
+ async function combine(...configs$1) {
376
+ const resolved = await Promise.all(configs$1);
377
+ return resolved.flat();
391
378
  }
379
+ /**
380
+ * Rename plugin prefixes in a rule object.
381
+ * Accepts a map of prefixes to rename.
382
+ *
383
+ * @example
384
+ * ```ts
385
+ * import { renameRules } from '@coderwyd/eslint-config'
386
+ *
387
+ * export default [{
388
+ * rules: renameRules(
389
+ * {
390
+ * '@typescript-eslint/indent': 'error'
391
+ * },
392
+ * { '@typescript-eslint': 'ts' }
393
+ * )
394
+ * }]
395
+ * ```
396
+ */
392
397
  function renameRules(rules, map) {
393
- return Object.fromEntries(
394
- Object.entries(rules).map(([key, value]) => {
395
- for (const [from, to] of Object.entries(map)) {
396
- if (key.startsWith(`${from}/`))
397
- return [to + key.slice(from.length), value];
398
- }
399
- return [key, value];
400
- })
401
- );
398
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
399
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
400
+ return [key, value];
401
+ }));
402
402
  }
403
- function renamePluginInConfigs(configs2, map) {
404
- return configs2.map((i) => {
405
- const clone = { ...i };
406
- if (clone.rules) clone.rules = renameRules(clone.rules, map);
407
- if (clone.plugins) {
408
- clone.plugins = Object.fromEntries(
409
- Object.entries(clone.plugins).map(([key, value]) => {
410
- if (key in map) return [map[key], value];
411
- return [key, value];
412
- })
413
- );
414
- }
415
- return clone;
416
- });
403
+ /**
404
+ * Rename plugin names a flat configs array
405
+ *
406
+ * @example
407
+ * ```ts
408
+ * import { renamePluginInConfigs } from '@antfu/eslint-config'
409
+ * import someConfigs from './some-configs'
410
+ *
411
+ * export default renamePluginInConfigs(someConfigs, {
412
+ * '@typescript-eslint': 'ts',
413
+ * 'import-x': 'import',
414
+ * })
415
+ * ```
416
+ */
417
+ function renamePluginInConfigs(configs$1, map) {
418
+ return configs$1.map((i) => {
419
+ const clone = { ...i };
420
+ if (clone.rules) clone.rules = renameRules(clone.rules, map);
421
+ if (clone.plugins) clone.plugins = Object.fromEntries(Object.entries(clone.plugins).map(([key, value]) => {
422
+ if (key in map) return [map[key], value];
423
+ return [key, value];
424
+ }));
425
+ return clone;
426
+ });
417
427
  }
418
428
  function getVueVersion() {
419
- const pkg = getPackageInfoSync("vue", { paths: [process.cwd()] });
420
- if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0]))
421
- return +pkg.version[0];
422
- return 3;
429
+ const pkg = getPackageInfoSync("vue", { paths: [process.cwd()] });
430
+ if (pkg && typeof pkg.version === "string" && !Number.isNaN(+pkg.version[0])) return +pkg.version[0];
431
+ return 3;
423
432
  }
424
433
  function toArray(value) {
425
- return Array.isArray(value) ? value : [value];
434
+ return Array.isArray(value) ? value : [value];
426
435
  }
427
436
  async function interopDefault(m) {
428
- const resolved = await m;
429
- return resolved.default || resolved;
437
+ const resolved = await m;
438
+ return resolved.default || resolved;
430
439
  }
431
440
  function isPackageInScope(name) {
432
- return isPackageExists(name, { paths: [scopeUrl] });
441
+ return isPackageExists(name, { paths: [scopeUrl] });
433
442
  }
434
443
  async function ensurePackages(packages) {
435
- if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false)
436
- return;
437
- const nonExistingPackages = packages.filter((i) => !isPackageInScope(i));
438
- if (nonExistingPackages.length === 0) return;
439
- const { default: prompts } = await import("prompts");
440
- const { result } = await prompts([
441
- {
442
- message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?`,
443
- name: "result",
444
- type: "confirm"
445
- }
446
- ]);
447
- if (result) {
448
- await import("@antfu/install-pkg").then(
449
- (i) => i.installPackage(nonExistingPackages, { dev: true })
450
- );
451
- }
444
+ if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) return;
445
+ const nonExistingPackages = packages.filter((i) => !isPackageInScope(i));
446
+ if (nonExistingPackages.length === 0) return;
447
+ const { default: prompts } = await import("prompts");
448
+ const { result } = await prompts([{
449
+ message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?`,
450
+ name: "result",
451
+ type: "confirm"
452
+ }]);
453
+ if (result) await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
452
454
  }
453
455
  function resolveSubOptions(options, key) {
454
- return typeof options[key] === "boolean" ? {} : options[key] || {};
456
+ return typeof options[key] === "boolean" ? {} : options[key] || {};
455
457
  }
456
458
  function getOverrides(options, key) {
457
- const subOptions = resolveSubOptions(options, key);
458
- return {
459
- ..."overrides" in subOptions && subOptions.overrides ? subOptions.overrides : {}
460
- };
459
+ const subOptions = resolveSubOptions(options, key);
460
+ return { ..."overrides" in subOptions && subOptions.overrides ? subOptions.overrides : {} };
461
461
  }
462
462
  function isInEditorEnv() {
463
- if (process.env.CI) return false;
464
- if (isInGitHooksOrLintStaged()) {
465
- return false;
466
- }
467
- return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM || false);
463
+ if (process.env.CI) return false;
464
+ if (isInGitHooksOrLintStaged()) return false;
465
+ return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM || false);
468
466
  }
469
467
  function isInGitHooksOrLintStaged() {
470
- return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged") || process.env.npm_lifecycle_script?.startsWith("nano-staged") || false);
468
+ return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged") || process.env.npm_lifecycle_script?.startsWith("nano-staged") || false);
471
469
  }
472
470
 
473
- // src/configs/jsdoc.ts
471
+ //#endregion
472
+ //#region src/configs/jsdoc.ts
474
473
  async function jsdoc() {
475
- return [
476
- {
477
- name: "coderwyd/jsdoc/rules",
478
- plugins: {
479
- jsdoc: await interopDefault(import("eslint-plugin-jsdoc"))
480
- },
481
- rules: {
482
- "jsdoc/check-access": "warn",
483
- "jsdoc/check-param-names": "warn",
484
- "jsdoc/check-property-names": "warn",
485
- "jsdoc/check-types": "warn",
486
- "jsdoc/empty-tags": "warn",
487
- "jsdoc/implements-on-classes": "warn",
488
- "jsdoc/no-defaults": "warn",
489
- "jsdoc/no-multi-asterisks": "warn",
490
- "jsdoc/require-param-name": "warn",
491
- "jsdoc/require-property": "warn",
492
- "jsdoc/require-property-description": "warn",
493
- "jsdoc/require-property-name": "warn",
494
- "jsdoc/require-returns-check": "warn",
495
- "jsdoc/require-returns-description": "warn",
496
- "jsdoc/require-yields-check": "warn"
497
- }
498
- }
499
- ];
474
+ return [{
475
+ name: "coderwyd/jsdoc/rules",
476
+ plugins: { jsdoc: await interopDefault(import("eslint-plugin-jsdoc")) },
477
+ rules: {
478
+ "jsdoc/check-access": "warn",
479
+ "jsdoc/check-param-names": "warn",
480
+ "jsdoc/check-property-names": "warn",
481
+ "jsdoc/check-types": "warn",
482
+ "jsdoc/empty-tags": "warn",
483
+ "jsdoc/implements-on-classes": "warn",
484
+ "jsdoc/no-defaults": "warn",
485
+ "jsdoc/no-multi-asterisks": "warn",
486
+ "jsdoc/require-param-name": "warn",
487
+ "jsdoc/require-property": "warn",
488
+ "jsdoc/require-property-description": "warn",
489
+ "jsdoc/require-property-name": "warn",
490
+ "jsdoc/require-returns-check": "warn",
491
+ "jsdoc/require-returns-description": "warn",
492
+ "jsdoc/require-yields-check": "warn"
493
+ }
494
+ }];
500
495
  }
501
496
 
502
- // src/configs/jsonc.ts
497
+ //#endregion
498
+ //#region src/configs/jsonc.ts
503
499
  async function jsonc(options = {}) {
504
- const { files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC], overrides = {} } = options || {};
505
- const [pluginJsonc, parserJsonc] = await Promise.all([
506
- interopDefault(import("eslint-plugin-jsonc")),
507
- interopDefault(import("jsonc-eslint-parser"))
508
- ]);
509
- return [
510
- {
511
- name: "coderwyd/jsonc/setup",
512
- plugins: {
513
- jsonc: pluginJsonc
514
- }
515
- },
516
- {
517
- files,
518
- languageOptions: {
519
- parser: parserJsonc
520
- },
521
- name: "coderwyd/jsonc/rules",
522
- rules: {
523
- "jsonc/no-bigint-literals": "error",
524
- "jsonc/no-binary-expression": "error",
525
- "jsonc/no-binary-numeric-literals": "error",
526
- "jsonc/no-dupe-keys": "error",
527
- "jsonc/no-escape-sequence-in-identifier": "error",
528
- "jsonc/no-floating-decimal": "error",
529
- "jsonc/no-hexadecimal-numeric-literals": "error",
530
- "jsonc/no-infinity": "error",
531
- "jsonc/no-multi-str": "error",
532
- "jsonc/no-nan": "error",
533
- "jsonc/no-number-props": "error",
534
- "jsonc/no-numeric-separators": "error",
535
- "jsonc/no-octal": "error",
536
- "jsonc/no-octal-escape": "error",
537
- "jsonc/no-octal-numeric-literals": "error",
538
- "jsonc/no-parenthesized": "error",
539
- "jsonc/no-plus-sign": "error",
540
- "jsonc/no-regexp-literals": "error",
541
- "jsonc/no-sparse-arrays": "error",
542
- "jsonc/no-template-literals": "error",
543
- "jsonc/no-undefined-value": "error",
544
- "jsonc/no-unicode-codepoint-escapes": "error",
545
- "jsonc/no-useless-escape": "error",
546
- "jsonc/space-unary-ops": "error",
547
- "jsonc/valid-json-number": "error",
548
- "jsonc/vue-custom-block/no-parsing-error": "error",
549
- ...overrides
550
- }
551
- }
552
- ];
500
+ const { files = [
501
+ GLOB_JSON,
502
+ GLOB_JSON5,
503
+ GLOB_JSONC
504
+ ], overrides = {} } = options || {};
505
+ const [pluginJsonc, parserJsonc] = await Promise.all([interopDefault(import("eslint-plugin-jsonc")), interopDefault(import("jsonc-eslint-parser"))]);
506
+ return [{
507
+ name: "coderwyd/jsonc/setup",
508
+ plugins: { jsonc: pluginJsonc }
509
+ }, {
510
+ files,
511
+ languageOptions: { parser: parserJsonc },
512
+ name: "coderwyd/jsonc/rules",
513
+ rules: {
514
+ "jsonc/no-bigint-literals": "error",
515
+ "jsonc/no-binary-expression": "error",
516
+ "jsonc/no-binary-numeric-literals": "error",
517
+ "jsonc/no-dupe-keys": "error",
518
+ "jsonc/no-escape-sequence-in-identifier": "error",
519
+ "jsonc/no-floating-decimal": "error",
520
+ "jsonc/no-hexadecimal-numeric-literals": "error",
521
+ "jsonc/no-infinity": "error",
522
+ "jsonc/no-multi-str": "error",
523
+ "jsonc/no-nan": "error",
524
+ "jsonc/no-number-props": "error",
525
+ "jsonc/no-numeric-separators": "error",
526
+ "jsonc/no-octal": "error",
527
+ "jsonc/no-octal-escape": "error",
528
+ "jsonc/no-octal-numeric-literals": "error",
529
+ "jsonc/no-parenthesized": "error",
530
+ "jsonc/no-plus-sign": "error",
531
+ "jsonc/no-regexp-literals": "error",
532
+ "jsonc/no-sparse-arrays": "error",
533
+ "jsonc/no-template-literals": "error",
534
+ "jsonc/no-undefined-value": "error",
535
+ "jsonc/no-unicode-codepoint-escapes": "error",
536
+ "jsonc/no-useless-escape": "error",
537
+ "jsonc/space-unary-ops": "error",
538
+ "jsonc/valid-json-number": "error",
539
+ "jsonc/vue-custom-block/no-parsing-error": "error",
540
+ ...overrides
541
+ }
542
+ }];
553
543
  }
554
544
 
555
- // src/configs/node.ts
545
+ //#endregion
546
+ //#region src/configs/node.ts
556
547
  function node() {
557
- return [
558
- {
559
- name: "coderwyd/node/rules",
560
- plugins: {
561
- node: default5
562
- },
563
- rules: {
564
- "node/handle-callback-err": ["error", "^(err|error)$"],
565
- "node/no-deprecated-api": "error",
566
- "node/no-exports-assign": "error",
567
- "node/no-new-require": "error",
568
- "node/no-path-concat": "error",
569
- "node/no-unsupported-features/es-builtins": "error",
570
- "node/prefer-global/buffer": ["error", "never"],
571
- "node/prefer-global/process": ["error", "never"],
572
- "node/process-exit-as-throw": "error"
573
- }
574
- }
575
- ];
548
+ return [{
549
+ name: "coderwyd/node/rules",
550
+ plugins: { node: pluginNode },
551
+ rules: {
552
+ "node/handle-callback-err": ["error", "^(err|error)$"],
553
+ "node/no-deprecated-api": "error",
554
+ "node/no-exports-assign": "error",
555
+ "node/no-new-require": "error",
556
+ "node/no-path-concat": "error",
557
+ "node/no-unsupported-features/es-builtins": "error",
558
+ "node/prefer-global/buffer": ["error", "never"],
559
+ "node/prefer-global/process": ["error", "never"],
560
+ "node/process-exit-as-throw": "error"
561
+ }
562
+ }];
576
563
  }
577
564
 
578
- // src/configs/perfectionist.ts
565
+ //#endregion
566
+ //#region src/configs/perfectionist.ts
567
+ /**
568
+ * Optional perfectionist plugin for props and items sorting.
569
+ *
570
+ * @see https://github.com/azat-io/eslint-plugin-perfectionist
571
+ */
579
572
  function perfectionist() {
580
- return [
581
- {
582
- name: "coderwyd/perfectionist/rules",
583
- plugins: {
584
- perfectionist: default6
585
- },
586
- rules: {
587
- "perfectionist/sort-exports": [
588
- "error",
589
- { order: "asc", type: "natural" }
590
- ],
591
- "perfectionist/sort-imports": [
592
- "warn",
593
- {
594
- groups: [
595
- "builtin",
596
- "external",
597
- "type",
598
- ["internal", "internal-type"],
599
- ["parent", "sibling", "index"],
600
- ["parent-type", "sibling-type", "index-type"],
601
- "object",
602
- "side-effect",
603
- "side-effect-style",
604
- "style",
605
- "unknown"
606
- ],
607
- internalPattern: ["^[~@#]/.*"],
608
- newlinesBetween: "ignore",
609
- order: "asc",
610
- type: "natural"
611
- }
612
- ],
613
- "perfectionist/sort-named-exports": [
614
- "warn",
615
- { groupKind: "values-first", order: "asc", type: "natural" }
616
- ],
617
- "perfectionist/sort-named-imports": [
618
- "warn",
619
- { groupKind: "values-first", order: "asc", type: "natural" }
620
- ]
621
- }
622
- }
623
- ];
573
+ return [{
574
+ name: "coderwyd/perfectionist/rules",
575
+ plugins: { perfectionist: pluginPerfectionist },
576
+ rules: {
577
+ "perfectionist/sort-exports": ["error", {
578
+ order: "asc",
579
+ type: "natural"
580
+ }],
581
+ "perfectionist/sort-imports": ["warn", {
582
+ groups: [
583
+ "side-effect-style",
584
+ "value-style",
585
+ "value-builtin",
586
+ "value-external",
587
+ "value-subpath",
588
+ "value-internal",
589
+ "value-parent",
590
+ "value-sibling",
591
+ "value-index",
592
+ "ts-equals-import",
593
+ "side-effect",
594
+ "type-builtin",
595
+ "type-external",
596
+ "type-subpath",
597
+ "type-internal",
598
+ "type-parent",
599
+ "type-sibling",
600
+ "type-index",
601
+ "unknown"
602
+ ],
603
+ internalPattern: ["^[~@#]/.*"],
604
+ newlinesBetween: "ignore",
605
+ order: "asc",
606
+ type: "natural"
607
+ }],
608
+ "perfectionist/sort-named-exports": ["warn", {
609
+ groupKind: "values-first",
610
+ order: "asc",
611
+ type: "natural"
612
+ }],
613
+ "perfectionist/sort-named-imports": ["warn", {
614
+ groupKind: "values-first",
615
+ order: "asc",
616
+ type: "natural"
617
+ }]
618
+ }
619
+ }];
624
620
  }
625
621
 
626
- // src/configs/prettier.ts
627
- import prettierRules from "eslint-config-prettier";
628
- var { rules: eslintRules } = prettierRules;
622
+ //#endregion
623
+ //#region src/configs/prettier.ts
624
+ const { rules: eslintRules } = prettierRules;
629
625
  function prettier() {
630
- return [
631
- {
632
- name: "coderwyd/prettier/rules",
633
- rules: {
634
- ...eslintRules,
635
- "arrow-body-style": "off",
636
- "prefer-arrow-callback": "off"
637
- }
638
- }
639
- ];
626
+ return [{
627
+ name: "coderwyd/prettier/rules",
628
+ rules: {
629
+ ...eslintRules,
630
+ "arrow-body-style": "off",
631
+ "prefer-arrow-callback": "off"
632
+ }
633
+ }];
640
634
  }
641
635
 
642
- // src/env.ts
643
- import process2 from "node:process";
644
- import { isPackageExists as isPackageExists2 } from "local-pkg";
645
- var isInEditor = !!((process2.env.VSCODE_PID || process2.env.VSCODE_CWD || process2.env.JETBRAINS_IDE || process2.env.VIM || process2.env.NVIM) && !process2.env.CI);
646
- var VueJsPackages = ["vue", "nuxt", "vitepress", "@slidev/cli"];
647
- var RemixPackages = [
648
- "@remix-run/node",
649
- "@remix-run/react",
650
- "@remix-run/serve",
651
- "@remix-run/dev"
636
+ //#endregion
637
+ //#region src/env.ts
638
+ const isInEditor = !!((process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM) && !process.env.CI);
639
+ const VueJsPackages = [
640
+ "vue",
641
+ "nuxt",
642
+ "vitepress",
643
+ "@slidev/cli"
652
644
  ];
653
- var ReactRouterPackages = [
654
- "@react-router/node",
655
- "@react-router/react",
656
- "@react-router/serve",
657
- "@react-router/dev"
645
+ const RemixPackages = [
646
+ "@remix-run/node",
647
+ "@remix-run/react",
648
+ "@remix-run/serve",
649
+ "@remix-run/dev"
658
650
  ];
659
- var NextJsPackages = ["next"];
660
- var ReactRefreshAllowConstantExportPackages = ["vite"];
661
- var isUsingTypeScript = isPackageExists2("typescript");
662
- var isUsingVue = hasPackages(VueJsPackages);
663
- var isUsingRemix = hasPackages(RemixPackages);
664
- var isUsingReactRouter = hasPackages(ReactRouterPackages);
665
- var isUsingNext = hasPackages(NextJsPackages);
666
- var isAllowConstantExport = hasPackages(
667
- ReactRefreshAllowConstantExportPackages
668
- );
651
+ const ReactRouterPackages = [
652
+ "@react-router/node",
653
+ "@react-router/react",
654
+ "@react-router/serve",
655
+ "@react-router/dev"
656
+ ];
657
+ const NextJsPackages = ["next"];
658
+ const ReactRefreshAllowConstantExportPackages = ["vite"];
659
+ const isUsingTypeScript = isPackageExists("typescript");
660
+ const isUsingVue = hasPackages(VueJsPackages);
661
+ const isUsingRemix = hasPackages(RemixPackages);
662
+ const isUsingReactRouter = hasPackages(ReactRouterPackages);
663
+ const isUsingNext = hasPackages(NextJsPackages);
664
+ const isAllowConstantExport = hasPackages(ReactRefreshAllowConstantExportPackages);
669
665
  function hasPackages(packages) {
670
- return packages.some((name) => isPackageExists2(name));
666
+ return packages.some((name) => isPackageExists(name));
671
667
  }
672
668
 
673
- // src/configs/react.ts
669
+ //#endregion
670
+ //#region src/configs/react.ts
674
671
  async function react(options = {}) {
675
- const {
676
- files = [GLOB_SRC],
677
- filesTypeAware = [GLOB_TS, GLOB_TSX],
678
- ignoresTypeAware = [`${GLOB_MARKDOWN}/**`, GLOB_ASTRO_TS],
679
- overrides = {},
680
- tsconfigPath
681
- } = options;
682
- await ensurePackages([
683
- "@eslint-react/eslint-plugin",
684
- "eslint-plugin-react-hooks",
685
- "eslint-plugin-react-refresh"
686
- ]);
687
- const isTypeAware = !!tsconfigPath;
688
- const typeAwareRules = {
689
- "react/no-leaked-conditional-rendering": "warn"
690
- };
691
- const [
692
- pluginReact,
693
- pluginReactHooks,
694
- pluginReactRefresh,
695
- pluginReactCompiler
696
- ] = await Promise.all([
697
- interopDefault(import("@eslint-react/eslint-plugin")),
698
- interopDefault(import("eslint-plugin-react-hooks")),
699
- interopDefault(import("eslint-plugin-react-refresh")),
700
- interopDefault(import("eslint-plugin-react-compiler"))
701
- ]);
702
- const plugins = pluginReact.configs.all.plugins;
703
- return [
704
- {
705
- name: "coderwyd/react/setup",
706
- plugins: {
707
- react: plugins["@eslint-react"],
708
- "react-compiler": pluginReactCompiler,
709
- "react-dom": plugins["@eslint-react/dom"],
710
- "react-hooks": pluginReactHooks,
711
- "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
712
- "react-naming-convention": plugins["@eslint-react/naming-convention"],
713
- "react-refresh": pluginReactRefresh,
714
- "react-web-api": plugins["@eslint-react/web-api"]
715
- }
716
- },
717
- {
718
- files,
719
- languageOptions: {
720
- parserOptions: {
721
- ecmaFeatures: {
722
- jsx: true
723
- }
724
- },
725
- sourceType: "module"
726
- },
727
- name: "coderwyd/react/rules",
728
- rules: {
729
- "react-compiler/react-compiler": "warn",
730
- // recommended rules from @eslint-react/dom
731
- "react-dom/no-children-in-void-dom-elements": "warn",
732
- "react-dom/no-dangerously-set-innerhtml": "warn",
733
- "react-dom/no-dangerously-set-innerhtml-with-children": "error",
734
- "react-dom/no-find-dom-node": "error",
735
- "react-dom/no-missing-button-type": "warn",
736
- "react-dom/no-missing-iframe-sandbox": "warn",
737
- "react-dom/no-namespace": "error",
738
- "react-dom/no-render-return-value": "error",
739
- "react-dom/no-script-url": "warn",
740
- "react-dom/no-unsafe-iframe-sandbox": "warn",
741
- "react-dom/no-unsafe-target-blank": "warn",
742
- // recommended rules react-hooks
743
- "react-hooks/exhaustive-deps": "warn",
744
- "react-hooks/rules-of-hooks": "error",
745
- // react refresh
746
- "react-refresh/only-export-components": [
747
- "warn",
748
- {
749
- allowConstantExport: isAllowConstantExport,
750
- allowExportNames: [
751
- ...isUsingNext ? [
752
- "dynamic",
753
- "dynamicParams",
754
- "revalidate",
755
- "fetchCache",
756
- "runtime",
757
- "preferredRegion",
758
- "maxDuration",
759
- "config",
760
- "generateStaticParams",
761
- "metadata",
762
- "generateMetadata",
763
- "viewport",
764
- "generateViewport"
765
- ] : [],
766
- ...isUsingRemix || isUsingReactRouter ? ["meta", "links", "headers", "loader", "action"] : []
767
- ]
768
- }
769
- ],
770
- // recommended rules from @eslint-react/web-api
771
- "react-web-api/no-leaked-event-listener": "warn",
772
- "react-web-api/no-leaked-interval": "warn",
773
- "react-web-api/no-leaked-resize-observer": "warn",
774
- "react-web-api/no-leaked-timeout": "warn",
775
- // recommended rules from @eslint-react
776
- "react/ensure-forward-ref-using-ref": "warn",
777
- "react/jsx-no-duplicate-props": "warn",
778
- "react/jsx-uses-vars": "warn",
779
- "react/no-access-state-in-setstate": "error",
780
- "react/no-array-index-key": "warn",
781
- "react/no-children-count": "warn",
782
- "react/no-children-for-each": "warn",
783
- "react/no-children-map": "warn",
784
- "react/no-children-only": "warn",
785
- "react/no-children-to-array": "warn",
786
- "react/no-clone-element": "warn",
787
- "react/no-comment-textnodes": "warn",
788
- "react/no-component-will-mount": "error",
789
- "react/no-component-will-receive-props": "error",
790
- "react/no-component-will-update": "error",
791
- "react/no-context-provider": "warn",
792
- "react/no-create-ref": "error",
793
- "react/no-default-props": "error",
794
- "react/no-direct-mutation-state": "error",
795
- "react/no-duplicate-key": "error",
796
- "react/no-forward-ref": "warn",
797
- "react/no-implicit-key": "warn",
798
- "react/no-missing-key": "error",
799
- "react/no-nested-components": "error",
800
- "react/no-prop-types": "error",
801
- "react/no-redundant-should-component-update": "error",
802
- "react/no-set-state-in-component-did-mount": "warn",
803
- "react/no-set-state-in-component-did-update": "warn",
804
- "react/no-set-state-in-component-will-update": "warn",
805
- "react/no-string-refs": "error",
806
- "react/no-unsafe-component-will-mount": "warn",
807
- "react/no-unsafe-component-will-receive-props": "warn",
808
- "react/no-unsafe-component-will-update": "warn",
809
- "react/no-unstable-context-value": "warn",
810
- "react/no-unstable-default-props": "warn",
811
- "react/no-unused-class-component-members": "warn",
812
- "react/no-unused-state": "warn",
813
- "react/prefer-destructuring-assignment": "warn",
814
- "react/prefer-shorthand-boolean": "warn",
815
- "react/prefer-shorthand-fragment": "warn",
816
- // overrides
817
- ...overrides
818
- }
819
- },
820
- ...isTypeAware ? [
821
- {
822
- files: filesTypeAware,
823
- ignores: ignoresTypeAware,
824
- name: "coderwyd/react/type-aware-rules",
825
- rules: {
826
- ...typeAwareRules
827
- }
828
- }
829
- ] : []
830
- ];
672
+ const { files = [GLOB_SRC], filesTypeAware = [GLOB_TS, GLOB_TSX], ignoresTypeAware = [`${GLOB_MARKDOWN}/**`, GLOB_ASTRO_TS], overrides = {}, tsconfigPath } = options;
673
+ await ensurePackages([
674
+ "@eslint-react/eslint-plugin",
675
+ "eslint-plugin-react-hooks",
676
+ "eslint-plugin-react-refresh"
677
+ ]);
678
+ const isTypeAware = !!tsconfigPath;
679
+ const typeAwareRules = { "react/no-leaked-conditional-rendering": "warn" };
680
+ const [pluginReact, pluginReactHooks, pluginReactRefresh, pluginReactCompiler] = await Promise.all([
681
+ interopDefault(import("@eslint-react/eslint-plugin")),
682
+ interopDefault(import("eslint-plugin-react-hooks")),
683
+ interopDefault(import("eslint-plugin-react-refresh")),
684
+ interopDefault(import("eslint-plugin-react-compiler"))
685
+ ]);
686
+ const plugins = pluginReact.configs.all.plugins;
687
+ return [
688
+ {
689
+ name: "coderwyd/react/setup",
690
+ plugins: {
691
+ react: plugins["@eslint-react"],
692
+ "react-compiler": pluginReactCompiler,
693
+ "react-dom": plugins["@eslint-react/dom"],
694
+ "react-hooks": pluginReactHooks,
695
+ "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
696
+ "react-naming-convention": plugins["@eslint-react/naming-convention"],
697
+ "react-refresh": pluginReactRefresh,
698
+ "react-web-api": plugins["@eslint-react/web-api"]
699
+ }
700
+ },
701
+ {
702
+ files,
703
+ languageOptions: {
704
+ parserOptions: { ecmaFeatures: { jsx: true } },
705
+ sourceType: "module"
706
+ },
707
+ name: "coderwyd/react/rules",
708
+ rules: {
709
+ "react-compiler/react-compiler": "warn",
710
+ "react/no-access-state-in-setstate": "error",
711
+ "react/no-array-index-key": "warn",
712
+ "react/no-children-count": "warn",
713
+ "react/no-children-for-each": "warn",
714
+ "react/no-children-map": "warn",
715
+ "react/no-children-only": "warn",
716
+ "react/no-children-to-array": "warn",
717
+ "react/no-clone-element": "warn",
718
+ "react/no-comment-textnodes": "warn",
719
+ "react/no-component-will-mount": "error",
720
+ "react/no-component-will-receive-props": "error",
721
+ "react/no-component-will-update": "error",
722
+ "react/no-context-provider": "warn",
723
+ "react/no-create-ref": "error",
724
+ "react/no-default-props": "error",
725
+ "react/no-direct-mutation-state": "error",
726
+ "react/no-duplicate-jsx-props": "warn",
727
+ "react/no-duplicate-key": "warn",
728
+ "react/no-forward-ref": "warn",
729
+ "react/no-implicit-key": "warn",
730
+ "react/no-missing-key": "error",
731
+ "react/no-nested-component-definitions": "error",
732
+ "react/no-prop-types": "error",
733
+ "react/no-redundant-should-component-update": "error",
734
+ "react/no-set-state-in-component-did-mount": "warn",
735
+ "react/no-set-state-in-component-did-update": "warn",
736
+ "react/no-set-state-in-component-will-update": "warn",
737
+ "react/no-string-refs": "error",
738
+ "react/no-unsafe-component-will-mount": "warn",
739
+ "react/no-unsafe-component-will-receive-props": "warn",
740
+ "react/no-unsafe-component-will-update": "warn",
741
+ "react/no-unstable-context-value": "warn",
742
+ "react/no-unstable-default-props": "warn",
743
+ "react/no-unused-class-component-members": "warn",
744
+ "react/no-unused-state": "warn",
745
+ "react/no-use-context": "warn",
746
+ "react/no-useless-forward-ref": "warn",
747
+ "react/use-jsx-vars": "warn",
748
+ "react-dom/no-dangerously-set-innerhtml": "warn",
749
+ "react-dom/no-dangerously-set-innerhtml-with-children": "error",
750
+ "react-dom/no-find-dom-node": "error",
751
+ "react-dom/no-flush-sync": "error",
752
+ "react-dom/no-hydrate": "error",
753
+ "react-dom/no-missing-button-type": "warn",
754
+ "react-dom/no-missing-iframe-sandbox": "warn",
755
+ "react-dom/no-namespace": "error",
756
+ "react-dom/no-render": "error",
757
+ "react-dom/no-render-return-value": "error",
758
+ "react-dom/no-script-url": "warn",
759
+ "react-dom/no-unsafe-iframe-sandbox": "warn",
760
+ "react-dom/no-unsafe-target-blank": "warn",
761
+ "react-dom/no-use-form-state": "error",
762
+ "react-dom/no-void-elements-with-children": "error",
763
+ "react-hooks/exhaustive-deps": "warn",
764
+ "react-hooks/rules-of-hooks": "error",
765
+ "react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
766
+ "react-hooks-extra/no-unnecessary-use-prefix": "warn",
767
+ "react-web-api/no-leaked-event-listener": "warn",
768
+ "react-web-api/no-leaked-interval": "warn",
769
+ "react-web-api/no-leaked-resize-observer": "warn",
770
+ "react-web-api/no-leaked-timeout": "warn",
771
+ "react-refresh/only-export-components": ["warn", {
772
+ allowConstantExport: isAllowConstantExport,
773
+ allowExportNames: [...isUsingNext ? [
774
+ "dynamic",
775
+ "dynamicParams",
776
+ "revalidate",
777
+ "fetchCache",
778
+ "runtime",
779
+ "preferredRegion",
780
+ "maxDuration",
781
+ "config",
782
+ "generateStaticParams",
783
+ "metadata",
784
+ "generateMetadata",
785
+ "viewport",
786
+ "generateViewport"
787
+ ] : [], ...isUsingRemix || isUsingReactRouter ? [
788
+ "meta",
789
+ "links",
790
+ "headers",
791
+ "loader",
792
+ "action"
793
+ ] : []]
794
+ }],
795
+ ...overrides
796
+ }
797
+ },
798
+ ...isTypeAware ? [{
799
+ files: filesTypeAware,
800
+ ignores: ignoresTypeAware,
801
+ name: "antfu/react/type-aware-rules",
802
+ rules: { ...typeAwareRules }
803
+ }] : []
804
+ ];
831
805
  }
832
806
 
833
- // src/configs/regexp.ts
834
- import { configs } from "eslint-plugin-regexp";
807
+ //#endregion
808
+ //#region src/configs/regexp.ts
835
809
  function regexp(options = {}) {
836
- const config = configs["flat/recommended"];
837
- const rules = {
838
- ...config.rules
839
- };
840
- if (options.level === "warn") {
841
- Object.keys(rules).forEach((key) => {
842
- if (rules[key] === "error") rules[key] = "warn";
843
- });
844
- }
845
- return [
846
- {
847
- ...config,
848
- name: "coderwyd/regexp/rules",
849
- rules: {
850
- ...rules,
851
- ...options.overrides
852
- }
853
- }
854
- ];
810
+ const config = configs["flat/recommended"];
811
+ const rules = { ...config.rules };
812
+ if (options.level === "warn") Object.keys(rules).forEach((key) => {
813
+ if (rules[key] === "error") rules[key] = "warn";
814
+ });
815
+ return [{
816
+ ...config,
817
+ name: "coderwyd/regexp/rules",
818
+ rules: {
819
+ ...rules,
820
+ ...options.overrides
821
+ }
822
+ }];
855
823
  }
856
824
 
857
- // src/configs/sort.ts
825
+ //#endregion
826
+ //#region src/configs/sort.ts
827
+ /**
828
+ * Sort package.json
829
+ *
830
+ * Requires `jsonc` config
831
+ */
858
832
  function sortPackageJson() {
859
- return [
860
- {
861
- files: ["**/package.json"],
862
- name: "coderwyd/sort/package-json",
863
- rules: {
864
- "jsonc/sort-array-values": [
865
- "error",
866
- {
867
- order: { type: "asc" },
868
- pathPattern: "^files$"
869
- }
870
- ],
871
- "jsonc/sort-keys": [
872
- "error",
873
- {
874
- order: [
875
- "publisher",
876
- "name",
877
- "displayName",
878
- "type",
879
- "version",
880
- "private",
881
- "packageManager",
882
- "description",
883
- "author",
884
- "license",
885
- "funding",
886
- "homepage",
887
- "repository",
888
- "bugs",
889
- "keywords",
890
- "categories",
891
- "sideEffects",
892
- "exports",
893
- "main",
894
- "module",
895
- "unpkg",
896
- "jsdelivr",
897
- "types",
898
- "typesVersions",
899
- "bin",
900
- "icon",
901
- "files",
902
- "engines",
903
- "activationEvents",
904
- "contributes",
905
- "scripts",
906
- "peerDependencies",
907
- "peerDependenciesMeta",
908
- "dependencies",
909
- "optionalDependencies",
910
- "devDependencies",
911
- "pnpm",
912
- "overrides",
913
- "resolutions",
914
- "husky",
915
- "simple-git-hooks",
916
- "lint-staged",
917
- "nano-staged",
918
- "eslintConfig"
919
- ],
920
- pathPattern: "^$"
921
- },
922
- {
923
- order: { type: "asc" },
924
- pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
925
- },
926
- {
927
- order: { type: "asc" },
928
- pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
929
- },
930
- {
931
- order: ["types", "import", "require", "default"],
932
- pathPattern: "^exports.*$"
933
- },
934
- {
935
- order: [
936
- // client hooks only
937
- "pre-commit",
938
- "prepare-commit-msg",
939
- "commit-msg",
940
- "post-commit",
941
- "pre-rebase",
942
- "post-rewrite",
943
- "post-checkout",
944
- "post-merge",
945
- "pre-push",
946
- "pre-auto-gc"
947
- ],
948
- pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
949
- }
950
- ]
951
- }
952
- }
953
- ];
833
+ return [{
834
+ files: ["**/package.json"],
835
+ name: "coderwyd/sort/package-json",
836
+ rules: {
837
+ "jsonc/sort-array-values": ["error", {
838
+ order: { type: "asc" },
839
+ pathPattern: "^files$"
840
+ }],
841
+ "jsonc/sort-keys": [
842
+ "error",
843
+ {
844
+ order: [
845
+ "publisher",
846
+ "name",
847
+ "displayName",
848
+ "type",
849
+ "version",
850
+ "private",
851
+ "packageManager",
852
+ "description",
853
+ "author",
854
+ "license",
855
+ "funding",
856
+ "homepage",
857
+ "repository",
858
+ "bugs",
859
+ "keywords",
860
+ "categories",
861
+ "sideEffects",
862
+ "exports",
863
+ "main",
864
+ "module",
865
+ "unpkg",
866
+ "jsdelivr",
867
+ "types",
868
+ "typesVersions",
869
+ "bin",
870
+ "icon",
871
+ "files",
872
+ "engines",
873
+ "activationEvents",
874
+ "contributes",
875
+ "scripts",
876
+ "peerDependencies",
877
+ "peerDependenciesMeta",
878
+ "dependencies",
879
+ "optionalDependencies",
880
+ "devDependencies",
881
+ "pnpm",
882
+ "overrides",
883
+ "resolutions",
884
+ "husky",
885
+ "simple-git-hooks",
886
+ "lint-staged",
887
+ "nano-staged",
888
+ "eslintConfig"
889
+ ],
890
+ pathPattern: "^$"
891
+ },
892
+ {
893
+ order: { type: "asc" },
894
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
895
+ },
896
+ {
897
+ order: { type: "asc" },
898
+ pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
899
+ },
900
+ {
901
+ order: [
902
+ "types",
903
+ "import",
904
+ "require",
905
+ "default"
906
+ ],
907
+ pathPattern: "^exports.*$"
908
+ },
909
+ {
910
+ order: [
911
+ "pre-commit",
912
+ "prepare-commit-msg",
913
+ "commit-msg",
914
+ "post-commit",
915
+ "pre-rebase",
916
+ "post-rewrite",
917
+ "post-checkout",
918
+ "post-merge",
919
+ "pre-push",
920
+ "pre-auto-gc"
921
+ ],
922
+ pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
923
+ }
924
+ ]
925
+ }
926
+ }];
954
927
  }
928
+ /**
929
+ * Sort tsconfig.json
930
+ *
931
+ * Requires `jsonc` config
932
+ */
955
933
  function sortTsconfig() {
956
- return [
957
- {
958
- files: ["**/tsconfig.json", "**/tsconfig.*.json"],
959
- name: "coderwyd/sort/tsconfig-json",
960
- rules: {
961
- "jsonc/sort-keys": [
962
- "error",
963
- {
964
- order: [
965
- "extends",
966
- "compilerOptions",
967
- "references",
968
- "files",
969
- "include",
970
- "exclude"
971
- ],
972
- pathPattern: "^$"
973
- },
974
- {
975
- order: [
976
- /* Projects */
977
- "incremental",
978
- "composite",
979
- "tsBuildInfoFile",
980
- "disableSourceOfProjectReferenceRedirect",
981
- "disableSolutionSearching",
982
- "disableReferencedProjectLoad",
983
- /* Language and Environment */
984
- "target",
985
- "jsx",
986
- "jsxFactory",
987
- "jsxFragmentFactory",
988
- "jsxImportSource",
989
- "lib",
990
- "moduleDetection",
991
- "noLib",
992
- "reactNamespace",
993
- "useDefineForClassFields",
994
- "emitDecoratorMetadata",
995
- "experimentalDecorators",
996
- /* Modules */
997
- "baseUrl",
998
- "rootDir",
999
- "rootDirs",
1000
- "customConditions",
1001
- "module",
1002
- "moduleResolution",
1003
- "moduleSuffixes",
1004
- "noResolve",
1005
- "paths",
1006
- "resolveJsonModule",
1007
- "resolvePackageJsonExports",
1008
- "resolvePackageJsonImports",
1009
- "typeRoots",
1010
- "types",
1011
- "allowArbitraryExtensions",
1012
- "allowImportingTsExtensions",
1013
- "allowUmdGlobalAccess",
1014
- /* JavaScript Support */
1015
- "allowJs",
1016
- "checkJs",
1017
- "maxNodeModuleJsDepth",
1018
- /* Type Checking */
1019
- "strict",
1020
- "strictBindCallApply",
1021
- "strictFunctionTypes",
1022
- "strictNullChecks",
1023
- "strictPropertyInitialization",
1024
- "allowUnreachableCode",
1025
- "allowUnusedLabels",
1026
- "alwaysStrict",
1027
- "exactOptionalPropertyTypes",
1028
- "noFallthroughCasesInSwitch",
1029
- "noImplicitAny",
1030
- "noImplicitOverride",
1031
- "noImplicitReturns",
1032
- "noImplicitThis",
1033
- "noPropertyAccessFromIndexSignature",
1034
- "noUncheckedIndexedAccess",
1035
- "noUnusedLocals",
1036
- "noUnusedParameters",
1037
- "useUnknownInCatchVariables",
1038
- /* Emit */
1039
- "declaration",
1040
- "declarationDir",
1041
- "declarationMap",
1042
- "downlevelIteration",
1043
- "emitBOM",
1044
- "emitDeclarationOnly",
1045
- "importHelpers",
1046
- "importsNotUsedAsValues",
1047
- "inlineSourceMap",
1048
- "inlineSources",
1049
- "mapRoot",
1050
- "newLine",
1051
- "noEmit",
1052
- "noEmitHelpers",
1053
- "noEmitOnError",
1054
- "outDir",
1055
- "outFile",
1056
- "preserveConstEnums",
1057
- "preserveValueImports",
1058
- "removeComments",
1059
- "sourceMap",
1060
- "sourceRoot",
1061
- "stripInternal",
1062
- /* Interop Constraints */
1063
- "allowSyntheticDefaultImports",
1064
- "esModuleInterop",
1065
- "forceConsistentCasingInFileNames",
1066
- "isolatedDeclarations",
1067
- "isolatedModules",
1068
- "preserveSymlinks",
1069
- "verbatimModuleSyntax",
1070
- /* Completeness */
1071
- "skipDefaultLibCheck",
1072
- "skipLibCheck"
1073
- ],
1074
- pathPattern: "^compilerOptions$"
1075
- }
1076
- ]
1077
- }
1078
- }
1079
- ];
934
+ return [{
935
+ files: ["**/tsconfig.json", "**/tsconfig.*.json"],
936
+ name: "coderwyd/sort/tsconfig-json",
937
+ rules: { "jsonc/sort-keys": [
938
+ "error",
939
+ {
940
+ order: [
941
+ "extends",
942
+ "compilerOptions",
943
+ "references",
944
+ "files",
945
+ "include",
946
+ "exclude"
947
+ ],
948
+ pathPattern: "^$"
949
+ },
950
+ {
951
+ order: [
952
+ "incremental",
953
+ "composite",
954
+ "tsBuildInfoFile",
955
+ "disableSourceOfProjectReferenceRedirect",
956
+ "disableSolutionSearching",
957
+ "disableReferencedProjectLoad",
958
+ "target",
959
+ "jsx",
960
+ "jsxFactory",
961
+ "jsxFragmentFactory",
962
+ "jsxImportSource",
963
+ "lib",
964
+ "moduleDetection",
965
+ "noLib",
966
+ "reactNamespace",
967
+ "useDefineForClassFields",
968
+ "emitDecoratorMetadata",
969
+ "experimentalDecorators",
970
+ "libReplacement",
971
+ "baseUrl",
972
+ "rootDir",
973
+ "rootDirs",
974
+ "customConditions",
975
+ "module",
976
+ "moduleResolution",
977
+ "moduleSuffixes",
978
+ "noResolve",
979
+ "paths",
980
+ "resolveJsonModule",
981
+ "resolvePackageJsonExports",
982
+ "resolvePackageJsonImports",
983
+ "typeRoots",
984
+ "types",
985
+ "allowArbitraryExtensions",
986
+ "allowImportingTsExtensions",
987
+ "allowUmdGlobalAccess",
988
+ "allowJs",
989
+ "checkJs",
990
+ "maxNodeModuleJsDepth",
991
+ "strict",
992
+ "strictBindCallApply",
993
+ "strictFunctionTypes",
994
+ "strictNullChecks",
995
+ "strictPropertyInitialization",
996
+ "allowUnreachableCode",
997
+ "allowUnusedLabels",
998
+ "alwaysStrict",
999
+ "exactOptionalPropertyTypes",
1000
+ "noFallthroughCasesInSwitch",
1001
+ "noImplicitAny",
1002
+ "noImplicitOverride",
1003
+ "noImplicitReturns",
1004
+ "noImplicitThis",
1005
+ "noPropertyAccessFromIndexSignature",
1006
+ "noUncheckedIndexedAccess",
1007
+ "noUnusedLocals",
1008
+ "noUnusedParameters",
1009
+ "useUnknownInCatchVariables",
1010
+ "declaration",
1011
+ "declarationDir",
1012
+ "declarationMap",
1013
+ "downlevelIteration",
1014
+ "emitBOM",
1015
+ "emitDeclarationOnly",
1016
+ "importHelpers",
1017
+ "importsNotUsedAsValues",
1018
+ "inlineSourceMap",
1019
+ "inlineSources",
1020
+ "mapRoot",
1021
+ "newLine",
1022
+ "noEmit",
1023
+ "noEmitHelpers",
1024
+ "noEmitOnError",
1025
+ "outDir",
1026
+ "outFile",
1027
+ "preserveConstEnums",
1028
+ "preserveValueImports",
1029
+ "removeComments",
1030
+ "sourceMap",
1031
+ "sourceRoot",
1032
+ "stripInternal",
1033
+ "allowSyntheticDefaultImports",
1034
+ "esModuleInterop",
1035
+ "forceConsistentCasingInFileNames",
1036
+ "isolatedDeclarations",
1037
+ "isolatedModules",
1038
+ "preserveSymlinks",
1039
+ "verbatimModuleSyntax",
1040
+ "erasableSyntaxOnly",
1041
+ "skipDefaultLibCheck",
1042
+ "skipLibCheck"
1043
+ ],
1044
+ pathPattern: "^compilerOptions$"
1045
+ }
1046
+ ] }
1047
+ }];
1080
1048
  }
1081
1049
 
1082
- // src/configs/specials.ts
1050
+ //#endregion
1051
+ //#region src/configs/specials.ts
1083
1052
  function specials() {
1084
- return [
1085
- {
1086
- files: [`**/scripts/${GLOB_SRC}`],
1087
- name: "coderwyd/specials/scripts",
1088
- rules: {
1089
- "antfu/no-top-level-await": "off",
1090
- "no-console": "off",
1091
- "ts/explicit-function-return-type": "off"
1092
- }
1093
- },
1094
- {
1095
- files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`],
1096
- name: "coderwyd/specials/cli",
1097
- rules: {
1098
- "antfu/no-top-level-await": "off",
1099
- "no-console": "off"
1100
- }
1101
- },
1102
- {
1103
- files: ["**/bin/**/*", `**/bin.${GLOB_SRC_EXT}`],
1104
- name: "coderwyd/specials/bin",
1105
- rules: {
1106
- "antfu/no-import-dist": "off",
1107
- "antfu/no-import-node-modules-by-path": "off"
1108
- }
1109
- },
1110
- {
1111
- files: [GLOB_DTS],
1112
- name: "coderwyd/specials/dts",
1113
- rules: {
1114
- "eslint-comments/no-unlimited-disable": "off",
1115
- "import/no-duplicates": "off",
1116
- "no-restricted-syntax": "off",
1117
- "unused-imports/no-unused-vars": "off"
1118
- }
1119
- },
1120
- {
1121
- files: ["**/*.{test,spec}.([tj])s?(x)"],
1122
- name: "coderwyd/specials/test",
1123
- rules: {
1124
- "antfu/no-top-level-await": "off",
1125
- "no-unused-expressions": "off"
1126
- }
1127
- },
1128
- {
1129
- files: ["**/*.js", "**/*.cjs"],
1130
- name: "coderwyd/specials/cjs",
1131
- rules: {
1132
- "ts/no-require-imports": "off"
1133
- }
1134
- }
1135
- ];
1053
+ return [
1054
+ {
1055
+ files: [`**/scripts/${GLOB_SRC}`],
1056
+ name: "coderwyd/specials/scripts",
1057
+ rules: {
1058
+ "antfu/no-top-level-await": "off",
1059
+ "no-console": "off",
1060
+ "ts/explicit-function-return-type": "off"
1061
+ }
1062
+ },
1063
+ {
1064
+ files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`],
1065
+ name: "coderwyd/specials/cli",
1066
+ rules: {
1067
+ "antfu/no-top-level-await": "off",
1068
+ "no-console": "off"
1069
+ }
1070
+ },
1071
+ {
1072
+ files: ["**/bin/**/*", `**/bin.${GLOB_SRC_EXT}`],
1073
+ name: "coderwyd/specials/bin",
1074
+ rules: {
1075
+ "antfu/no-import-dist": "off",
1076
+ "antfu/no-import-node-modules-by-path": "off"
1077
+ }
1078
+ },
1079
+ {
1080
+ files: [GLOB_DTS],
1081
+ name: "coderwyd/specials/dts",
1082
+ rules: {
1083
+ "eslint-comments/no-unlimited-disable": "off",
1084
+ "import/no-duplicates": "off",
1085
+ "no-restricted-syntax": "off",
1086
+ "unused-imports/no-unused-vars": "off"
1087
+ }
1088
+ },
1089
+ {
1090
+ files: ["**/*.{test,spec}.([tj])s?(x)"],
1091
+ name: "coderwyd/specials/test",
1092
+ rules: {
1093
+ "antfu/no-top-level-await": "off",
1094
+ "no-unused-expressions": "off"
1095
+ }
1096
+ },
1097
+ {
1098
+ files: ["**/*.js", "**/*.cjs"],
1099
+ name: "coderwyd/specials/cjs",
1100
+ rules: { "ts/no-require-imports": "off" }
1101
+ }
1102
+ ];
1136
1103
  }
1137
1104
 
1138
- // src/configs/svelte.ts
1105
+ //#endregion
1106
+ //#region src/configs/svelte.ts
1139
1107
  async function svelte(options = {}) {
1140
- const { files = [GLOB_SVELTE], overrides = {} } = options;
1141
- await ensurePackages(["eslint-plugin-svelte"]);
1142
- const [pluginSvelte, parserSvelte] = await Promise.all([
1143
- interopDefault(import("eslint-plugin-svelte")),
1144
- interopDefault(import("svelte-eslint-parser"))
1145
- ]);
1146
- return [
1147
- {
1148
- name: "coderwyd/svelte/setup",
1149
- plugins: {
1150
- svelte: pluginSvelte
1151
- }
1152
- },
1153
- {
1154
- files,
1155
- languageOptions: {
1156
- parser: parserSvelte,
1157
- parserOptions: {
1158
- extraFileExtensions: [".svelte"],
1159
- parser: options.typescript ? await interopDefault(
1160
- import("@typescript-eslint/parser")
1161
- ) : null
1162
- }
1163
- },
1164
- name: "coderwyd/svelte/rules",
1165
- processor: pluginSvelte.processors[".svelte"],
1166
- rules: {
1167
- "import/no-mutable-exports": "off",
1168
- "no-undef": "off",
1169
- // incompatible with most recent (attribute-form) generic types RFC
1170
- "no-unused-vars": [
1171
- "error",
1172
- {
1173
- args: "none",
1174
- caughtErrors: "none",
1175
- ignoreRestSiblings: true,
1176
- vars: "all",
1177
- varsIgnorePattern: "^(\\$\\$Props$|\\$\\$Events$|\\$\\$Slots$)"
1178
- }
1179
- ],
1180
- "svelte/comment-directive": "error",
1181
- "svelte/no-at-debug-tags": "warn",
1182
- "svelte/no-at-html-tags": "error",
1183
- "svelte/no-dupe-else-if-blocks": "error",
1184
- "svelte/no-dupe-style-properties": "error",
1185
- "svelte/no-dupe-use-directives": "error",
1186
- "svelte/no-dynamic-slot-name": "error",
1187
- "svelte/no-export-load-in-svelte-module-in-kit-pages": "error",
1188
- "svelte/no-inner-declarations": "error",
1189
- "svelte/no-not-function-handler": "error",
1190
- "svelte/no-object-in-text-mustaches": "error",
1191
- "svelte/no-reactive-functions": "error",
1192
- "svelte/no-reactive-literals": "error",
1193
- "svelte/no-shorthand-style-property-overrides": "error",
1194
- "svelte/no-unknown-style-directive-property": "error",
1195
- "svelte/no-unused-svelte-ignore": "error",
1196
- "svelte/no-useless-mustaches": "error",
1197
- "svelte/require-store-callbacks-use-set-param": "error",
1198
- "svelte/system": "error",
1199
- "svelte/valid-each-key": "error",
1200
- "unused-imports/no-unused-vars": [
1201
- "error",
1202
- {
1203
- args: "after-used",
1204
- argsIgnorePattern: "^_",
1205
- vars: "all",
1206
- varsIgnorePattern: "^(_|\\$\\$Props$|\\$\\$Events$|\\$\\$Slots$)"
1207
- }
1208
- ],
1209
- ...overrides
1210
- }
1211
- }
1212
- ];
1108
+ const { files = [GLOB_SVELTE], overrides = {} } = options;
1109
+ await ensurePackages(["eslint-plugin-svelte"]);
1110
+ const [pluginSvelte, parserSvelte] = await Promise.all([interopDefault(import("eslint-plugin-svelte")), interopDefault(import("svelte-eslint-parser"))]);
1111
+ return [{
1112
+ name: "coderwyd/svelte/setup",
1113
+ plugins: { svelte: pluginSvelte }
1114
+ }, {
1115
+ files,
1116
+ languageOptions: {
1117
+ parser: parserSvelte,
1118
+ parserOptions: {
1119
+ extraFileExtensions: [".svelte"],
1120
+ parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null
1121
+ }
1122
+ },
1123
+ name: "coderwyd/svelte/rules",
1124
+ processor: pluginSvelte.processors[".svelte"],
1125
+ rules: {
1126
+ "import/no-mutable-exports": "off",
1127
+ "no-undef": "off",
1128
+ "no-unused-vars": ["error", {
1129
+ args: "none",
1130
+ caughtErrors: "none",
1131
+ ignoreRestSiblings: true,
1132
+ vars: "all",
1133
+ varsIgnorePattern: "^(\\$\\$Props$|\\$\\$Events$|\\$\\$Slots$)"
1134
+ }],
1135
+ "svelte/comment-directive": "error",
1136
+ "svelte/no-at-debug-tags": "warn",
1137
+ "svelte/no-at-html-tags": "error",
1138
+ "svelte/no-dupe-else-if-blocks": "error",
1139
+ "svelte/no-dupe-style-properties": "error",
1140
+ "svelte/no-dupe-use-directives": "error",
1141
+ "svelte/no-dynamic-slot-name": "error",
1142
+ "svelte/no-export-load-in-svelte-module-in-kit-pages": "error",
1143
+ "svelte/no-inner-declarations": "error",
1144
+ "svelte/no-not-function-handler": "error",
1145
+ "svelte/no-object-in-text-mustaches": "error",
1146
+ "svelte/no-reactive-functions": "error",
1147
+ "svelte/no-reactive-literals": "error",
1148
+ "svelte/no-shorthand-style-property-overrides": "error",
1149
+ "svelte/no-unknown-style-directive-property": "error",
1150
+ "svelte/no-unused-svelte-ignore": "error",
1151
+ "svelte/no-useless-mustaches": "error",
1152
+ "svelte/require-store-callbacks-use-set-param": "error",
1153
+ "svelte/system": "error",
1154
+ "svelte/valid-each-key": "error",
1155
+ "unused-imports/no-unused-vars": ["error", {
1156
+ args: "after-used",
1157
+ argsIgnorePattern: "^_",
1158
+ vars: "all",
1159
+ varsIgnorePattern: "^(_|\\$\\$Props$|\\$\\$Events$|\\$\\$Slots$)"
1160
+ }],
1161
+ ...overrides
1162
+ }
1163
+ }];
1213
1164
  }
1214
1165
 
1215
- // src/configs/tailwindcss.ts
1166
+ //#endregion
1167
+ //#region src/configs/tailwindcss.ts
1216
1168
  async function tailwindcss(options = {}) {
1217
- const { overrides } = options;
1218
- await ensurePackages(["eslint-plugin-tailwindcss"]);
1219
- const pluginTailwindcss = await interopDefault(
1220
- import("eslint-plugin-tailwindcss")
1221
- );
1222
- return [
1223
- {
1224
- name: "coderwyd/tailwindcss/rules",
1225
- plugins: {
1226
- tailwindcss: pluginTailwindcss
1227
- },
1228
- rules: {
1229
- "tailwindcss/classnames-order": "warn",
1230
- "tailwindcss/enforces-negative-arbitrary-values": "warn",
1231
- "tailwindcss/enforces-shorthand": "warn",
1232
- "tailwindcss/migration-from-tailwind-2": "warn",
1233
- "tailwindcss/no-arbitrary-value": "off",
1234
- "tailwindcss/no-contradicting-classname": "warn",
1235
- "tailwindcss/no-custom-classname": "off",
1236
- "tailwindcss/no-unnecessary-arbitrary-value": "warn",
1237
- ...overrides
1238
- }
1239
- }
1240
- ];
1169
+ const { overrides } = options;
1170
+ await ensurePackages(["eslint-plugin-tailwindcss"]);
1171
+ const pluginTailwindcss = await interopDefault(import("eslint-plugin-tailwindcss"));
1172
+ return [{
1173
+ name: "coderwyd/tailwindcss/rules",
1174
+ plugins: { tailwindcss: pluginTailwindcss },
1175
+ rules: {
1176
+ "tailwindcss/classnames-order": "warn",
1177
+ "tailwindcss/enforces-negative-arbitrary-values": "warn",
1178
+ "tailwindcss/enforces-shorthand": "warn",
1179
+ "tailwindcss/migration-from-tailwind-2": "warn",
1180
+ "tailwindcss/no-arbitrary-value": "off",
1181
+ "tailwindcss/no-contradicting-classname": "warn",
1182
+ "tailwindcss/no-custom-classname": "off",
1183
+ "tailwindcss/no-unnecessary-arbitrary-value": "warn",
1184
+ ...overrides
1185
+ }
1186
+ }];
1241
1187
  }
1242
1188
 
1243
- // src/configs/test.ts
1244
- var _pluginTest;
1189
+ //#endregion
1190
+ //#region src/configs/test.ts
1191
+ let _pluginTest;
1245
1192
  async function test(options = {}) {
1246
- const { files = GLOB_TESTS, isInEditor: isInEditor2 = false, overrides = {} } = options;
1247
- const [pluginVitest, pluginNoOnlyTests] = await Promise.all([
1248
- interopDefault(import("@vitest/eslint-plugin")),
1249
- // @ts-expect-error missing types
1250
- interopDefault(import("eslint-plugin-no-only-tests"))
1251
- ]);
1252
- _pluginTest = _pluginTest || {
1253
- ...pluginVitest,
1254
- rules: {
1255
- ...pluginVitest.rules,
1256
- // extend `test/no-only-tests` rule
1257
- ...pluginNoOnlyTests.rules
1258
- }
1259
- };
1260
- return [
1261
- {
1262
- name: "coderwyd/test/setup",
1263
- plugins: {
1264
- test: _pluginTest
1265
- }
1266
- },
1267
- {
1268
- files,
1269
- name: "coderwyd/test/rules",
1270
- rules: {
1271
- "node/prefer-global/process": "off",
1272
- "test/consistent-test-it": [
1273
- "error",
1274
- { fn: "it", withinDescribe: "it" }
1275
- ],
1276
- "test/no-identical-title": "error",
1277
- "test/no-import-node-test": "error",
1278
- "test/no-only-tests": isInEditor2 ? "off" : "error",
1279
- "test/prefer-hooks-in-order": "error",
1280
- "test/prefer-lowercase-title": "error",
1281
- "ts/explicit-function-return-type": "off",
1282
- ...overrides
1283
- }
1284
- }
1285
- ];
1193
+ const { files = GLOB_TESTS, isInEditor: isInEditor$1 = false, overrides = {} } = options;
1194
+ const [pluginVitest, pluginNoOnlyTests] = await Promise.all([interopDefault(import("@vitest/eslint-plugin")), interopDefault(import("eslint-plugin-no-only-tests"))]);
1195
+ _pluginTest = _pluginTest || {
1196
+ ...pluginVitest,
1197
+ rules: {
1198
+ ...pluginVitest.rules,
1199
+ ...pluginNoOnlyTests.rules
1200
+ }
1201
+ };
1202
+ return [{
1203
+ name: "coderwyd/test/setup",
1204
+ plugins: { test: _pluginTest }
1205
+ }, {
1206
+ files,
1207
+ name: "coderwyd/test/rules",
1208
+ rules: {
1209
+ "node/prefer-global/process": "off",
1210
+ "test/consistent-test-it": ["error", {
1211
+ fn: "it",
1212
+ withinDescribe: "it"
1213
+ }],
1214
+ "test/no-identical-title": "error",
1215
+ "test/no-import-node-test": "error",
1216
+ "test/no-only-tests": isInEditor$1 ? "off" : "error",
1217
+ "test/prefer-hooks-in-order": "error",
1218
+ "test/prefer-lowercase-title": "error",
1219
+ "ts/explicit-function-return-type": "off",
1220
+ ...overrides
1221
+ }
1222
+ }];
1286
1223
  }
1287
1224
 
1288
- // src/configs/typescript.ts
1289
- import process3 from "node:process";
1225
+ //#endregion
1226
+ //#region src/configs/typescript.ts
1290
1227
  async function typescript(options = {}) {
1291
- const {
1292
- componentExts = [],
1293
- overrides = {},
1294
- overridesTypeAware = {},
1295
- parserOptions = {}
1296
- } = options;
1297
- const files = options.files ?? [
1298
- GLOB_TS,
1299
- GLOB_TSX,
1300
- ...componentExts.map((ext) => `**/*.${ext}`)
1301
- ];
1302
- const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
1303
- const ignoresTypeAware = options.ignoresTypeAware ?? [
1304
- `${GLOB_MARKDOWN}/**`,
1305
- GLOB_ASTRO_TS
1306
- ];
1307
- const tsconfigPath = options.tsconfigPath;
1308
- const isTypeAware = !!tsconfigPath;
1309
- const typeAwareRules = {
1310
- "dot-notation": "off",
1311
- "no-implied-eval": "off",
1312
- "ts/await-thenable": "error",
1313
- "ts/dot-notation": ["error", { allowKeywords: true }],
1314
- "ts/no-floating-promises": "error",
1315
- "ts/no-for-in-array": "error",
1316
- "ts/no-implied-eval": "error",
1317
- "ts/no-misused-promises": "error",
1318
- "ts/no-unnecessary-type-assertion": "error",
1319
- "ts/no-unsafe-argument": "error",
1320
- "ts/no-unsafe-assignment": "error",
1321
- "ts/no-unsafe-call": "error",
1322
- "ts/no-unsafe-member-access": "error",
1323
- "ts/no-unsafe-return": "error",
1324
- "ts/promise-function-async": "error",
1325
- "ts/restrict-plus-operands": "error",
1326
- "ts/restrict-template-expressions": "error",
1327
- "ts/return-await": "error",
1328
- "ts/strict-boolean-expressions": "error",
1329
- "ts/switch-exhaustiveness-check": "error",
1330
- "ts/unbound-method": "error"
1331
- };
1332
- const [pluginTs, parserTs] = await Promise.all([
1333
- interopDefault(import("@typescript-eslint/eslint-plugin")),
1334
- interopDefault(import("@typescript-eslint/parser"))
1335
- ]);
1336
- function makeParser(typeAware, files2, ignores2) {
1337
- return {
1338
- files: files2,
1339
- ...ignores2 ? { ignores: ignores2 } : {},
1340
- languageOptions: {
1341
- parser: parserTs,
1342
- parserOptions: {
1343
- extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1344
- sourceType: "module",
1345
- ...typeAware ? {
1346
- projectService: {
1347
- allowDefaultProject: ["./*.js"],
1348
- defaultProject: tsconfigPath
1349
- },
1350
- tsconfigRootDir: process3.cwd()
1351
- } : {},
1352
- ...parserOptions
1353
- }
1354
- },
1355
- name: `coderwyd/typescript/${typeAware ? "type-aware-parser" : "parser"}`
1356
- };
1357
- }
1358
- return [
1359
- {
1360
- // Install the plugins without globs, so they can be configured separately.
1361
- name: "coderwyd/typescript/setup",
1362
- plugins: {
1363
- antfu: default3,
1364
- ts: pluginTs
1365
- }
1366
- },
1367
- // assign type-aware parser for type-aware files and type-unaware parser for the rest
1368
- ...isTypeAware ? [
1369
- makeParser(false, files),
1370
- makeParser(true, filesTypeAware, ignoresTypeAware)
1371
- ] : [makeParser(false, files)],
1372
- {
1373
- files,
1374
- name: "coderwyd/typescript/rules",
1375
- rules: {
1376
- ...renameRules(
1377
- pluginTs.configs["eslint-recommended"].overrides[0].rules,
1378
- { "@typescript-eslint": "ts" }
1379
- ),
1380
- ...renameRules(pluginTs.configs.strict.rules, {
1381
- "@typescript-eslint": "ts"
1382
- }),
1383
- "no-dupe-class-members": "off",
1384
- "no-redeclare": "off",
1385
- "no-use-before-define": "off",
1386
- "no-useless-constructor": "off",
1387
- "ts/ban-ts-comment": [
1388
- "error",
1389
- { "ts-expect-error": "allow-with-description" }
1390
- ],
1391
- "ts/consistent-type-definitions": ["error", "interface"],
1392
- "ts/consistent-type-imports": [
1393
- "error",
1394
- {
1395
- disallowTypeAnnotations: false,
1396
- fixStyle: "separate-type-imports",
1397
- prefer: "type-imports"
1398
- }
1399
- ],
1400
- "ts/method-signature-style": ["error", "property"],
1401
- // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
1402
- "ts/no-dupe-class-members": "error",
1403
- "ts/no-dynamic-delete": "off",
1404
- "ts/no-empty-object-type": [
1405
- "error",
1406
- {
1407
- allowInterfaces: "with-single-extends",
1408
- // interface Derived extends Base {}
1409
- allowObjectTypes: "never",
1410
- allowWithName: "Props$"
1411
- }
1412
- ],
1413
- "ts/no-explicit-any": "off",
1414
- "ts/no-extraneous-class": "off",
1415
- "ts/no-import-type-side-effects": "error",
1416
- "ts/no-invalid-void-type": "off",
1417
- "ts/no-non-null-assertion": "off",
1418
- "ts/no-redeclare": ["error", { builtinGlobals: false }],
1419
- "ts/no-require-imports": "error",
1420
- "ts/no-unused-expressions": [
1421
- "error",
1422
- {
1423
- allowShortCircuit: true,
1424
- allowTaggedTemplates: true,
1425
- allowTernary: true
1426
- }
1427
- ],
1428
- "ts/no-unused-vars": "off",
1429
- "ts/no-use-before-define": [
1430
- "error",
1431
- { classes: false, functions: false, variables: true }
1432
- ],
1433
- "ts/no-useless-constructor": "off",
1434
- "ts/no-wrapper-object-types": "error",
1435
- "ts/triple-slash-reference": "off",
1436
- "ts/unified-signatures": "off",
1437
- ...overrides
1438
- }
1439
- },
1440
- ...isTypeAware ? [
1441
- {
1442
- files: filesTypeAware,
1443
- ignores: ignoresTypeAware,
1444
- name: "coderwyd/typescript/rules-type-aware",
1445
- rules: {
1446
- ...typeAwareRules,
1447
- ...overridesTypeAware
1448
- }
1449
- }
1450
- ] : []
1451
- ];
1228
+ const { componentExts = [], overrides = {}, overridesTypeAware = {}, parserOptions = {} } = options;
1229
+ const files = options.files ?? [
1230
+ GLOB_TS,
1231
+ GLOB_TSX,
1232
+ ...componentExts.map((ext) => `**/*.${ext}`)
1233
+ ];
1234
+ const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
1235
+ const ignoresTypeAware = options.ignoresTypeAware ?? [`${GLOB_MARKDOWN}/**`, GLOB_ASTRO_TS];
1236
+ const tsconfigPath = options.tsconfigPath;
1237
+ const isTypeAware = !!tsconfigPath;
1238
+ const typeAwareRules = {
1239
+ "dot-notation": "off",
1240
+ "no-implied-eval": "off",
1241
+ "ts/await-thenable": "error",
1242
+ "ts/dot-notation": ["error", { allowKeywords: true }],
1243
+ "ts/no-floating-promises": "error",
1244
+ "ts/no-for-in-array": "error",
1245
+ "ts/no-implied-eval": "error",
1246
+ "ts/no-misused-promises": "error",
1247
+ "ts/no-unnecessary-type-assertion": "error",
1248
+ "ts/no-unsafe-argument": "error",
1249
+ "ts/no-unsafe-assignment": "error",
1250
+ "ts/no-unsafe-call": "error",
1251
+ "ts/no-unsafe-member-access": "error",
1252
+ "ts/no-unsafe-return": "error",
1253
+ "ts/promise-function-async": "error",
1254
+ "ts/restrict-plus-operands": "error",
1255
+ "ts/restrict-template-expressions": "error",
1256
+ "ts/return-await": "error",
1257
+ "ts/strict-boolean-expressions": "error",
1258
+ "ts/switch-exhaustiveness-check": "error",
1259
+ "ts/unbound-method": "error"
1260
+ };
1261
+ const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
1262
+ function makeParser(typeAware, files$1, ignores$1) {
1263
+ return {
1264
+ files: files$1,
1265
+ ...ignores$1 ? { ignores: ignores$1 } : {},
1266
+ languageOptions: {
1267
+ parser: parserTs,
1268
+ parserOptions: {
1269
+ extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1270
+ sourceType: "module",
1271
+ ...typeAware ? {
1272
+ projectService: {
1273
+ allowDefaultProject: ["./*.js"],
1274
+ defaultProject: tsconfigPath
1275
+ },
1276
+ tsconfigRootDir: process.cwd()
1277
+ } : {},
1278
+ ...parserOptions
1279
+ }
1280
+ },
1281
+ name: `coderwyd/typescript/${typeAware ? "type-aware-parser" : "parser"}`
1282
+ };
1283
+ }
1284
+ return [
1285
+ {
1286
+ name: "coderwyd/typescript/setup",
1287
+ plugins: {
1288
+ antfu: pluginAntfu,
1289
+ ts: pluginTs
1290
+ }
1291
+ },
1292
+ ...isTypeAware ? [makeParser(false, files), makeParser(true, filesTypeAware, ignoresTypeAware)] : [makeParser(false, files)],
1293
+ {
1294
+ files,
1295
+ name: "coderwyd/typescript/rules",
1296
+ rules: {
1297
+ ...renameRules(pluginTs.configs["eslint-recommended"].overrides[0].rules, { "@typescript-eslint": "ts" }),
1298
+ ...renameRules(pluginTs.configs.strict.rules, { "@typescript-eslint": "ts" }),
1299
+ "no-dupe-class-members": "off",
1300
+ "no-redeclare": "off",
1301
+ "no-use-before-define": "off",
1302
+ "no-useless-constructor": "off",
1303
+ "ts/ban-ts-comment": ["error", { "ts-expect-error": "allow-with-description" }],
1304
+ "ts/consistent-type-definitions": ["error", "interface"],
1305
+ "ts/consistent-type-imports": ["error", {
1306
+ disallowTypeAnnotations: false,
1307
+ fixStyle: "separate-type-imports",
1308
+ prefer: "type-imports"
1309
+ }],
1310
+ "ts/method-signature-style": ["error", "property"],
1311
+ "ts/no-dupe-class-members": "error",
1312
+ "ts/no-dynamic-delete": "off",
1313
+ "ts/no-empty-object-type": ["error", {
1314
+ allowInterfaces: "with-single-extends",
1315
+ allowObjectTypes: "never",
1316
+ allowWithName: "Props$"
1317
+ }],
1318
+ "ts/no-explicit-any": "off",
1319
+ "ts/no-extraneous-class": "off",
1320
+ "ts/no-import-type-side-effects": "error",
1321
+ "ts/no-invalid-void-type": "off",
1322
+ "ts/no-non-null-assertion": "off",
1323
+ "ts/no-redeclare": ["error", { builtinGlobals: false }],
1324
+ "ts/no-require-imports": "error",
1325
+ "ts/no-unused-expressions": ["error", {
1326
+ allowShortCircuit: true,
1327
+ allowTaggedTemplates: true,
1328
+ allowTernary: true
1329
+ }],
1330
+ "ts/no-unused-vars": "off",
1331
+ "ts/no-use-before-define": ["error", {
1332
+ classes: false,
1333
+ functions: false,
1334
+ variables: true
1335
+ }],
1336
+ "ts/no-useless-constructor": "off",
1337
+ "ts/no-wrapper-object-types": "error",
1338
+ "ts/triple-slash-reference": "off",
1339
+ "ts/unified-signatures": "off",
1340
+ ...overrides
1341
+ }
1342
+ },
1343
+ ...isTypeAware ? [{
1344
+ files: filesTypeAware,
1345
+ ignores: ignoresTypeAware,
1346
+ name: "coderwyd/typescript/rules-type-aware",
1347
+ rules: {
1348
+ ...typeAwareRules,
1349
+ ...overridesTypeAware
1350
+ }
1351
+ }] : []
1352
+ ];
1452
1353
  }
1453
1354
 
1454
- // src/configs/unicorn.ts
1355
+ //#endregion
1356
+ //#region src/configs/unicorn.ts
1455
1357
  function unicorn() {
1456
- return [
1457
- {
1458
- name: "coderwyd/unicorn/rules",
1459
- plugins: {
1460
- unicorn: default7
1461
- },
1462
- rules: {
1463
- // 'unicorn/better-regex': 'error',
1464
- "unicorn/catch-error-name": "error",
1465
- "unicorn/consistent-empty-array-spread": "error",
1466
- "unicorn/consistent-existence-index-check": "error",
1467
- "unicorn/custom-error-definition": "error",
1468
- "unicorn/error-message": "error",
1469
- // 'unicorn/explicit-length-check': 'error',
1470
- // 'unicorn/filename-case': [
1471
- // 'error',
1472
- // {
1473
- // cases: { kebabCase: true, pascalCase: true },
1474
- // ignore: [/^[A-Z]+\..*$/],
1475
- // },
1476
- "unicorn/escape-case": "error",
1477
- // ],
1478
- "unicorn/new-for-builtins": "error",
1479
- // 'unicorn/no-array-callback-reference': 'error',
1480
- "unicorn/no-array-method-this-argument": "error",
1481
- "unicorn/no-array-push-push": "error",
1482
- "unicorn/no-await-in-promise-methods": "error",
1483
- "unicorn/no-console-spaces": "error",
1484
- "unicorn/no-for-loop": "error",
1485
- "unicorn/no-hex-escape": "error",
1486
- "unicorn/no-instanceof-builtins": "error",
1487
- "unicorn/no-invalid-remove-event-listener": "error",
1488
- "unicorn/no-length-as-slice-end": "error",
1489
- "unicorn/no-lonely-if": "error",
1490
- "unicorn/no-negation-in-equality-check": "error",
1491
- "unicorn/no-new-array": "error",
1492
- "unicorn/no-new-buffer": "error",
1493
- "unicorn/no-single-promise-in-promise-methods": "error",
1494
- "unicorn/no-static-only-class": "error",
1495
- "unicorn/no-unnecessary-await": "error",
1496
- "unicorn/no-zero-fractions": "error",
1497
- "unicorn/prefer-add-event-listener": "error",
1498
- "unicorn/prefer-array-find": "error",
1499
- "unicorn/prefer-array-flat-map": "error",
1500
- "unicorn/prefer-array-index-of": "error",
1501
- "unicorn/prefer-array-some": "error",
1502
- "unicorn/prefer-at": "error",
1503
- "unicorn/prefer-blob-reading-methods": "error",
1504
- "unicorn/prefer-date-now": "error",
1505
- "unicorn/prefer-dom-node-append": "error",
1506
- "unicorn/prefer-dom-node-dataset": "error",
1507
- "unicorn/prefer-dom-node-remove": "error",
1508
- "unicorn/prefer-dom-node-text-content": "error",
1509
- "unicorn/prefer-includes": "error",
1510
- "unicorn/prefer-keyboard-event-key": "error",
1511
- "unicorn/prefer-math-min-max": "error",
1512
- "unicorn/prefer-math-trunc": "error",
1513
- "unicorn/prefer-modern-dom-apis": "error",
1514
- "unicorn/prefer-modern-math-apis": "error",
1515
- "unicorn/prefer-negative-index": "error",
1516
- "unicorn/prefer-node-protocol": "error",
1517
- "unicorn/prefer-number-properties": "error",
1518
- "unicorn/prefer-optional-catch-binding": "error",
1519
- "unicorn/prefer-prototype-methods": "error",
1520
- "unicorn/prefer-query-selector": "error",
1521
- "unicorn/prefer-reflect-apply": "error",
1522
- // 'unicorn/prefer-regexp-test': 'error',
1523
- "unicorn/prefer-string-replace-all": "error",
1524
- "unicorn/prefer-string-slice": "error",
1525
- "unicorn/prefer-string-starts-ends-with": "error",
1526
- "unicorn/prefer-string-trim-start-end": "error",
1527
- // top level await is not supported in all environments
1528
- // 'unicorn/prefer-top-level-await': 'error',
1529
- "unicorn/prefer-type-error": "error",
1530
- "unicorn/throw-new-error": "error"
1531
- }
1532
- }
1533
- ];
1358
+ return [{
1359
+ name: "coderwyd/unicorn/rules",
1360
+ plugins: { unicorn: pluginUnicorn },
1361
+ rules: {
1362
+ "unicorn/catch-error-name": "error",
1363
+ "unicorn/consistent-empty-array-spread": "error",
1364
+ "unicorn/consistent-existence-index-check": "error",
1365
+ "unicorn/custom-error-definition": "error",
1366
+ "unicorn/error-message": "error",
1367
+ "unicorn/escape-case": "error",
1368
+ "unicorn/new-for-builtins": "error",
1369
+ "unicorn/no-array-method-this-argument": "error",
1370
+ "unicorn/no-array-push-push": "error",
1371
+ "unicorn/no-await-in-promise-methods": "error",
1372
+ "unicorn/no-console-spaces": "error",
1373
+ "unicorn/no-for-loop": "error",
1374
+ "unicorn/no-hex-escape": "error",
1375
+ "unicorn/no-instanceof-builtins": "error",
1376
+ "unicorn/no-invalid-remove-event-listener": "error",
1377
+ "unicorn/no-length-as-slice-end": "error",
1378
+ "unicorn/no-lonely-if": "error",
1379
+ "unicorn/no-negation-in-equality-check": "error",
1380
+ "unicorn/no-new-array": "error",
1381
+ "unicorn/no-new-buffer": "error",
1382
+ "unicorn/no-single-promise-in-promise-methods": "error",
1383
+ "unicorn/no-static-only-class": "error",
1384
+ "unicorn/no-unnecessary-await": "error",
1385
+ "unicorn/no-zero-fractions": "error",
1386
+ "unicorn/prefer-add-event-listener": "error",
1387
+ "unicorn/prefer-array-find": "error",
1388
+ "unicorn/prefer-array-flat-map": "error",
1389
+ "unicorn/prefer-array-index-of": "error",
1390
+ "unicorn/prefer-array-some": "error",
1391
+ "unicorn/prefer-at": "error",
1392
+ "unicorn/prefer-blob-reading-methods": "error",
1393
+ "unicorn/prefer-date-now": "error",
1394
+ "unicorn/prefer-dom-node-append": "error",
1395
+ "unicorn/prefer-dom-node-dataset": "error",
1396
+ "unicorn/prefer-dom-node-remove": "error",
1397
+ "unicorn/prefer-dom-node-text-content": "error",
1398
+ "unicorn/prefer-includes": "error",
1399
+ "unicorn/prefer-keyboard-event-key": "error",
1400
+ "unicorn/prefer-math-min-max": "error",
1401
+ "unicorn/prefer-math-trunc": "error",
1402
+ "unicorn/prefer-modern-dom-apis": "error",
1403
+ "unicorn/prefer-modern-math-apis": "error",
1404
+ "unicorn/prefer-negative-index": "error",
1405
+ "unicorn/prefer-node-protocol": "error",
1406
+ "unicorn/prefer-number-properties": "error",
1407
+ "unicorn/prefer-optional-catch-binding": "error",
1408
+ "unicorn/prefer-prototype-methods": "error",
1409
+ "unicorn/prefer-query-selector": "error",
1410
+ "unicorn/prefer-reflect-apply": "error",
1411
+ "unicorn/prefer-string-replace-all": "error",
1412
+ "unicorn/prefer-string-slice": "error",
1413
+ "unicorn/prefer-string-starts-ends-with": "error",
1414
+ "unicorn/prefer-string-trim-start-end": "error",
1415
+ "unicorn/prefer-type-error": "error",
1416
+ "unicorn/throw-new-error": "error"
1417
+ }
1418
+ }];
1534
1419
  }
1535
1420
 
1536
- // src/configs/unocss.ts
1421
+ //#endregion
1422
+ //#region src/configs/unocss.ts
1537
1423
  async function unocss(options = {}) {
1538
- const { attributify = true, strict = false } = options;
1539
- await ensurePackages(["@unocss/eslint-plugin"]);
1540
- const [pluginUnoCSS] = await Promise.all([
1541
- interopDefault(import("@unocss/eslint-plugin"))
1542
- ]);
1543
- return [
1544
- {
1545
- name: "coderwyd/unocss/rules",
1546
- plugins: {
1547
- unocss: pluginUnoCSS
1548
- },
1549
- rules: {
1550
- "unocss/order": "warn",
1551
- ...attributify ? {
1552
- "unocss/order-attributify": "warn"
1553
- } : {},
1554
- ...strict ? {
1555
- "unocss/blocklist": "error"
1556
- } : {}
1557
- }
1558
- }
1559
- ];
1424
+ const { attributify = true, strict = false } = options;
1425
+ await ensurePackages(["@unocss/eslint-plugin"]);
1426
+ const [pluginUnoCSS] = await Promise.all([interopDefault(import("@unocss/eslint-plugin"))]);
1427
+ return [{
1428
+ name: "coderwyd/unocss/rules",
1429
+ plugins: { unocss: pluginUnoCSS },
1430
+ rules: {
1431
+ "unocss/order": "warn",
1432
+ ...attributify ? { "unocss/order-attributify": "warn" } : {},
1433
+ ...strict ? { "unocss/blocklist": "error" } : {}
1434
+ }
1435
+ }];
1560
1436
  }
1561
1437
 
1562
- // src/configs/vue.ts
1438
+ //#endregion
1439
+ //#region src/configs/vue.ts
1563
1440
  async function vue(options = {}) {
1564
- const { files = [GLOB_VUE], overrides = {} } = options;
1565
- const [pluginVue, parserVue] = await Promise.all([
1566
- interopDefault(import("eslint-plugin-vue")),
1567
- interopDefault(import("vue-eslint-parser"))
1568
- ]);
1569
- const isVue3 = getVueVersion() === 3;
1570
- const configKeys = isVue3 ? ["essential", "strongly-recommended", "recommended"] : ["vue2-essential", "vue2-strongly-recommended", "vue2-recommended"];
1571
- const vueRules = configKeys.reduce((preRules, key) => {
1572
- const config = pluginVue.configs[key];
1573
- return {
1574
- ...preRules,
1575
- ...config.rules
1576
- };
1577
- }, {});
1578
- return [
1579
- {
1580
- files,
1581
- languageOptions: {
1582
- parser: parserVue,
1583
- parserOptions: {
1584
- ecmaFeatures: {
1585
- jsx: true
1586
- },
1587
- extraFileExtensions: [".vue"],
1588
- parser: options.typescript ? await interopDefault(
1589
- import("@typescript-eslint/parser")
1590
- ) : null,
1591
- sourceType: "module"
1592
- }
1593
- },
1594
- name: "coderwyd/vue/rules",
1595
- plugins: {
1596
- vue: pluginVue
1597
- },
1598
- processor: pluginVue.processors[".vue"],
1599
- rules: {
1600
- ...pluginVue.configs.base.rules,
1601
- ...vueRules,
1602
- "antfu/no-top-level-await": "off",
1603
- "node/prefer-global/process": "off",
1604
- "ts/explicit-function-return-type": "off",
1605
- "vue/block-order": [
1606
- "error",
1607
- {
1608
- order: isVue3 ? ["script", "template", "style"] : ["template", "script", "style"]
1609
- }
1610
- ],
1611
- // 'vue/component-api-style': ['warn', ['script-setup', 'composition']],
1612
- "vue/component-name-in-template-casing": ["error", "PascalCase"],
1613
- "vue/component-options-name-casing": ["error", "PascalCase"],
1614
- // this is deprecated
1615
- "vue/component-tags-order": "off",
1616
- "vue/custom-event-name-casing": ["error", "camelCase"],
1617
- // 'vue/define-emits-declaration': ['warn', 'type-based'],
1618
- "vue/define-macros-order": [
1619
- "error",
1620
- {
1621
- order: [
1622
- "defineOptions",
1623
- "defineProps",
1624
- "defineEmits",
1625
- "defineSlots"
1626
- ]
1627
- }
1628
- ],
1629
- // 'vue/define-props-declaration': ['warn', 'type-based'],
1630
- "vue/eqeqeq": ["error", "smart"],
1631
- "vue/html-self-closing": [
1632
- "error",
1633
- {
1634
- html: {
1635
- component: "always",
1636
- normal: "always",
1637
- void: "any"
1638
- },
1639
- math: "always",
1640
- svg: "always"
1641
- }
1642
- ],
1643
- "vue/max-attributes-per-line": "off",
1644
- "vue/multi-word-component-names": "off",
1645
- // 'vue/next-tick-style': ['warn', 'promise'],
1646
- "vue/no-constant-condition": "warn",
1647
- "vue/no-duplicate-attr-inheritance": "warn",
1648
- "vue/no-empty-pattern": "error",
1649
- "vue/no-extra-parens": ["error", "functions"],
1650
- "vue/no-irregular-whitespace": "error",
1651
- "vue/no-loss-of-precision": "error",
1652
- "vue/no-required-prop-with-default": "warn",
1653
- "vue/no-restricted-syntax": [
1654
- "error",
1655
- "DebuggerStatement",
1656
- "LabeledStatement",
1657
- "WithStatement"
1658
- ],
1659
- "vue/no-restricted-v-bind": ["error", "/^v-/"],
1660
- "vue/no-setup-props-reactivity-loss": "off",
1661
- "vue/no-sparse-arrays": "error",
1662
- "vue/no-unsupported-features": "warn",
1663
- "vue/no-unused-emit-declarations": "warn",
1664
- "vue/no-unused-refs": "error",
1665
- "vue/no-use-v-else-with-v-for": "error",
1666
- "vue/no-useless-mustaches": "warn",
1667
- "vue/no-useless-v-bind": "error",
1668
- "vue/no-v-html": "off",
1669
- "vue/no-v-text": "warn",
1670
- "vue/object-shorthand": [
1671
- "error",
1672
- "always",
1673
- {
1674
- avoidQuotes: true,
1675
- ignoreConstructors: false
1676
- }
1677
- ],
1678
- "vue/padding-line-between-blocks": ["error", "always"],
1679
- "vue/prefer-define-options": "warn",
1680
- "vue/prefer-separate-static-class": "error",
1681
- "vue/prefer-template": "error",
1682
- "vue/prop-name-casing": ["error", "camelCase"],
1683
- "vue/require-default-prop": "off",
1684
- "vue/require-macro-variable-name": [
1685
- "warn",
1686
- {
1687
- defineEmits: "emit",
1688
- defineProps: "props",
1689
- defineSlots: "slots",
1690
- useAttrs: "attrs",
1691
- useSlots: "slots"
1692
- }
1693
- ],
1694
- "vue/require-prop-types": "off",
1695
- // 'vue/singleline-html-element-content-newline': 'off',
1696
- "vue/space-infix-ops": "error",
1697
- "vue/space-unary-ops": ["error", { nonwords: false, words: true }],
1698
- "vue/valid-define-options": "warn",
1699
- ...overrides
1700
- }
1701
- }
1702
- ];
1441
+ const { files = [GLOB_VUE], overrides = {} } = options;
1442
+ const [pluginVue, parserVue] = await Promise.all([interopDefault(import("eslint-plugin-vue")), interopDefault(import("vue-eslint-parser"))]);
1443
+ const isVue3 = getVueVersion() === 3;
1444
+ const configKeys = isVue3 ? [
1445
+ "essential",
1446
+ "strongly-recommended",
1447
+ "recommended"
1448
+ ] : [
1449
+ "vue2-essential",
1450
+ "vue2-strongly-recommended",
1451
+ "vue2-recommended"
1452
+ ];
1453
+ const vueRules = configKeys.reduce((preRules, key) => {
1454
+ const config = pluginVue.configs[key];
1455
+ return {
1456
+ ...preRules,
1457
+ ...config.rules
1458
+ };
1459
+ }, {});
1460
+ return [{
1461
+ files,
1462
+ languageOptions: {
1463
+ parser: parserVue,
1464
+ parserOptions: {
1465
+ ecmaFeatures: { jsx: true },
1466
+ extraFileExtensions: [".vue"],
1467
+ parser: options.typescript ? await interopDefault(import("@typescript-eslint/parser")) : null,
1468
+ sourceType: "module"
1469
+ }
1470
+ },
1471
+ name: "coderwyd/vue/rules",
1472
+ plugins: { vue: pluginVue },
1473
+ processor: pluginVue.processors[".vue"],
1474
+ rules: {
1475
+ ...pluginVue.configs.base.rules,
1476
+ ...vueRules,
1477
+ "antfu/no-top-level-await": "off",
1478
+ "node/prefer-global/process": "off",
1479
+ "ts/explicit-function-return-type": "off",
1480
+ "vue/block-order": ["error", { order: isVue3 ? [
1481
+ "script",
1482
+ "template",
1483
+ "style"
1484
+ ] : [
1485
+ "template",
1486
+ "script",
1487
+ "style"
1488
+ ] }],
1489
+ "vue/component-name-in-template-casing": ["error", "PascalCase"],
1490
+ "vue/component-options-name-casing": ["error", "PascalCase"],
1491
+ "vue/component-tags-order": "off",
1492
+ "vue/custom-event-name-casing": ["error", "camelCase"],
1493
+ "vue/define-macros-order": ["error", { order: [
1494
+ "defineOptions",
1495
+ "defineProps",
1496
+ "defineEmits",
1497
+ "defineSlots"
1498
+ ] }],
1499
+ "vue/eqeqeq": ["error", "smart"],
1500
+ "vue/html-self-closing": ["error", {
1501
+ html: {
1502
+ component: "always",
1503
+ normal: "always",
1504
+ void: "any"
1505
+ },
1506
+ math: "always",
1507
+ svg: "always"
1508
+ }],
1509
+ "vue/max-attributes-per-line": "off",
1510
+ "vue/multi-word-component-names": "off",
1511
+ "vue/no-constant-condition": "warn",
1512
+ "vue/no-duplicate-attr-inheritance": "warn",
1513
+ "vue/no-empty-pattern": "error",
1514
+ "vue/no-extra-parens": ["error", "functions"],
1515
+ "vue/no-irregular-whitespace": "error",
1516
+ "vue/no-loss-of-precision": "error",
1517
+ "vue/no-required-prop-with-default": "warn",
1518
+ "vue/no-restricted-syntax": [
1519
+ "error",
1520
+ "DebuggerStatement",
1521
+ "LabeledStatement",
1522
+ "WithStatement"
1523
+ ],
1524
+ "vue/no-restricted-v-bind": ["error", "/^v-/"],
1525
+ "vue/no-setup-props-reactivity-loss": "off",
1526
+ "vue/no-sparse-arrays": "error",
1527
+ "vue/no-unsupported-features": "warn",
1528
+ "vue/no-unused-emit-declarations": "warn",
1529
+ "vue/no-unused-refs": "error",
1530
+ "vue/no-use-v-else-with-v-for": "error",
1531
+ "vue/no-useless-mustaches": "warn",
1532
+ "vue/no-useless-v-bind": "error",
1533
+ "vue/no-v-html": "off",
1534
+ "vue/no-v-text": "warn",
1535
+ "vue/object-shorthand": [
1536
+ "error",
1537
+ "always",
1538
+ {
1539
+ avoidQuotes: true,
1540
+ ignoreConstructors: false
1541
+ }
1542
+ ],
1543
+ "vue/padding-line-between-blocks": ["error", "always"],
1544
+ "vue/prefer-define-options": "warn",
1545
+ "vue/prefer-separate-static-class": "error",
1546
+ "vue/prefer-template": "error",
1547
+ "vue/prop-name-casing": ["error", "camelCase"],
1548
+ "vue/require-default-prop": "off",
1549
+ "vue/require-macro-variable-name": ["warn", {
1550
+ defineEmits: "emit",
1551
+ defineProps: "props",
1552
+ defineSlots: "slots",
1553
+ useAttrs: "attrs",
1554
+ useSlots: "slots"
1555
+ }],
1556
+ "vue/require-prop-types": "off",
1557
+ "vue/space-infix-ops": "error",
1558
+ "vue/space-unary-ops": ["error", {
1559
+ nonwords: false,
1560
+ words: true
1561
+ }],
1562
+ "vue/valid-define-options": "warn",
1563
+ ...overrides
1564
+ }
1565
+ }];
1703
1566
  }
1704
1567
 
1705
- // src/configs/yaml.ts
1568
+ //#endregion
1569
+ //#region src/configs/yaml.ts
1706
1570
  async function yaml(options = {}) {
1707
- const { files = [GLOB_YAML], overrides = {} } = options;
1708
- const [pluginYaml, parserYaml] = await Promise.all([
1709
- interopDefault(import("eslint-plugin-yml")),
1710
- interopDefault(import("yaml-eslint-parser"))
1711
- ]);
1712
- return [
1713
- {
1714
- name: "coderwyd/yaml/setup",
1715
- plugins: {
1716
- yaml: pluginYaml
1717
- }
1718
- },
1719
- {
1720
- files,
1721
- languageOptions: {
1722
- parser: parserYaml
1723
- },
1724
- name: "coderwyd/yaml/rules",
1725
- rules: {
1726
- "yaml/block-mapping": "error",
1727
- "yaml/block-sequence": "error",
1728
- "yaml/no-empty-key": "error",
1729
- "yaml/no-empty-sequence-entry": "error",
1730
- "yaml/no-irregular-whitespace": "error",
1731
- "yaml/plain-scalar": "error",
1732
- "yaml/vue-custom-block/no-parsing-error": "error",
1733
- ...overrides
1734
- }
1735
- },
1736
- {
1737
- files: ["pnpm-workspace.yaml"],
1738
- name: "coderwyd/yaml/pnpm-workspace",
1739
- rules: {
1740
- "yaml/sort-keys": [
1741
- "error",
1742
- {
1743
- order: [
1744
- "packages",
1745
- "overrides",
1746
- "patchedDependencies",
1747
- "hoistPattern",
1748
- "catalog",
1749
- "catalogs",
1750
- "allowedDeprecatedVersions",
1751
- "allowNonAppliedPatches",
1752
- "configDependencies",
1753
- "ignoredBuiltDependencies",
1754
- "ignoredOptionalDependencies",
1755
- "neverBuiltDependencies",
1756
- "onlyBuiltDependencies",
1757
- "onlyBuiltDependenciesFile",
1758
- "packageExtensions",
1759
- "peerDependencyRules",
1760
- "supportedArchitectures"
1761
- ],
1762
- pathPattern: "^$"
1763
- },
1764
- {
1765
- order: { type: "asc" },
1766
- pathPattern: ".*"
1767
- }
1768
- ]
1769
- }
1770
- }
1771
- ];
1571
+ const { files = [GLOB_YAML], overrides = {} } = options;
1572
+ const [pluginYaml, parserYaml] = await Promise.all([interopDefault(import("eslint-plugin-yml")), interopDefault(import("yaml-eslint-parser"))]);
1573
+ return [
1574
+ {
1575
+ name: "coderwyd/yaml/setup",
1576
+ plugins: { yaml: pluginYaml }
1577
+ },
1578
+ {
1579
+ files,
1580
+ languageOptions: { parser: parserYaml },
1581
+ name: "coderwyd/yaml/rules",
1582
+ rules: {
1583
+ "yaml/block-mapping": "error",
1584
+ "yaml/block-sequence": "error",
1585
+ "yaml/no-empty-key": "error",
1586
+ "yaml/no-empty-sequence-entry": "error",
1587
+ "yaml/no-irregular-whitespace": "error",
1588
+ "yaml/plain-scalar": "error",
1589
+ "yaml/vue-custom-block/no-parsing-error": "error",
1590
+ ...overrides
1591
+ }
1592
+ },
1593
+ {
1594
+ files: ["pnpm-workspace.yaml"],
1595
+ name: "coderwyd/yaml/pnpm-workspace",
1596
+ rules: { "yaml/sort-keys": [
1597
+ "error",
1598
+ {
1599
+ order: [
1600
+ "packages",
1601
+ "overrides",
1602
+ "patchedDependencies",
1603
+ "hoistPattern",
1604
+ "catalog",
1605
+ "catalogs",
1606
+ "allowedDeprecatedVersions",
1607
+ "allowNonAppliedPatches",
1608
+ "configDependencies",
1609
+ "ignoredBuiltDependencies",
1610
+ "ignoredOptionalDependencies",
1611
+ "neverBuiltDependencies",
1612
+ "onlyBuiltDependencies",
1613
+ "onlyBuiltDependenciesFile",
1614
+ "packageExtensions",
1615
+ "peerDependencyRules",
1616
+ "supportedArchitectures"
1617
+ ],
1618
+ pathPattern: "^$"
1619
+ },
1620
+ {
1621
+ order: { type: "asc" },
1622
+ pathPattern: ".*"
1623
+ }
1624
+ ] }
1625
+ }
1626
+ ];
1772
1627
  }
1773
1628
 
1774
- // src/index.ts
1775
- var flatConfigProps = [
1776
- "name",
1777
- "languageOptions",
1778
- "linterOptions",
1779
- "processor",
1780
- "plugins",
1781
- "rules",
1782
- "settings"
1629
+ //#endregion
1630
+ //#region src/index.ts
1631
+ const flatConfigProps = [
1632
+ "name",
1633
+ "languageOptions",
1634
+ "linterOptions",
1635
+ "processor",
1636
+ "plugins",
1637
+ "rules",
1638
+ "settings"
1783
1639
  ];
1784
- var defaultPluginRenaming = {
1785
- "@eslint-react": "react",
1786
- "@eslint-react/dom": "react-dom",
1787
- "@eslint-react/hooks-extra": "react-hooks-extra",
1788
- "@eslint-react/naming-convention": "react-naming-convention",
1789
- "@typescript-eslint": "ts",
1790
- "import-x": "import",
1791
- n: "node",
1792
- vitest: "test",
1793
- yml: "yaml"
1640
+ const defaultPluginRenaming = {
1641
+ "@eslint-react": "react",
1642
+ "@eslint-react/dom": "react-dom",
1643
+ "@eslint-react/hooks-extra": "react-hooks-extra",
1644
+ "@eslint-react/naming-convention": "react-naming-convention",
1645
+ "@typescript-eslint": "ts",
1646
+ "import-x": "import",
1647
+ n: "node",
1648
+ vitest: "test",
1649
+ yml: "yaml"
1794
1650
  };
1651
+ /**
1652
+ * Construct an array of ESLint flat config items.
1653
+ *
1654
+ * @param {OptionsConfig & TypedFlatConfigItem} options
1655
+ * The options for generating the ESLint configurations.
1656
+ * @param {Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[] | Linter.Config[]>[]} userConfigs
1657
+ * The user configurations to be merged with the generated configurations.
1658
+ * @returns {Promise<TypedFlatConfigItem[]>}
1659
+ * The merged ESLint configurations.
1660
+ */
1795
1661
  async function defineConfig(options = {}, ...userConfigs) {
1796
- const {
1797
- autoRenamePlugins = true,
1798
- componentExts = [],
1799
- gitignore: enableGitignore = true,
1800
- react: enableReact = false,
1801
- regexp: enableRegexp = true,
1802
- svelte: enableSvelte = false,
1803
- tailwindcss: enableTailwindCSS = false,
1804
- typescript: enableTypeScript = isUsingTypeScript,
1805
- unocss: enableUnoCSS = false,
1806
- vue: enableVue = isUsingVue
1807
- } = options;
1808
- let isInEditor2 = options.isInEditor;
1809
- if (isInEditor2 == null) {
1810
- isInEditor2 = isInEditorEnv();
1811
- if (isInEditor2)
1812
- console.log(
1813
- "[@coderwyd/eslint-config] Detected running in editor, some rules are disabled."
1814
- );
1815
- }
1816
- const configs2 = [];
1817
- if (enableGitignore) {
1818
- if (typeof enableGitignore !== "boolean") {
1819
- configs2.push(
1820
- interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1821
- r({
1822
- ...enableGitignore,
1823
- name: "coderwyd/gitignore"
1824
- })
1825
- ])
1826
- );
1827
- } else {
1828
- configs2.push(
1829
- interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1830
- r({ name: "coderwyd/gitignore", strict: false })
1831
- ])
1832
- );
1833
- }
1834
- }
1835
- const typescriptOptions = resolveSubOptions(options, "typescript");
1836
- const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
1837
- configs2.push(
1838
- ignores(options.ignores),
1839
- javascript({
1840
- isInEditor: isInEditor2,
1841
- overrides: getOverrides(options, "javascript")
1842
- }),
1843
- comments(),
1844
- node(),
1845
- jsdoc(),
1846
- imports(),
1847
- unicorn(),
1848
- command(),
1849
- deMorgan(),
1850
- perfectionist()
1851
- // Optional plugins (installed but not enabled by default)
1852
- );
1853
- if (enableVue) componentExts.push("vue");
1854
- if (enableTypeScript) {
1855
- configs2.push(
1856
- typescript({
1857
- ...typescriptOptions,
1858
- componentExts,
1859
- overrides: getOverrides(options, "typescript")
1860
- })
1861
- );
1862
- }
1863
- if (enableRegexp)
1864
- configs2.push(regexp(typeof enableRegexp === "boolean" ? {} : enableRegexp));
1865
- if (options.test ?? true) {
1866
- configs2.push(
1867
- test({
1868
- isInEditor: isInEditor2,
1869
- overrides: getOverrides(options, "test")
1870
- })
1871
- );
1872
- }
1873
- if (enableVue) {
1874
- configs2.push(
1875
- vue({
1876
- ...resolveSubOptions(options, "vue"),
1877
- overrides: getOverrides(options, "typescript"),
1878
- typescript: !!enableTypeScript
1879
- })
1880
- );
1881
- }
1882
- if (enableReact) {
1883
- configs2.push(
1884
- react({
1885
- overrides: getOverrides(options, "react"),
1886
- tsconfigPath
1887
- })
1888
- );
1889
- }
1890
- if (enableSvelte) {
1891
- configs2.push(
1892
- svelte({
1893
- overrides: getOverrides(options, "svelte"),
1894
- typescript: !!enableTypeScript
1895
- })
1896
- );
1897
- }
1898
- if (enableUnoCSS) {
1899
- configs2.push(
1900
- unocss({
1901
- ...resolveSubOptions(options, "unocss"),
1902
- overrides: getOverrides(options, "unocss")
1903
- })
1904
- );
1905
- }
1906
- if (enableTailwindCSS) {
1907
- configs2.push(
1908
- tailwindcss({
1909
- ...resolveSubOptions(options, "tailwindcss"),
1910
- overrides: getOverrides(options, "tailwindcss")
1911
- })
1912
- );
1913
- }
1914
- if (options.jsonc ?? true) {
1915
- configs2.push(
1916
- jsonc({
1917
- overrides: getOverrides(options, "jsonc")
1918
- }),
1919
- sortPackageJson(),
1920
- sortTsconfig()
1921
- );
1922
- }
1923
- if (options.yaml ?? true) {
1924
- configs2.push(
1925
- yaml({
1926
- overrides: getOverrides(options, "yaml")
1927
- })
1928
- );
1929
- }
1930
- configs2.push(specials(), prettier());
1931
- if ("files" in options) {
1932
- throw new Error(
1933
- '[@coderwyd/eslint-config] The first argument should not contain the "files" property as the options are supposed to be global. Place it in the second or later config instead.'
1934
- );
1935
- }
1936
- const fusedConfig = flatConfigProps.reduce((acc, key) => {
1937
- if (key in options) acc[key] = options[key];
1938
- return acc;
1939
- }, {});
1940
- if (Object.keys(fusedConfig).length > 0) configs2.push([fusedConfig]);
1941
- const merged = await combine(...configs2, ...userConfigs);
1942
- if (autoRenamePlugins)
1943
- return renamePluginInConfigs(merged, defaultPluginRenaming);
1944
- return merged;
1662
+ const { autoRenamePlugins = true, componentExts = [], gitignore: enableGitignore = true, react: enableReact = false, regexp: enableRegexp = true, svelte: enableSvelte = false, tailwindcss: enableTailwindCSS = false, typescript: enableTypeScript = isUsingTypeScript, unocss: enableUnoCSS = false, vue: enableVue = isUsingVue } = options;
1663
+ let isInEditor$1 = options.isInEditor;
1664
+ if (isInEditor$1 == null) {
1665
+ isInEditor$1 = isInEditorEnv();
1666
+ if (isInEditor$1) console.log("[@coderwyd/eslint-config] Detected running in editor, some rules are disabled.");
1667
+ }
1668
+ const configs$1 = [];
1669
+ if (enableGitignore) if (typeof enableGitignore !== "boolean") configs$1.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
1670
+ ...enableGitignore,
1671
+ name: "coderwyd/gitignore"
1672
+ })]));
1673
+ else configs$1.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
1674
+ name: "coderwyd/gitignore",
1675
+ strict: false
1676
+ })]));
1677
+ const typescriptOptions = resolveSubOptions(options, "typescript");
1678
+ const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
1679
+ configs$1.push(
1680
+ ignores(options.ignores),
1681
+ javascript({
1682
+ isInEditor: isInEditor$1,
1683
+ overrides: getOverrides(options, "javascript")
1684
+ }),
1685
+ comments(),
1686
+ node(),
1687
+ jsdoc(),
1688
+ imports(),
1689
+ unicorn(),
1690
+ command(),
1691
+ deMorgan(),
1692
+ perfectionist()
1693
+ // Optional plugins (installed but not enabled by default)
1694
+ );
1695
+ if (enableVue) componentExts.push("vue");
1696
+ if (enableTypeScript) configs$1.push(typescript({
1697
+ ...typescriptOptions,
1698
+ componentExts,
1699
+ overrides: getOverrides(options, "typescript")
1700
+ }));
1701
+ if (enableRegexp) configs$1.push(regexp(typeof enableRegexp === "boolean" ? {} : enableRegexp));
1702
+ if (options.test ?? true) configs$1.push(test({
1703
+ isInEditor: isInEditor$1,
1704
+ overrides: getOverrides(options, "test")
1705
+ }));
1706
+ if (enableVue) configs$1.push(vue({
1707
+ ...resolveSubOptions(options, "vue"),
1708
+ overrides: getOverrides(options, "typescript"),
1709
+ typescript: !!enableTypeScript
1710
+ }));
1711
+ if (enableReact) configs$1.push(react({
1712
+ overrides: getOverrides(options, "react"),
1713
+ tsconfigPath
1714
+ }));
1715
+ if (enableSvelte) configs$1.push(svelte({
1716
+ overrides: getOverrides(options, "svelte"),
1717
+ typescript: !!enableTypeScript
1718
+ }));
1719
+ if (enableUnoCSS) configs$1.push(unocss({
1720
+ ...resolveSubOptions(options, "unocss"),
1721
+ overrides: getOverrides(options, "unocss")
1722
+ }));
1723
+ if (enableTailwindCSS) configs$1.push(tailwindcss({
1724
+ ...resolveSubOptions(options, "tailwindcss"),
1725
+ overrides: getOverrides(options, "tailwindcss")
1726
+ }));
1727
+ if (options.jsonc ?? true) configs$1.push(jsonc({ overrides: getOverrides(options, "jsonc") }), sortPackageJson(), sortTsconfig());
1728
+ if (options.yaml ?? true) configs$1.push(yaml({ overrides: getOverrides(options, "yaml") }));
1729
+ configs$1.push(specials(), prettier());
1730
+ if ("files" in options) throw new Error("[@coderwyd/eslint-config] The first argument should not contain the \"files\" property as the options are supposed to be global. Place it in the second or later config instead.");
1731
+ const fusedConfig = flatConfigProps.reduce((acc, key) => {
1732
+ if (key in options) acc[key] = options[key];
1733
+ return acc;
1734
+ }, {});
1735
+ if (Object.keys(fusedConfig).length > 0) configs$1.push([fusedConfig]);
1736
+ const merged = await combine(...configs$1, ...userConfigs);
1737
+ if (autoRenamePlugins) return renamePluginInConfigs(merged, defaultPluginRenaming);
1738
+ return merged;
1945
1739
  }
1946
- export {
1947
- combine,
1948
- defaultPluginRenaming,
1949
- defineConfig,
1950
- ensurePackages,
1951
- getOverrides,
1952
- getVueVersion,
1953
- interopDefault,
1954
- isInEditorEnv,
1955
- isInGitHooksOrLintStaged,
1956
- isPackageInScope,
1957
- renamePluginInConfigs,
1958
- renameRules,
1959
- resolveSubOptions,
1960
- toArray
1961
- };
1740
+
1741
+ //#endregion
1742
+ export { combine, defaultPluginRenaming, defineConfig, ensurePackages, getOverrides, getVueVersion, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, renamePluginInConfigs, renameRules, resolveSubOptions, toArray };