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