@vida0905/eslint-config 2.8.0 → 2.9.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.
@@ -6,7 +6,7 @@ import path from "node:path";
6
6
  import { styleText } from "node:util";
7
7
 
8
8
  //#region package.json
9
- var version = "2.8.0";
9
+ var version = "2.9.0";
10
10
 
11
11
  //#endregion
12
12
  //#region src/cli/constants.ts
package/dist/index.d.mts CHANGED
@@ -15,6 +15,75 @@ interface RuleOptions {
15
15
  * @see https://github.com/azat-io/eslint-plugin-de-morgan/blob/main/docs/no-negated-disjunction.md
16
16
  */
17
17
  'de-morgan/no-negated-disjunction'?: Linter.RuleEntry<[]>;
18
+ /**
19
+ * Bans a list of dependencies from being used
20
+ * @see https://github.com/es-tooling/eslint-plugin-depend/blob/main/docs/rules/ban-dependencies.md
21
+ */
22
+ 'e18e/ban-dependencies'?: Linter.RuleEntry<E18EBanDependencies>;
23
+ /**
24
+ * Prefer optimized alternatives to `indexOf()` equality checks
25
+ */
26
+ 'e18e/no-indexof-equality'?: Linter.RuleEntry<[]>;
27
+ /**
28
+ * Prefer Array.prototype.at() over length-based indexing
29
+ */
30
+ 'e18e/prefer-array-at'?: Linter.RuleEntry<[]>;
31
+ /**
32
+ * Prefer Array.prototype.fill() over Array.from or map with constant values
33
+ */
34
+ 'e18e/prefer-array-fill'?: Linter.RuleEntry<[]>;
35
+ /**
36
+ * Prefer Array.from(iterable, mapper) over [...iterable].map(mapper) to avoid intermediate array allocation
37
+ */
38
+ 'e18e/prefer-array-from-map'?: Linter.RuleEntry<[]>;
39
+ /**
40
+ * Prefer Array.prototype.toReversed() over copying and reversing arrays
41
+ */
42
+ 'e18e/prefer-array-to-reversed'?: Linter.RuleEntry<[]>;
43
+ /**
44
+ * Prefer Array.prototype.toSorted() over copying and sorting arrays
45
+ */
46
+ 'e18e/prefer-array-to-sorted'?: Linter.RuleEntry<[]>;
47
+ /**
48
+ * Prefer Array.prototype.toSpliced() over copying and splicing arrays
49
+ */
50
+ 'e18e/prefer-array-to-spliced'?: Linter.RuleEntry<[]>;
51
+ /**
52
+ * Prefer Date.now() over new Date().getTime() and +new Date()
53
+ */
54
+ 'e18e/prefer-date-now'?: Linter.RuleEntry<[]>;
55
+ /**
56
+ * Prefer the exponentiation operator ** over Math.pow()
57
+ */
58
+ 'e18e/prefer-exponentiation-operator'?: Linter.RuleEntry<[]>;
59
+ /**
60
+ * Prefer .includes() over indexOf() comparisons for arrays and strings
61
+ */
62
+ 'e18e/prefer-includes'?: Linter.RuleEntry<[]>;
63
+ /**
64
+ * Prefer nullish coalescing operator (?? and ??=) over verbose null checks
65
+ */
66
+ 'e18e/prefer-nullish-coalescing'?: Linter.RuleEntry<[]>;
67
+ /**
68
+ * Prefer Object.hasOwn() over Object.prototype.hasOwnProperty.call() and obj.hasOwnProperty()
69
+ */
70
+ 'e18e/prefer-object-has-own'?: Linter.RuleEntry<[]>;
71
+ /**
72
+ * prefer `RegExp.test()` over `String.match()` and `RegExp.exec()` when only checking for match existence
73
+ */
74
+ 'e18e/prefer-regex-test'?: Linter.RuleEntry<[]>;
75
+ /**
76
+ * Prefer spread syntax over Array.concat(), Array.from(), Object.assign({}, ...), and Function.apply()
77
+ */
78
+ 'e18e/prefer-spread-syntax'?: Linter.RuleEntry<[]>;
79
+ /**
80
+ * Prefer passing function and arguments directly to setTimeout/setInterval instead of wrapping in an arrow function or using bind
81
+ */
82
+ 'e18e/prefer-timer-args'?: Linter.RuleEntry<[]>;
83
+ /**
84
+ * Prefer URL.canParse() over try-catch blocks for URL validation
85
+ */
86
+ 'e18e/prefer-url-canparse'?: Linter.RuleEntry<[]>;
18
87
  /**
19
88
  * Prefer recommended order of Nuxt config properties
20
89
  * @see https://eslint.nuxt.com/packages/plugin#nuxtnuxt-config-keys-order
@@ -26,6 +95,14 @@ interface RuleOptions {
26
95
  */
27
96
  'nuxt/prefer-import-meta'?: Linter.RuleEntry<[]>;
28
97
  }
