@coderwyd/eslint-config 3.5.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,1917 +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 NextJsPackages = ["next"];
711
- var ReactRefreshAllowConstantExportPackages = ["vite"];
712
- var isUsingRemix = hasPackages(RemixPackages);
713
- var isUsingNext = hasPackages(NextJsPackages);
714
- var isAllowConstantExport = hasPackages(
715
- ReactRefreshAllowConstantExportPackages
716
- );
717
- function hasPackages(packages) {
718
- return packages.some((name) => (0, import_local_pkg2.isPackageExists)(name));
719
- }
720
-
721
- // src/configs/react.ts
722
- async function react(options = {}) {
723
- const {
724
- files = [GLOB_SRC],
725
- filesTypeAware = [GLOB_TS, GLOB_TSX],
726
- ignoresTypeAware = [`${GLOB_MARKDOWN}/**`, GLOB_ASTRO_TS],
727
- overrides = {},
728
- tsconfigPath
729
- } = options;
730
- await ensurePackages([
731
- "@eslint-react/eslint-plugin",
732
- "eslint-plugin-react-hooks",
733
- "eslint-plugin-react-refresh"
734
- ]);
735
- const isTypeAware = !!tsconfigPath;
736
- const typeAwareRules = {
737
- "react/no-leaked-conditional-rendering": "warn"
738
- };
739
- const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all(
740
- [
741
- interopDefault(import("@eslint-react/eslint-plugin")),
742
- interopDefault(import("eslint-plugin-react-hooks")),
743
- interopDefault(import("eslint-plugin-react-refresh"))
744
- ]
745
- );
746
- const plugins = pluginReact.configs.all.plugins;
747
- return [
748
- {
749
- name: "coderwyd/react/setup",
750
- plugins: {
751
- react: plugins["@eslint-react"],
752
- "react-dom": plugins["@eslint-react/dom"],
753
- "react-hooks": pluginReactHooks,
754
- "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
755
- "react-naming-convention": plugins["@eslint-react/naming-convention"],
756
- "react-refresh": pluginReactRefresh
757
- }
758
- },
759
- {
760
- files,
761
- languageOptions: {
762
- parserOptions: {
763
- ecmaFeatures: {
764
- jsx: true
765
- }
766
- },
767
- sourceType: "module"
768
- },
769
- name: "coderwyd/react/rules",
770
- rules: {
771
- // recommended rules from @eslint-react/dom
772
- "react-dom/no-children-in-void-dom-elements": "warn",
773
- "react-dom/no-dangerously-set-innerhtml": "warn",
774
- "react-dom/no-dangerously-set-innerhtml-with-children": "error",
775
- "react-dom/no-find-dom-node": "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-return-value": "error",
780
- "react-dom/no-script-url": "warn",
781
- "react-dom/no-unsafe-iframe-sandbox": "warn",
782
- "react-dom/no-unsafe-target-blank": "warn",
783
- // recommended rules react-hooks
784
- "react-hooks/exhaustive-deps": "warn",
785
- "react-hooks/rules-of-hooks": "error",
786
- // react refresh
787
- "react-refresh/only-export-components": [
788
- "warn",
789
- {
790
- allowConstantExport: isAllowConstantExport,
791
- allowExportNames: [
792
- ...isUsingNext ? [
793
- "dynamic",
794
- "dynamicParams",
795
- "revalidate",
796
- "fetchCache",
797
- "runtime",
798
- "preferredRegion",
799
- "maxDuration",
800
- "config",
801
- "generateStaticParams",
802
- "metadata",
803
- "generateMetadata",
804
- "viewport",
805
- "generateViewport"
806
- ] : [],
807
- ...isUsingRemix ? ["meta", "links", "headers", "loader", "action"] : []
808
- ]
809
- }
810
- ],
811
- // recommended rules from @eslint-react
812
- "react/ensure-forward-ref-using-ref": "warn",
813
- "react/jsx-no-duplicate-props": "warn",
814
- "react/jsx-uses-vars": "warn",
815
- "react/no-access-state-in-setstate": "error",
816
- "react/no-array-index-key": "warn",
817
- "react/no-children-count": "warn",
818
- "react/no-children-for-each": "warn",
819
- "react/no-children-map": "warn",
820
- "react/no-children-only": "warn",
821
- "react/no-children-to-array": "warn",
822
- "react/no-clone-element": "warn",
823
- "react/no-comment-textnodes": "warn",
824
- "react/no-component-will-mount": "error",
825
- "react/no-component-will-receive-props": "error",
826
- "react/no-component-will-update": "error",
827
- "react/no-context-provider": "warn",
828
- "react/no-create-ref": "error",
829
- "react/no-default-props": "error",
830
- "react/no-direct-mutation-state": "error",
831
- "react/no-duplicate-key": "error",
832
- "react/no-forward-ref": "warn",
833
- "react/no-implicit-key": "warn",
834
- "react/no-missing-key": "error",
835
- "react/no-nested-components": "error",
836
- "react/no-prop-types": "error",
837
- "react/no-redundant-should-component-update": "error",
838
- "react/no-set-state-in-component-did-mount": "warn",
839
- "react/no-set-state-in-component-did-update": "warn",
840
- "react/no-set-state-in-component-will-update": "warn",
841
- "react/no-string-refs": "error",
842
- "react/no-unsafe-component-will-mount": "warn",
843
- "react/no-unsafe-component-will-receive-props": "warn",
844
- "react/no-unsafe-component-will-update": "warn",
845
- "react/no-unstable-context-value": "warn",
846
- "react/no-unstable-default-props": "warn",
847
- "react/no-unused-class-component-members": "warn",
848
- "react/no-unused-state": "warn",
849
- "react/prefer-destructuring-assignment": "warn",
850
- "react/prefer-shorthand-boolean": "warn",
851
- "react/prefer-shorthand-fragment": "warn",
852
- // overrides
853
- ...overrides
854
- }
855
- },
856
- ...isTypeAware ? [
857
- {
858
- files: filesTypeAware,
859
- ignores: ignoresTypeAware,
860
- name: "coderwyd/react/type-aware-rules",
861
- rules: {
862
- ...typeAwareRules
863
- }
864
- }
865
- ] : []
866
- ];
867
- }
868
-
869
- // src/configs/regexp.ts
870
- var import_eslint_plugin_regexp = require("eslint-plugin-regexp");
871
- function regexp(options = {}) {
872
- const config = import_eslint_plugin_regexp.configs["flat/recommended"];
873
- const rules = {
874
- ...config.rules
875
- };
876
- if (options.level === "warn") {
877
- Object.keys(rules).forEach((key) => {
878
- if (rules[key] === "error") rules[key] = "warn";
879
- });
880
- }
881
- return [
882
- {
883
- ...config,
884
- name: "coderwyd/regexp/rules",
885
- rules: {
886
- ...rules,
887
- ...options.overrides
888
- }
889
- }
890
- ];
891
- }
892
-
893
- // src/configs/sort.ts
894
- function sortPackageJson() {
895
- return [
896
- {
897
- files: ["**/package.json"],
898
- name: "coderwyd/sort/package-json",
899
- rules: {
900
- "jsonc/sort-array-values": [
901
- "error",
902
- {
903
- order: { type: "asc" },
904
- pathPattern: "^files$"
905
- }
906
- ],
907
- "jsonc/sort-keys": [
908
- "error",
909
- {
910
- order: [
911
- "publisher",
912
- "name",
913
- "displayName",
914
- "type",
915
- "version",
916
- "private",
917
- "packageManager",
918
- "description",
919
- "author",
920
- "license",
921
- "funding",
922
- "homepage",
923
- "repository",
924
- "bugs",
925
- "keywords",
926
- "categories",
927
- "sideEffects",
928
- "exports",
929
- "main",
930
- "module",
931
- "unpkg",
932
- "jsdelivr",
933
- "types",
934
- "typesVersions",
935
- "bin",
936
- "icon",
937
- "files",
938
- "engines",
939
- "activationEvents",
940
- "contributes",
941
- "scripts",
942
- "peerDependencies",
943
- "peerDependenciesMeta",
944
- "dependencies",
945
- "optionalDependencies",
946
- "devDependencies",
947
- "pnpm",
948
- "overrides",
949
- "resolutions",
950
- "husky",
951
- "simple-git-hooks",
952
- "lint-staged",
953
- "eslintConfig"
954
- ],
955
- pathPattern: "^$"
956
- },
957
- {
958
- order: { type: "asc" },
959
- pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
960
- },
961
- {
962
- order: { type: "asc" },
963
- pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
964
- },
965
- {
966
- order: ["types", "import", "require", "default"],
967
- pathPattern: "^exports.*$"
968
- },
969
- {
970
- order: [
971
- // client hooks only
972
- "pre-commit",
973
- "prepare-commit-msg",
974
- "commit-msg",
975
- "post-commit",
976
- "pre-rebase",
977
- "post-rewrite",
978
- "post-checkout",
979
- "post-merge",
980
- "pre-push",
981
- "pre-auto-gc"
982
- ],
983
- pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
984
- }
985
- ]
986
- }
987
- }
988
- ];
989
- }
990
- function sortTsconfig() {
991
- return [
992
- {
993
- files: ["**/tsconfig.json", "**/tsconfig.*.json"],
994
- name: "coderwyd/sort/tsconfig-json",
995
- rules: {
996
- "jsonc/sort-keys": [
997
- "error",
998
- {
999
- order: [
1000
- "extends",
1001
- "compilerOptions",
1002
- "references",
1003
- "files",
1004
- "include",
1005
- "exclude"
1006
- ],
1007
- pathPattern: "^$"
1008
- },
1009
- {
1010
- order: [
1011
- /* Projects */
1012
- "incremental",
1013
- "composite",
1014
- "tsBuildInfoFile",
1015
- "disableSourceOfProjectReferenceRedirect",
1016
- "disableSolutionSearching",
1017
- "disableReferencedProjectLoad",
1018
- /* Language and Environment */
1019
- "target",
1020
- "jsx",
1021
- "jsxFactory",
1022
- "jsxFragmentFactory",
1023
- "jsxImportSource",
1024
- "lib",
1025
- "moduleDetection",
1026
- "noLib",
1027
- "reactNamespace",
1028
- "useDefineForClassFields",
1029
- "emitDecoratorMetadata",
1030
- "experimentalDecorators",
1031
- /* Modules */
1032
- "baseUrl",
1033
- "rootDir",
1034
- "rootDirs",
1035
- "customConditions",
1036
- "module",
1037
- "moduleResolution",
1038
- "moduleSuffixes",
1039
- "noResolve",
1040
- "paths",
1041
- "resolveJsonModule",
1042
- "resolvePackageJsonExports",
1043
- "resolvePackageJsonImports",
1044
- "typeRoots",
1045
- "types",
1046
- "allowArbitraryExtensions",
1047
- "allowImportingTsExtensions",
1048
- "allowUmdGlobalAccess",
1049
- /* JavaScript Support */
1050
- "allowJs",
1051
- "checkJs",
1052
- "maxNodeModuleJsDepth",
1053
- /* Type Checking */
1054
- "strict",
1055
- "strictBindCallApply",
1056
- "strictFunctionTypes",
1057
- "strictNullChecks",
1058
- "strictPropertyInitialization",
1059
- "allowUnreachableCode",
1060
- "allowUnusedLabels",
1061
- "alwaysStrict",
1062
- "exactOptionalPropertyTypes",
1063
- "noFallthroughCasesInSwitch",
1064
- "noImplicitAny",
1065
- "noImplicitOverride",
1066
- "noImplicitReturns",
1067
- "noImplicitThis",
1068
- "noPropertyAccessFromIndexSignature",
1069
- "noUncheckedIndexedAccess",
1070
- "noUnusedLocals",
1071
- "noUnusedParameters",
1072
- "useUnknownInCatchVariables",
1073
- /* Emit */
1074
- "declaration",
1075
- "declarationDir",
1076
- "declarationMap",
1077
- "downlevelIteration",
1078
- "emitBOM",
1079
- "emitDeclarationOnly",
1080
- "importHelpers",
1081
- "importsNotUsedAsValues",
1082
- "inlineSourceMap",
1083
- "inlineSources",
1084
- "mapRoot",
1085
- "newLine",
1086
- "noEmit",
1087
- "noEmitHelpers",
1088
- "noEmitOnError",
1089
- "outDir",
1090
- "outFile",
1091
- "preserveConstEnums",
1092
- "preserveValueImports",
1093
- "removeComments",
1094
- "sourceMap",
1095
- "sourceRoot",
1096
- "stripInternal",
1097
- /* Interop Constraints */
1098
- "allowSyntheticDefaultImports",
1099
- "esModuleInterop",
1100
- "forceConsistentCasingInFileNames",
1101
- "isolatedDeclarations",
1102
- "isolatedModules",
1103
- "preserveSymlinks",
1104
- "verbatimModuleSyntax",
1105
- /* Completeness */
1106
- "skipDefaultLibCheck",
1107
- "skipLibCheck"
1108
- ],
1109
- pathPattern: "^compilerOptions$"
1110
- }
1111
- ]
1112
- }
1113
- }
1114
- ];
1115
- }
1116
-
1117
- // src/configs/specials.ts
1118
- function specials() {
1119
- return [
1120
- {
1121
- files: [`**/scripts/${GLOB_SRC}`],
1122
- name: "coderwyd/specials/scripts",
1123
- rules: {
1124
- "antfu/no-top-level-await": "off",
1125
- "no-console": "off",
1126
- "ts/explicit-function-return-type": "off"
1127
- }
1128
- },
1129
- {
1130
- files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`],
1131
- name: "coderwyd/specials/cli",
1132
- rules: {
1133
- "antfu/no-top-level-await": "off",
1134
- "no-console": "off"
1135
- }
1136
- },
1137
- {
1138
- files: ["**/bin/**/*", `**/bin.${GLOB_SRC_EXT}`],
1139
- name: "coderwyd/specials/bin",
1140
- rules: {
1141
- "antfu/no-import-dist": "off",
1142
- "antfu/no-import-node-modules-by-path": "off"
1143
- }
1144
- },
1145
- {
1146
- files: [GLOB_DTS],
1147
- name: "coderwyd/specials/dts",
1148
- rules: {
1149
- "eslint-comments/no-unlimited-disable": "off",
1150
- "import/no-duplicates": "off",
1151
- "no-restricted-syntax": "off",
1152
- "unused-imports/no-unused-vars": "off"
1153
- }
1154
- },
1155
- {
1156
- files: ["**/*.{test,spec}.([tj])s?(x)"],
1157
- name: "coderwyd/specials/test",
1158
- rules: {
1159
- "antfu/no-top-level-await": "off",
1160
- "no-unused-expressions": "off"
1161
- }
1162
- },
1163
- {
1164
- files: ["**/*.js", "**/*.cjs"],
1165
- name: "coderwyd/specials/cjs",
1166
- rules: {
1167
- "ts/no-require-imports": "off"
1168
- }
1169
- }
1170
- ];
1171
- }
1172
-
1173
- // src/configs/svelte.ts
1174
- async function svelte(options = {}) {
1175
- const { files = [GLOB_SVELTE], overrides = {} } = options;
1176
- await ensurePackages(["eslint-plugin-svelte"]);
1177
- const [pluginSvelte, parserSvelte] = await Promise.all([
1178
- interopDefault(import("eslint-plugin-svelte")),
1179
- interopDefault(import("svelte-eslint-parser"))
1180
- ]);
1181
- return [
1182
- {
1183
- name: "coderwyd/svelte/setup",
1184
- plugins: {
1185
- svelte: pluginSvelte
1186
- }
1187
- },
1188
- {
1189
- files,
1190
- languageOptions: {
1191
- parser: parserSvelte,
1192
- parserOptions: {
1193
- extraFileExtensions: [".svelte"],
1194
- parser: options.typescript ? await interopDefault(
1195
- import("@typescript-eslint/parser")
1196
- ) : null
1197
- }
1198
- },
1199
- name: "coderwyd/svelte/rules",
1200
- processor: pluginSvelte.processors[".svelte"],
1201
- rules: {
1202
- "import/no-mutable-exports": "off",
1203
- "no-undef": "off",
1204
- // incompatible with most recent (attribute-form) generic types RFC
1205
- "no-unused-vars": [
1206
- "error",
1207
- {
1208
- args: "none",
1209
- caughtErrors: "none",
1210
- ignoreRestSiblings: true,
1211
- vars: "all",
1212
- varsIgnorePattern: "^(\\$\\$Props$|\\$\\$Events$|\\$\\$Slots$)"
1213
- }
1214
- ],
1215
- "svelte/comment-directive": "error",
1216
- "svelte/no-at-debug-tags": "warn",
1217
- "svelte/no-at-html-tags": "error",
1218
- "svelte/no-dupe-else-if-blocks": "error",
1219
- "svelte/no-dupe-style-properties": "error",
1220
- "svelte/no-dupe-use-directives": "error",
1221
- "svelte/no-dynamic-slot-name": "error",
1222
- "svelte/no-export-load-in-svelte-module-in-kit-pages": "error",
1223
- "svelte/no-inner-declarations": "error",
1224
- "svelte/no-not-function-handler": "error",
1225
- "svelte/no-object-in-text-mustaches": "error",
1226
- "svelte/no-reactive-functions": "error",
1227
- "svelte/no-reactive-literals": "error",
1228
- "svelte/no-shorthand-style-property-overrides": "error",
1229
- "svelte/no-unknown-style-directive-property": "error",
1230
- "svelte/no-unused-svelte-ignore": "error",
1231
- "svelte/no-useless-mustaches": "error",
1232
- "svelte/require-store-callbacks-use-set-param": "error",
1233
- "svelte/system": "error",
1234
- "svelte/valid-each-key": "error",
1235
- "unused-imports/no-unused-vars": [
1236
- "error",
1237
- {
1238
- args: "after-used",
1239
- argsIgnorePattern: "^_",
1240
- vars: "all",
1241
- varsIgnorePattern: "^(_|\\$\\$Props$|\\$\\$Events$|\\$\\$Slots$)"
1242
- }
1243
- ],
1244
- ...overrides
1245
- }
1246
- }
1247
- ];
1248
- }
1249
-
1250
- // src/configs/tailwindcss.ts
1251
- async function tailwindcss(options = {}) {
1252
- const { overrides } = options;
1253
- await ensurePackages(["eslint-plugin-tailwindcss"]);
1254
- const pluginTailwindcss = await interopDefault(
1255
- import("eslint-plugin-tailwindcss")
1256
- );
1257
- return [
1258
- {
1259
- name: "coderwyd/tailwindcss/rules",
1260
- plugins: {
1261
- tailwindcss: pluginTailwindcss
1262
- },
1263
- rules: {
1264
- "tailwindcss/classnames-order": "warn",
1265
- "tailwindcss/enforces-negative-arbitrary-values": "warn",
1266
- "tailwindcss/enforces-shorthand": "warn",
1267
- "tailwindcss/migration-from-tailwind-2": "warn",
1268
- "tailwindcss/no-arbitrary-value": "off",
1269
- "tailwindcss/no-contradicting-classname": "warn",
1270
- "tailwindcss/no-custom-classname": "off",
1271
- "tailwindcss/no-unnecessary-arbitrary-value": "warn",
1272
- ...overrides
1273
- }
1274
- }
1275
- ];
1276
- }
1277
-
1278
- // src/configs/test.ts
1279
- var _pluginTest;
1280
- async function test(options = {}) {
1281
- const { files = GLOB_TESTS, isInEditor: isInEditor2 = false, overrides = {} } = options;
1282
- const [pluginVitest, pluginNoOnlyTests] = await Promise.all([
1283
- interopDefault(import("@vitest/eslint-plugin")),
1284
- // @ts-expect-error missing types
1285
- interopDefault(import("eslint-plugin-no-only-tests"))
1286
- ]);
1287
- _pluginTest = _pluginTest || {
1288
- ...pluginVitest,
1289
- rules: {
1290
- ...pluginVitest.rules,
1291
- // extend `test/no-only-tests` rule
1292
- ...pluginNoOnlyTests.rules
1293
- }
1294
- };
1295
- return [
1296
- {
1297
- name: "coderwyd/test/setup",
1298
- plugins: {
1299
- test: _pluginTest
1300
- }
1301
- },
1302
- {
1303
- files,
1304
- name: "coderwyd/test/rules",
1305
- rules: {
1306
- "node/prefer-global/process": "off",
1307
- "test/consistent-test-it": [
1308
- "error",
1309
- { fn: "it", withinDescribe: "it" }
1310
- ],
1311
- "test/no-identical-title": "error",
1312
- "test/no-import-node-test": "error",
1313
- "test/no-only-tests": isInEditor2 ? "off" : "error",
1314
- "test/prefer-hooks-in-order": "error",
1315
- "test/prefer-lowercase-title": "error",
1316
- "ts/explicit-function-return-type": "off",
1317
- ...overrides
1318
- }
1319
- }
1320
- ];
1321
- }
1322
-
1323
- // src/configs/typescript.ts
1324
- var import_node_process3 = __toESM(require("process"), 1);
1325
- async function typescript(options = {}) {
1326
- const {
1327
- componentExts = [],
1328
- overrides = {},
1329
- overridesTypeAware = {},
1330
- parserOptions = {}
1331
- } = options;
1332
- const files = options.files ?? [
1333
- GLOB_TS,
1334
- GLOB_TSX,
1335
- ...componentExts.map((ext) => `**/*.${ext}`)
1336
- ];
1337
- const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
1338
- const ignoresTypeAware = options.ignoresTypeAware ?? [
1339
- `${GLOB_MARKDOWN}/**`,
1340
- GLOB_ASTRO_TS
1341
- ];
1342
- const tsconfigPath = options.tsconfigPath;
1343
- const isTypeAware = !!tsconfigPath;
1344
- const typeAwareRules = {
1345
- "dot-notation": "off",
1346
- "no-implied-eval": "off",
1347
- "ts/await-thenable": "error",
1348
- "ts/dot-notation": ["error", { allowKeywords: true }],
1349
- "ts/no-floating-promises": "error",
1350
- "ts/no-for-in-array": "error",
1351
- "ts/no-implied-eval": "error",
1352
- "ts/no-misused-promises": "error",
1353
- "ts/no-unnecessary-type-assertion": "error",
1354
- "ts/no-unsafe-argument": "error",
1355
- "ts/no-unsafe-assignment": "error",
1356
- "ts/no-unsafe-call": "error",
1357
- "ts/no-unsafe-member-access": "error",
1358
- "ts/no-unsafe-return": "error",
1359
- "ts/promise-function-async": "error",
1360
- "ts/restrict-plus-operands": "error",
1361
- "ts/restrict-template-expressions": "error",
1362
- "ts/return-await": "error",
1363
- "ts/strict-boolean-expressions": "error",
1364
- "ts/switch-exhaustiveness-check": "error",
1365
- "ts/unbound-method": "error"
1366
- };
1367
- const [pluginTs, parserTs] = await Promise.all([
1368
- interopDefault(import("@typescript-eslint/eslint-plugin")),
1369
- interopDefault(import("@typescript-eslint/parser"))
1370
- ]);
1371
- function makeParser(typeAware, files2, ignores2) {
1372
- return {
1373
- files: files2,
1374
- ...ignores2 ? { ignores: ignores2 } : {},
1375
- languageOptions: {
1376
- parser: parserTs,
1377
- parserOptions: {
1378
- extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1379
- sourceType: "module",
1380
- ...typeAware ? {
1381
- projectService: {
1382
- allowDefaultProject: ["./*.js"],
1383
- defaultProject: tsconfigPath
1384
- },
1385
- tsconfigRootDir: import_node_process3.default.cwd()
1386
- } : {},
1387
- ...parserOptions
1388
- }
1389
- },
1390
- name: `coderwyd/typescript/${typeAware ? "type-aware-parser" : "parser"}`
1391
- };
1392
- }
1393
- return [
1394
- {
1395
- // Install the plugins without globs, so they can be configured separately.
1396
- name: "coderwyd/typescript/setup",
1397
- plugins: {
1398
- antfu: import_eslint_plugin_antfu.default,
1399
- ts: pluginTs
1400
- }
1401
- },
1402
- // assign type-aware parser for type-aware files and type-unaware parser for the rest
1403
- ...isTypeAware ? [
1404
- makeParser(false, files),
1405
- makeParser(true, filesTypeAware, ignoresTypeAware)
1406
- ] : [makeParser(false, files)],
1407
- {
1408
- files,
1409
- name: "coderwyd/typescript/rules",
1410
- rules: {
1411
- ...renameRules(
1412
- pluginTs.configs["eslint-recommended"].overrides[0].rules,
1413
- { "@typescript-eslint": "ts" }
1414
- ),
1415
- ...renameRules(pluginTs.configs.strict.rules, {
1416
- "@typescript-eslint": "ts"
1417
- }),
1418
- "no-dupe-class-members": "off",
1419
- "no-redeclare": "off",
1420
- "no-use-before-define": "off",
1421
- "no-useless-constructor": "off",
1422
- "ts/ban-ts-comment": [
1423
- "error",
1424
- { "ts-expect-error": "allow-with-description" }
1425
- ],
1426
- "ts/consistent-type-definitions": ["error", "interface"],
1427
- "ts/consistent-type-imports": [
1428
- "error",
1429
- { disallowTypeAnnotations: false, prefer: "type-imports" }
1430
- ],
1431
- "ts/method-signature-style": ["error", "property"],
1432
- // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
1433
- "ts/no-dupe-class-members": "error",
1434
- "ts/no-dynamic-delete": "off",
1435
- "ts/no-empty-object-type": [
1436
- "error",
1437
- {
1438
- allowInterfaces: "with-single-extends",
1439
- // interface Derived extends Base {}
1440
- allowObjectTypes: "never",
1441
- allowWithName: "Props$"
1442
- }
1443
- ],
1444
- "ts/no-explicit-any": "off",
1445
- "ts/no-extraneous-class": "off",
1446
- "ts/no-import-type-side-effects": "error",
1447
- "ts/no-invalid-void-type": "off",
1448
- "ts/no-non-null-assertion": "off",
1449
- "ts/no-redeclare": ["error", { builtinGlobals: false }],
1450
- "ts/no-require-imports": "error",
1451
- "ts/no-unused-expressions": [
1452
- "error",
1453
- {
1454
- allowShortCircuit: true,
1455
- allowTaggedTemplates: true,
1456
- allowTernary: true
1457
- }
1458
- ],
1459
- "ts/no-unused-vars": "off",
1460
- "ts/no-use-before-define": [
1461
- "error",
1462
- { classes: false, functions: false, variables: true }
1463
- ],
1464
- "ts/no-useless-constructor": "off",
1465
- "ts/no-wrapper-object-types": "error",
1466
- "ts/triple-slash-reference": "off",
1467
- "ts/unified-signatures": "off",
1468
- ...overrides
1469
- }
1470
- },
1471
- ...isTypeAware ? [
1472
- {
1473
- files: filesTypeAware,
1474
- ignores: ignoresTypeAware,
1475
- name: "coderwyd/typescript/rules-type-aware",
1476
- rules: {
1477
- ...typeAwareRules,
1478
- ...overridesTypeAware
1479
- }
1480
- }
1481
- ] : []
1482
- ];
1483
- }
1484
-
1485
- // src/configs/unicorn.ts
1486
- function unicorn() {
1487
- return [
1488
- {
1489
- name: "coderwyd/unicorn/rules",
1490
- plugins: {
1491
- unicorn: import_eslint_plugin_unicorn.default
1492
- },
1493
- rules: {
1494
- // 'unicorn/better-regex': 'error',
1495
- "unicorn/catch-error-name": "error",
1496
- "unicorn/consistent-empty-array-spread": "error",
1497
- "unicorn/consistent-existence-index-check": "error",
1498
- "unicorn/custom-error-definition": "error",
1499
- "unicorn/error-message": "error",
1500
- // 'unicorn/explicit-length-check': 'error',
1501
- // 'unicorn/filename-case': [
1502
- // 'error',
1503
- // {
1504
- // cases: { kebabCase: true, pascalCase: true },
1505
- // ignore: [/^[A-Z]+\..*$/],
1506
- // },
1507
- "unicorn/escape-case": "error",
1508
- // ],
1509
- "unicorn/new-for-builtins": "error",
1510
- // 'unicorn/no-array-callback-reference': 'error',
1511
- "unicorn/no-array-method-this-argument": "error",
1512
- "unicorn/no-array-push-push": "error",
1513
- "unicorn/no-await-in-promise-methods": "error",
1514
- "unicorn/no-console-spaces": "error",
1515
- "unicorn/no-for-loop": "error",
1516
- "unicorn/no-hex-escape": "error",
1517
- "unicorn/no-instanceof-array": "error",
1518
- "unicorn/no-invalid-remove-event-listener": "error",
1519
- "unicorn/no-length-as-slice-end": "error",
1520
- "unicorn/no-lonely-if": "error",
1521
- "unicorn/no-negation-in-equality-check": "error",
1522
- "unicorn/no-new-array": "error",
1523
- "unicorn/no-new-buffer": "error",
1524
- "unicorn/no-single-promise-in-promise-methods": "error",
1525
- "unicorn/no-static-only-class": "error",
1526
- "unicorn/no-unnecessary-await": "error",
1527
- "unicorn/no-zero-fractions": "error",
1528
- "unicorn/prefer-add-event-listener": "error",
1529
- "unicorn/prefer-array-find": "error",
1530
- "unicorn/prefer-array-flat-map": "error",
1531
- "unicorn/prefer-array-index-of": "error",
1532
- "unicorn/prefer-array-some": "error",
1533
- "unicorn/prefer-at": "error",
1534
- "unicorn/prefer-blob-reading-methods": "error",
1535
- "unicorn/prefer-date-now": "error",
1536
- "unicorn/prefer-dom-node-append": "error",
1537
- "unicorn/prefer-dom-node-dataset": "error",
1538
- "unicorn/prefer-dom-node-remove": "error",
1539
- "unicorn/prefer-dom-node-text-content": "error",
1540
- "unicorn/prefer-includes": "error",
1541
- "unicorn/prefer-keyboard-event-key": "error",
1542
- "unicorn/prefer-math-min-max": "error",
1543
- "unicorn/prefer-math-trunc": "error",
1544
- "unicorn/prefer-modern-dom-apis": "error",
1545
- "unicorn/prefer-modern-math-apis": "error",
1546
- "unicorn/prefer-negative-index": "error",
1547
- "unicorn/prefer-node-protocol": "error",
1548
- "unicorn/prefer-number-properties": "error",
1549
- "unicorn/prefer-optional-catch-binding": "error",
1550
- "unicorn/prefer-prototype-methods": "error",
1551
- "unicorn/prefer-query-selector": "error",
1552
- "unicorn/prefer-reflect-apply": "error",
1553
- // 'unicorn/prefer-regexp-test': 'error',
1554
- "unicorn/prefer-string-replace-all": "error",
1555
- "unicorn/prefer-string-slice": "error",
1556
- "unicorn/prefer-string-starts-ends-with": "error",
1557
- "unicorn/prefer-string-trim-start-end": "error",
1558
- // top level await is not supported in all environments
1559
- // 'unicorn/prefer-top-level-await': 'error',
1560
- "unicorn/prefer-type-error": "error",
1561
- "unicorn/throw-new-error": "error"
1562
- }
1563
- }
1564
- ];
1565
- }
1566
-
1567
- // src/configs/unocss.ts
1568
- async function unocss(options = {}) {
1569
- const { attributify = true, strict = false } = options;
1570
- await ensurePackages(["@unocss/eslint-plugin"]);
1571
- const [pluginUnoCSS] = await Promise.all([
1572
- interopDefault(import("@unocss/eslint-plugin"))
1573
- ]);
1574
- return [
1575
- {
1576
- name: "coderwyd/unocss/rules",
1577
- plugins: {
1578
- unocss: pluginUnoCSS
1579
- },
1580
- rules: {
1581
- "unocss/order": "warn",
1582
- ...attributify ? {
1583
- "unocss/order-attributify": "warn"
1584
- } : {},
1585
- ...strict ? {
1586
- "unocss/blocklist": "error"
1587
- } : {}
1588
- }
1589
- }
1590
- ];
1591
- }
1592
-
1593
- // src/configs/vue.ts
1594
- async function vue(options = {}) {
1595
- const { files = [GLOB_VUE], overrides = {} } = options;
1596
- const [pluginVue, parserVue] = await Promise.all([
1597
- interopDefault(import("eslint-plugin-vue")),
1598
- interopDefault(import("vue-eslint-parser"))
1599
- ]);
1600
- const isVue3 = getVueVersion() === 3;
1601
- const configKeys = isVue3 ? ["vue3-essential", "vue3-strongly-recommended", "vue3-recommended"] : ["essential", "strongly-recommended", "recommended"];
1602
- const vueRules = configKeys.reduce((preRules, key) => {
1603
- const config = pluginVue.configs[key];
1604
- return {
1605
- ...preRules,
1606
- ...config.rules
1607
- };
1608
- }, {});
1609
- return [
1610
- {
1611
- files,
1612
- languageOptions: {
1613
- parser: parserVue,
1614
- parserOptions: {
1615
- ecmaFeatures: {
1616
- jsx: true
1617
- },
1618
- extraFileExtensions: [".vue"],
1619
- parser: options.typescript ? await interopDefault(
1620
- import("@typescript-eslint/parser")
1621
- ) : null,
1622
- sourceType: "module"
1623
- }
1624
- },
1625
- name: "coderwyd/vue/rules",
1626
- plugins: {
1627
- vue: pluginVue
1628
- },
1629
- processor: pluginVue.processors[".vue"],
1630
- rules: {
1631
- ...pluginVue.configs.base.rules,
1632
- ...vueRules,
1633
- "antfu/no-top-level-await": "off",
1634
- "node/prefer-global/process": "off",
1635
- "ts/explicit-function-return-type": "off",
1636
- "vue/block-order": [
1637
- "error",
1638
- {
1639
- order: isVue3 ? ["script", "template", "style"] : ["template", "script", "style"]
1640
- }
1641
- ],
1642
- // 'vue/component-api-style': ['warn', ['script-setup', 'composition']],
1643
- "vue/component-name-in-template-casing": ["error", "PascalCase"],
1644
- "vue/component-options-name-casing": ["error", "PascalCase"],
1645
- // this is deprecated
1646
- "vue/component-tags-order": "off",
1647
- "vue/custom-event-name-casing": ["error", "camelCase"],
1648
- // 'vue/define-emits-declaration': ['warn', 'type-based'],
1649
- "vue/define-macros-order": [
1650
- "error",
1651
- {
1652
- order: [
1653
- "defineOptions",
1654
- "defineProps",
1655
- "defineEmits",
1656
- "defineSlots"
1657
- ]
1658
- }
1659
- ],
1660
- // 'vue/define-props-declaration': ['warn', 'type-based'],
1661
- "vue/eqeqeq": ["error", "smart"],
1662
- "vue/html-self-closing": [
1663
- "error",
1664
- {
1665
- html: {
1666
- component: "always",
1667
- normal: "always",
1668
- void: "any"
1669
- },
1670
- math: "always",
1671
- svg: "always"
1672
- }
1673
- ],
1674
- "vue/max-attributes-per-line": "off",
1675
- "vue/multi-word-component-names": "off",
1676
- // 'vue/next-tick-style': ['warn', 'promise'],
1677
- "vue/no-constant-condition": "warn",
1678
- "vue/no-duplicate-attr-inheritance": "warn",
1679
- "vue/no-empty-pattern": "error",
1680
- "vue/no-extra-parens": ["error", "functions"],
1681
- "vue/no-irregular-whitespace": "error",
1682
- "vue/no-loss-of-precision": "error",
1683
- "vue/no-required-prop-with-default": "warn",
1684
- "vue/no-restricted-syntax": [
1685
- "error",
1686
- "DebuggerStatement",
1687
- "LabeledStatement",
1688
- "WithStatement"
1689
- ],
1690
- "vue/no-restricted-v-bind": ["error", "/^v-/"],
1691
- "vue/no-setup-props-reactivity-loss": "off",
1692
- "vue/no-sparse-arrays": "error",
1693
- "vue/no-unsupported-features": "warn",
1694
- "vue/no-unused-emit-declarations": "warn",
1695
- "vue/no-unused-refs": "error",
1696
- "vue/no-use-v-else-with-v-for": "error",
1697
- "vue/no-useless-mustaches": "warn",
1698
- "vue/no-useless-v-bind": "error",
1699
- "vue/no-v-html": "off",
1700
- "vue/no-v-text": "warn",
1701
- "vue/object-shorthand": [
1702
- "error",
1703
- "always",
1704
- {
1705
- avoidQuotes: true,
1706
- ignoreConstructors: false
1707
- }
1708
- ],
1709
- "vue/padding-line-between-blocks": ["error", "always"],
1710
- "vue/prefer-define-options": "warn",
1711
- "vue/prefer-separate-static-class": "error",
1712
- "vue/prefer-template": "error",
1713
- "vue/prop-name-casing": ["error", "camelCase"],
1714
- "vue/require-default-prop": "off",
1715
- "vue/require-macro-variable-name": [
1716
- "warn",
1717
- {
1718
- defineEmits: "emit",
1719
- defineProps: "props",
1720
- defineSlots: "slots",
1721
- useAttrs: "attrs",
1722
- useSlots: "slots"
1723
- }
1724
- ],
1725
- "vue/require-prop-types": "off",
1726
- // 'vue/singleline-html-element-content-newline': 'off',
1727
- "vue/space-infix-ops": "error",
1728
- "vue/space-unary-ops": ["error", { nonwords: false, words: true }],
1729
- "vue/valid-define-options": "warn",
1730
- ...overrides
1731
- }
1732
- }
1733
- ];
1734
- }
1735
-
1736
- // src/index.ts
1737
- var flatConfigProps = [
1738
- "name",
1739
- "languageOptions",
1740
- "linterOptions",
1741
- "processor",
1742
- "plugins",
1743
- "rules",
1744
- "settings"
1745
- ];
1746
- var defaultPluginRenaming = {
1747
- "@eslint-react": "react",
1748
- "@eslint-react/dom": "react-dom",
1749
- "@eslint-react/hooks-extra": "react-hooks-extra",
1750
- "@eslint-react/naming-convention": "react-naming-convention",
1751
- "@typescript-eslint": "ts",
1752
- "import-x": "import",
1753
- n: "node",
1754
- vitest: "test",
1755
- yml: "yaml"
1756
- };
1757
- async function defineConfig(options = {}, ...userConfigs) {
1758
- const {
1759
- autoRenamePlugins = true,
1760
- componentExts = [],
1761
- gitignore: enableGitignore = true,
1762
- react: enableReact = false,
1763
- regexp: enableRegexp = true,
1764
- svelte: enableSvelte = false,
1765
- tailwindcss: enableTailwindCSS = false,
1766
- typescript: enableTypeScript = hasTypeScript,
1767
- unocss: enableUnoCSS = false,
1768
- vue: enableVue = hasVue
1769
- } = options;
1770
- let isInEditor2 = options.isInEditor;
1771
- if (isInEditor2 == null) {
1772
- isInEditor2 = isInEditorEnv();
1773
- if (isInEditor2)
1774
- console.log(
1775
- "[@coderwyd/eslint-config] Detected running in editor, some rules are disabled."
1776
- );
1777
- }
1778
- const configs2 = [];
1779
- if (enableGitignore) {
1780
- if (typeof enableGitignore !== "boolean") {
1781
- configs2.push(
1782
- interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1783
- r({
1784
- ...enableGitignore,
1785
- name: "coderwyd/gitignore"
1786
- })
1787
- ])
1788
- );
1789
- } else {
1790
- configs2.push(
1791
- interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1792
- r({ name: "coderwyd/gitignore", strict: false })
1793
- ])
1794
- );
1795
- }
1796
- }
1797
- const typescriptOptions = resolveSubOptions(options, "typescript");
1798
- const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
1799
- configs2.push(
1800
- ignores(options.ignores),
1801
- javascript({
1802
- isInEditor: isInEditor2,
1803
- overrides: getOverrides(options, "javascript")
1804
- }),
1805
- comments(),
1806
- node(),
1807
- jsdoc(),
1808
- imports(),
1809
- unicorn(),
1810
- command(),
1811
- // Optional plugins (installed but not enabled by default)
1812
- perfectionist()
1813
- );
1814
- if (enableVue) componentExts.push("vue");
1815
- if (enableTypeScript) {
1816
- configs2.push(
1817
- typescript({
1818
- ...typescriptOptions,
1819
- componentExts,
1820
- overrides: getOverrides(options, "typescript")
1821
- })
1822
- );
1823
- }
1824
- if (enableRegexp)
1825
- configs2.push(regexp(typeof enableRegexp === "boolean" ? {} : enableRegexp));
1826
- if (options.test ?? true) {
1827
- configs2.push(
1828
- test({
1829
- isInEditor: isInEditor2,
1830
- overrides: getOverrides(options, "test")
1831
- })
1832
- );
1833
- }
1834
- if (enableVue) {
1835
- configs2.push(
1836
- vue({
1837
- ...resolveSubOptions(options, "vue"),
1838
- overrides: getOverrides(options, "typescript"),
1839
- typescript: !!enableTypeScript
1840
- })
1841
- );
1842
- }
1843
- if (enableReact) {
1844
- configs2.push(
1845
- react({
1846
- overrides: getOverrides(options, "react"),
1847
- tsconfigPath
1848
- })
1849
- );
1850
- }
1851
- if (enableSvelte) {
1852
- configs2.push(
1853
- svelte({
1854
- overrides: getOverrides(options, "svelte"),
1855
- typescript: !!enableTypeScript
1856
- })
1857
- );
1858
- }
1859
- if (enableUnoCSS) {
1860
- configs2.push(
1861
- unocss({
1862
- ...resolveSubOptions(options, "unocss"),
1863
- overrides: getOverrides(options, "unocss")
1864
- })
1865
- );
1866
- }
1867
- if (enableTailwindCSS) {
1868
- configs2.push(
1869
- tailwindcss({
1870
- ...resolveSubOptions(options, "tailwindcss"),
1871
- overrides: getOverrides(options, "tailwindcss")
1872
- })
1873
- );
1874
- }
1875
- if (options.jsonc ?? true) {
1876
- configs2.push(
1877
- jsonc({
1878
- overrides: getOverrides(options, "jsonc")
1879
- }),
1880
- sortPackageJson(),
1881
- sortTsconfig()
1882
- );
1883
- }
1884
- configs2.push(specials(), prettier());
1885
- if ("files" in options) {
1886
- throw new Error(
1887
- '[@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.'
1888
- );
1889
- }
1890
- const fusedConfig = flatConfigProps.reduce((acc, key) => {
1891
- if (key in options) acc[key] = options[key];
1892
- return acc;
1893
- }, {});
1894
- if (Object.keys(fusedConfig).length > 0) configs2.push([fusedConfig]);
1895
- const merged = await combine(...configs2, ...userConfigs);
1896
- if (autoRenamePlugins)
1897
- return renamePluginInConfigs(merged, defaultPluginRenaming);
1898
- return merged;
1899
- }
1900
- // Annotate the CommonJS export names for ESM import in node:
1901
- 0 && (module.exports = {
1902
- combine,
1903
- defaultPluginRenaming,
1904
- defineConfig,
1905
- ensurePackages,
1906
- getOverrides,
1907
- getVueVersion,
1908
- interopDefault,
1909
- isInEditorEnv,
1910
- isInGitHooksOrLintStaged,
1911
- isPackageInScope,
1912
- parserPlain,
1913
- renamePluginInConfigs,
1914
- renameRules,
1915
- resolveSubOptions,
1916
- toArray
1917
- });