@coderwyd/eslint-config 3.6.0 → 4.0.0

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