98
+ /* ======= Declarations ======= */
99
+ // ----- e18e/ban-dependencies -----
100
+ type E18EBanDependencies = [] | [{
101
+ presets?: string[];
102
+ modules?: string[];
103
+ allowed?: string[];
104
+ }];
105
+ // Names of all the configs
29
106
  //#endregion
30
107
  //#region src/types.d.ts
31
108
  interface Rules extends RuleOptions {}
@@ -49,6 +126,13 @@ type OptionsConfig$1 = Omit<OptionsConfig, "overrides"> & {
49
126
  */
50
127
  deMorgan?: boolean | OptionsFiles;
51
128
  /**
129
+ * Enable e18e rules.
130
+ *
131
+ * @see https://github.com/e18e/eslint-plugin
132
+ * @default true
133
+ */
134
+ e18e?: boolean | OptionsOverrides & OptionsFiles;
135
+ /**
52
136
  * Enable Nuxt.js rules.
53
137
  *
54
138
  * Requires installing:
@@ -59,11 +143,8 @@ type OptionsConfig$1 = Omit<OptionsConfig, "overrides"> & {
59
143
  nuxt?: boolean | OptionsOverrides & OptionsFiles;
60
144
  };
61
145
  //#endregion
62
- //#region src/utils.d.ts
63
- declare function deepMerge<T extends object>(target: T, source: T): T;
64
- //#endregion
65
146
  //#region src/index.d.ts
66
147
  declare function defineConfig(options?: OptionsConfig$1, ...userConfigs: Awaitable<TypedFlatConfigItem>[]): FlatConfigComposer<TypedFlatConfigItem, ConfigNames>;
67
148
  declare function applyOptions(options: OptionsConfig$1): OptionsConfig$1;
68
149
  //#endregion
69
- export { applyOptions, deepMerge, defineConfig as default, defineConfig };
150
+ export { applyOptions, defineConfig as default, defineConfig };
package/dist/index.mjs CHANGED
@@ -3,6 +3,96 @@ import { isPackageExists } from "local-pkg";
3
3
 
4
4
  export * from "@antfu/eslint-config"
5
5
 
6
+ //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
7
+ function isPrimitive(value) {
8
+ return value == null || typeof value !== "object" && typeof value !== "function";
9
+ }
10
+
11
+ //#endregion
12
+ //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
13
+ function isTypedArray(x) {
14
+ return ArrayBuffer.isView(x) && !(x instanceof DataView);
15
+ }
16
+
17
+ //#endregion
18
+ //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/object/clone.mjs
19
+ function clone(obj) {
20
+ if (isPrimitive(obj)) return obj;
21
+ if (Array.isArray(obj) || isTypedArray(obj) || obj instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer) return obj.slice(0);
22
+ const prototype = Object.getPrototypeOf(obj);
23
+ const Constructor = prototype.constructor;
24
+ if (obj instanceof Date || obj instanceof Map || obj instanceof Set) return new Constructor(obj);
25
+ if (obj instanceof RegExp) {
26
+ const newRegExp = new Constructor(obj);
27
+ newRegExp.lastIndex = obj.lastIndex;
28
+ return newRegExp;
29
+ }
30
+ if (obj instanceof DataView) return new Constructor(obj.buffer.slice(0));
31
+ if (obj instanceof Error) {
32
+ const newError = new Constructor(obj.message);
33
+ newError.stack = obj.stack;
34
+ newError.name = obj.name;
35
+ newError.cause = obj.cause;
36
+ return newError;
37
+ }
38
+ if (typeof File !== "undefined" && obj instanceof File) return new Constructor([obj], obj.name, {
39
+ type: obj.type,
40
+ lastModified: obj.lastModified
41
+ });
42
+ if (typeof obj === "object") {
43
+ const newObject = Object.create(prototype);
44
+ return Object.assign(newObject, obj);
45
+ }
46
+ return obj;
47
+ }
48
+
49
+ //#endregion
50
+ //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
51
+ function isPlainObject(value) {
52
+ if (!value || typeof value !== "object") return false;
53
+ const proto = Object.getPrototypeOf(value);
54
+ if (!(proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null)) return false;
55
+ return Object.prototype.toString.call(value) === "[object Object]";
56
+ }
57
+
58
+ //#endregion
59
+ //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
60
+ function isUnsafeProperty(key) {
61
+ return key === "__proto__";
62
+ }
63
+
64
+ //#endregion
65
+ //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/object/mergeWith.mjs
66
+ function mergeWith(target, source, merge) {
67
+ const sourceKeys = Object.keys(source);
68
+ for (let i = 0; i < sourceKeys.length; i++) {
69
+ const key = sourceKeys[i];
70
+ if (isUnsafeProperty(key)) continue;
71
+ const sourceValue = source[key];
72
+ const targetValue = target[key];
73
+ const merged = merge(targetValue, sourceValue, key, target, source);
74
+ if (merged !== void 0) target[key] = merged;
75
+ else if (Array.isArray(sourceValue)) if (Array.isArray(targetValue)) target[key] = mergeWith(targetValue, sourceValue, merge);
76
+ else target[key] = mergeWith([], sourceValue, merge);
77
+ else if (isPlainObject(sourceValue)) if (isPlainObject(targetValue)) target[key] = mergeWith(targetValue, sourceValue, merge);
78
+ else target[key] = mergeWith({}, sourceValue, merge);
79
+ else if (targetValue === void 0 || sourceValue !== void 0) target[key] = sourceValue;
80
+ }
81
+ return target;
82
+ }
83
+
84
+ //#endregion
85
+ //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/object/toMerged.mjs
86
+ function toMerged(target, source) {
87
+ return mergeWith(clone(target), source, function mergeRecursively(targetValue, sourceValue) {
88
+ if (Array.isArray(sourceValue)) if (Array.isArray(targetValue)) return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
89
+ else return mergeWith([], sourceValue, mergeRecursively);
90
+ else if (isPlainObject(sourceValue)) if (isPlainObject(targetValue)) return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
91
+ else return mergeWith({}, sourceValue, mergeRecursively);
92
+ });
93
+ }
94
+
95
+ //#endregion
6
96
  //#region src/configs/de-morgan.ts
7
97
  async function deMorgan(options = {}) {
8
98
  const { files = [GLOB_SRC] } = options;
@@ -13,6 +103,22 @@ async function deMorgan(options = {}) {
13
103
  }];
14
104
  }
15
105
 
106
+ //#endregion
107
+ //#region src/configs/e18e.ts
108
+ async function e18e(options = {}) {
109
+ const { files = [GLOB_SRC], overrides } = options;
110
+ const recommendedConfig = (await interopDefault(import("@e18e/eslint-plugin"))).configs.recommended;
111
+ return [{
112
+ name: "vida/e18e/rules",
113
+ files,
114
+ ...recommendedConfig,
115
+ rules: {
116
+ ...recommendedConfig.rules,
117
+ ...overrides
118
+ }
119
+ }];
120
+ }
121
+
16
122
  //#endregion
17
123
  //#region src/configs/nuxt.ts
18
124
  async function nuxt(options = {}) {
@@ -112,31 +218,26 @@ const antfuOverrides = Object.freeze({
112
218
  vue
113
219
  });
114
220
 
115
- //#endregion
116
- //#region src/utils.ts
117
- function deepMerge(target, source) {
118
- for (const key in source) if (Object.hasOwn(source, key)) if (source[key] instanceof Object && target[key] instanceof Object) target[key] = deepMerge(target[key], source[key]);
119
- else target[key] = source[key];
120
- return target;
121
- }
122
-
123
221
  //#endregion
124
222
  //#region src/index.ts
125
- const VuePackages = [
126
- "vue",
127
- "nuxt",
128
- "vitepress",
129
- "@slidev/cli"
130
- ];
131
- function defineConfig(options = {
223
+ const defaultOptions = {
132
224
  deMorgan: true,
225
+ e18e: true,
133
226
  nuxt: isPackageExists("nuxt"),
134
- vue: VuePackages.some((i) => isPackageExists(i)),
135
- typescript: isPackageExists("typescript")
136
- }, ...userConfigs) {
137
- const { deMorgan: enableDeMorgan, nuxt: enableNuxt } = options;
227
+ typescript: isPackageExists("typescript"),
228
+ vue: [
229
+ "vue",
230
+ "nuxt",
231
+ "vitepress",
232
+ "@slidev/cli"
233
+ ].some((i) => isPackageExists(i))
234
+ };
235
+ function defineConfig(options = {}, ...userConfigs) {
236
+ options = toMerged(defaultOptions, options);
237
+ const { deMorgan: enableDeMorgan, e18e: enableE18e, nuxt: enableNuxt } = options;
138
238
  const configs = [];
139
239
  if (enableDeMorgan) configs.push(deMorgan());
240
+ if (enableE18e) configs.push(e18e());
140
241
  if (enableNuxt) configs.push(nuxt());
141
242
  return antfu(applyOptions(options), ...configs, ...userConfigs);
142
243
  }
@@ -145,11 +246,11 @@ function applyOptions(options) {
145
246
  const optionVal = options[key];
146
247
  const defaultVal = antfuOverrides[key];
147
248
  if (optionVal === true) options[key] = defaultVal;
148
- else if (optionVal !== false) options[key] = optionVal ? deepMerge(defaultVal, optionVal) : defaultVal;
249
+ else if (optionVal !== false) options[key] = optionVal ? toMerged(defaultVal, optionVal) : defaultVal;
149
250
  }
150
251
  return options;
151
252
  }
152
253
  var src_default = defineConfig;
153
254
 
154
255
  //#endregion
155
- export { applyOptions, deepMerge, src_default as default, defineConfig };
256
+ export { applyOptions, src_default as default, defineConfig };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vida0905/eslint-config",
3
3
  "type": "module",
4
- "version": "2.8.0",
4
+ "version": "2.9.0",
5
5
  "description": "Vida Xie's ESLint Config",
6
6
  "author": "Vida Xie <vida_2020@163.com> (https://github.com/9romise/)",
7
7
  "license": "MIT",
@@ -41,6 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@antfu/eslint-config": "^6.7.3",
44
+ "@e18e/eslint-plugin": "^0.1.3",
44
45
  "cac": "^6.7.14",
45
46
  "eslint-flat-config-utils": "^2.1.4",
46
47
  "eslint-plugin-de-morgan": "^2.0.0",
@@ -48,6 +49,7 @@
48
49
  },
49
50
  "devDependencies": {
50
51
  "@types/node": "^25.0.3",
52
+ "es-toolkit": "^1.43.0",
51
53
  "eslint": "^9.39.2",
52
54
  "eslint-typegen": "^2.3.0",
53
55
  "husky": "^9.1.7",