@wongxy/eslint-config 4.0.1 → 4.0.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # eslint-config
2
2
 
3
- Personal ESLint configuration, based on `@antfu/eslint-config`
3
+ ESLint config based on [`@antfu/eslint-config`](https://github.com/antfu/eslint-config).
4
4
 
5
5
  ## Usage
6
6
 
@@ -8,11 +8,21 @@ Personal ESLint configuration, based on `@antfu/eslint-config`
8
8
  pnpm i -D eslint @wongxy/eslint-config
9
9
  ```
10
10
 
11
- And create `eslint.config.mjs` in your project root:
12
-
13
11
  ```js
14
12
  // eslint.config.mjs
15
13
  import wongxy from '@wongxy/eslint-config'
16
14
 
17
15
  export default wongxy()
18
16
  ```
17
+
18
+ ## Options
19
+
20
+ Everything `@antfu/eslint-config` accepts is passed through. On top of that:
21
+
22
+ | Option | Uses | Default |
23
+ | --- | --- | --- |
24
+ | `react` | `@eslint-react/eslint-plugin` | on when `react`, `react-dom`, `next` or `react-native` is installed |
25
+ | `reactnative` | `ts/no-require-imports`, `ts/no-use-before-define` off | on when `react-native` is installed |
26
+ | `tailwindcss` | `eslint-plugin-better-tailwindcss` | on when `tailwindcss` is installed |
27
+
28
+ `options.rules` and the per-integration `overrides` win over the defaults this config adds. Those defaults live in named `wongxy/*` configs.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { OptionsOverrides, antfu } from "@antfu/eslint-config";
1
+ import { Awaitable, OptionsConfig, OptionsOverrides, TypedFlatConfigItem, antfu } from "@antfu/eslint-config";
2
2
  import { Linter } from "eslint";
3
3
  //#region src/typegen.d.ts
4
4
  interface RuleOptions {
@@ -3033,7 +3033,7 @@ type TwNoUnnecessaryWhitespace = [] | [{
3033
3033
  }];
3034
3034
  //#endregion
3035
3035
  //#region src/types.d.ts
3036
- type Options = Parameters<typeof antfu>[0] & {
3036
+ type Options = OptionsConfig & Omit<TypedFlatConfigItem, 'files' | 'ignores'> & {
3037
3037
  /**
3038
3038
  * Enable Tailwind rules.
3039
3039
  *
@@ -3047,7 +3047,7 @@ type Options = Parameters<typeof antfu>[0] & {
3047
3047
  *
3048
3048
  * @default auto-detect based on the dependencies
3049
3049
  */
3050
- reactnative?: boolean;
3050
+ reactnative?: boolean | OptionsOverrides;
3051
3051
  /**
3052
3052
  * Enable react rules.
3053
3053
  *
@@ -3055,7 +3055,7 @@ type Options = Parameters<typeof antfu>[0] & {
3055
3055
  */
3056
3056
  react?: boolean | OptionsOverrides;
3057
3057
  };
3058
- type UserConfig = Parameters<typeof antfu>[1] & {
3058
+ type UserConfig = Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]> & {
3059
3059
  rules?: RuleOptions;
3060
3060
  };
3061
3061
  type OptionsReturn = ReturnType<typeof antfu>;
@@ -3074,6 +3074,6 @@ interface OptionsTailwindCSS {
3074
3074
  }
3075
3075
  //#endregion
3076
3076
  //#region src/index.d.ts
3077
- declare function wongxy(options?: Options, ...userConfigs: UserConfig[]): OptionsReturn;
3077
+ export default function wongxy(options?: Options, ...userConfigs: UserConfig[]): OptionsReturn;
3078
3078
  //#endregion
3079
- export { wongxy as default };
3079
+ export type { Options, OptionsReturn, OptionsTailwindCSS, PickKeysByPrefix, RuleOptionsTailwindCSS, UserConfig };
package/dist/index.mjs CHANGED
@@ -39,87 +39,92 @@ const ReactPackages = [
39
39
  "react-dom",
40
40
  "next"
41
41
  ];
42
- function resolveRules(overrides, rules) {
43
- return Object.fromEntries(Object.entries(rules).filter(([k]) => !overrides[k]));
42
+ const commonRules = {
43
+ "no-console": "off",
44
+ "no-alert": "off",
45
+ "no-multiple-empty-lines": "warn",
46
+ "antfu/top-level-function": "off",
47
+ "antfu/if-newline": "off",
48
+ "style/brace-style": [
49
+ "error",
50
+ "1tbs",
51
+ { allowSingleLine: true }
52
+ ],
53
+ "perfectionist/sort-jsx-props": ["warn", {
54
+ order: "asc",
55
+ type: "natural",
56
+ groups: [
57
+ "reserved-first",
58
+ "reserved-second",
59
+ "unknown",
60
+ "reserved-last"
61
+ ],
62
+ customGroups: [
63
+ {
64
+ groupName: "reserved-first",
65
+ elementNamePattern: ["key", "ref"]
66
+ },
67
+ {
68
+ groupName: "reserved-second",
69
+ elementNamePattern: ["id", "name"]
70
+ },
71
+ {
72
+ groupName: "reserved-last",
73
+ elementNamePattern: ["asChild"]
74
+ }
75
+ ]
76
+ }]
77
+ };
78
+ const vueRules = {
79
+ "vue/singleline-html-element-content-newline": "off",
80
+ "vue/valid-template-root": "off",
81
+ "vue/block-order": ["warn", { order: [["script", "template"], "style"] }],
82
+ "vue/custom-event-name-casing": "off"
83
+ };
84
+ const reactRules = { "react/prefer-destructuring-assignment": "off" };
85
+ const typescriptRules = { "ts/consistent-type-imports": ["error", {
86
+ disallowTypeAnnotations: false,
87
+ fixStyle: "inline-type-imports",
88
+ prefer: "type-imports"
89
+ }] };
90
+ const reactNativeRules = {
91
+ "ts/no-require-imports": "off",
92
+ "ts/no-use-before-define": "off"
93
+ };
94
+ function resolveRules(rules, ...chosen) {
95
+ const taken = Object.assign({}, ...chosen);
96
+ return Object.fromEntries(Object.entries(rules).filter(([rule]) => !(rule in taken)));
44
97
  }
45
98
  function wongxy(options = {}, ...userConfigs) {
46
- const { react: enableReact = ReactPackages.some((i) => isPackageExists(i)), typescript: enableTypeScript = isPackageExists("typescript"), vue: enableVue = VuePackages.some((i) => isPackageExists(i)), tailwindcss: enableTailwind = isPackageExists("tailwindcss"), reactnative: enableReactNative = isPackageExists("react-native") } = options;
47
- const configs = [];
48
- configs.push({
99
+ const { react: enableReact = ReactPackages.some((i) => isPackageExists(i)), reactnative: enableReactNative = isPackageExists("react-native"), tailwindcss: enableTailwind = isPackageExists("tailwindcss"), typescript: enableTypeScript = isPackageExists("typescript") || isPackageExists("@typescript/native-preview"), vue: enableVue = VuePackages.some((i) => isPackageExists(i)) } = options;
100
+ const reactNativeOptions = typeof options.reactnative === "object" ? options.reactnative : {};
101
+ const tailwindOptions = typeof options.tailwindcss === "object" ? options.tailwindcss : void 0;
102
+ const globalRules = options.rules;
103
+ const configs = [{
49
104
  name: "wongxy/common",
50
- rules: resolveRules(options.rules ?? {}, {
51
- "no-console": "off",
52
- "no-alert": "off",
53
- "no-multiple-empty-lines": "warn",
54
- "antfu/top-level-function": "off",
55
- "antfu/if-newline": "off",
56
- "style/brace-style": [
57
- "error",
58
- "1tbs",
59
- { allowSingleLine: true }
60
- ],
61
- "perfectionist/sort-jsx-props": ["warn", {
62
- order: "asc",
63
- type: "natural",
64
- groups: [
65
- "reserved-first",
66
- "reserved-second",
67
- "unknown",
68
- "reserved-last"
69
- ],
70
- customGroups: [
71
- {
72
- groupName: "reserved-first",
73
- elementNamePattern: ["key", "ref"]
74
- },
75
- {
76
- groupName: "reserved-second",
77
- elementNamePattern: ["id", "name"]
78
- },
79
- {
80
- groupName: "reserved-last",
81
- elementNamePattern: ["asChild"]
82
- }
83
- ]
84
- }]
85
- })
86
- });
105
+ rules: resolveRules(commonRules, globalRules)
106
+ }];
87
107
  if (enableVue) configs.push({
88
108
  name: "wongxy/vue",
89
109
  files: [GLOB_VUE],
90
- rules: resolveRules(getOverrides(options, "vue"), {
91
- "vue/singleline-html-element-content-newline": "off",
92
- "vue/valid-template-root": "off",
93
- "vue/block-order": ["warn", { order: [["script", "template"], "style"] }],
94
- "vue/custom-event-name-casing": "off"
95
- })
110
+ rules: resolveRules(vueRules, globalRules, getOverrides(options, "vue"))
96
111
  });
97
112
  if (enableReact) configs.push({
98
113
  name: "wongxy/react",
99
114
  files: [GLOB_SRC],
100
- rules: resolveRules(getOverrides(options, "react"), { "react/prefer-destructuring-assignment": "off" })
115
+ rules: resolveRules(reactRules, globalRules, getOverrides(options, "react"))
101
116
  });
102
117
  if (enableTypeScript) configs.push({
103
118
  name: "wongxy/typescript",
104
119
  files: [GLOB_TS, GLOB_TSX],
105
- rules: resolveRules(getOverrides(options, "typescript"), { "ts/consistent-type-imports": ["error", {
106
- disallowTypeAnnotations: false,
107
- fixStyle: "inline-type-imports",
108
- prefer: "type-imports"
109
- }] })
120
+ rules: resolveRules(typescriptRules, globalRules, getOverrides(options, "typescript"))
110
121
  });
111
122
  if (enableReactNative) configs.push({
112
123
  name: "wongxy/reactnative",
113
124
  files: [GLOB_TS, GLOB_TSX],
114
- rules: resolveRules(getOverrides(options, "typescript"), {
115
- "ts/no-require-imports": "off",
116
- "ts/no-use-before-define": "off"
117
- })
125
+ rules: resolveRules(reactNativeRules, globalRules, reactNativeOptions.overrides)
118
126
  });
119
- if (enableTailwind) {
120
- const tw = typeof options.tailwindcss === "object" ? options.tailwindcss : void 0;
121
- configs.push(tailwindcss(tw));
122
- }
127
+ if (enableTailwind) configs.push(tailwindcss(tailwindOptions));
123
128
  return antfu(options, ...configs, ...userConfigs);
124
129
  }
125
130
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wongxy/eslint-config",
3
3
  "type": "module",
4
- "version": "4.0.1",
4
+ "version": "4.0.3",
5
5
  "description": "xiyaowong's eslint config",
6
6
  "author": "xiyaowong (https://github.com/xiyaowong)",
7
7
  "license": "MIT",
@@ -20,35 +20,33 @@
20
20
  "eslint": "^10.9.1",
21
21
  "eslint-plugin-astro": "^3.1.0",
22
22
  "eslint-plugin-better-tailwindcss": "^4.7.0",
23
- "eslint-plugin-react-hooks": "^7.0.1",
24
23
  "eslint-plugin-react-refresh": "^0.5.5"
25
24
  },
26
25
  "dependencies": {
27
- "@antfu/eslint-config": "^9.3.0",
28
- "eslint-flat-config-utils": "^3.2.0",
26
+ "@antfu/eslint-config": "^9.5.1",
29
27
  "local-pkg": "^1.2.1"
30
28
  },
31
29
  "devDependencies": {
32
- "@antfu/ni": "^30.5.0",
30
+ "@antfu/ni": "^30.6.0",
33
31
  "@types/eslint": "^9.6.1",
34
- "@types/node": "^24.10.0",
35
- "bumpp": "^12.2.2",
36
- "eslint": "^10.9.1",
32
+ "@types/node": "^26.6.4",
33
+ "bumpp": "^12.3.0",
34
+ "eslint": "^10.12.0",
37
35
  "eslint-typegen": "^2.3.1",
38
36
  "esno": "^4.8.0",
39
- "tsdown": "^0.22.14",
40
- "typescript": "^5.9.3"
37
+ "tsdown": "^0.23.0",
38
+ "typescript": "^6.0.3"
41
39
  },
42
40
  "scripts": {
43
41
  "build": "nr typegen && tsdown --clean --dts",
44
42
  "stub": "tsdown --format esm",
45
43
  "watch": "tsdown --watch",
46
- "dev": "tsdown --watch & eslint-flat-config-viewer",
44
+ "dev": "tsdown --watch & nlx eslint-flat-config-viewer",
47
45
  "lint:fix": "eslint . --fix",
48
46
  "lint": "eslint .",
49
47
  "release": "bumpp && pnpm publish",
50
48
  "inspect": "nlx @eslint/config-inspector",
51
49
  "typegen": "esno scripts/typegen.ts",
52
- "typecheck": "tsc --noEmit"
50
+ "typecheck": "nr typegen && tsc --noEmit"
53
51
  }
54
52
  }