@wongxy/eslint-config 0.0.28 → 1.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 CHANGED
@@ -24,50 +24,75 @@ __export(src_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
26
  var import_eslint_config = require("@antfu/eslint-config");
27
+ var import_local_pkg = require("local-pkg");
28
+ var VuePackages = [
29
+ "vue",
30
+ "nuxt",
31
+ "vitepress",
32
+ "@slidev/cli"
33
+ ];
34
+ var ReactPackages = [
35
+ "react",
36
+ "react-native",
37
+ "react-dom",
38
+ "next"
39
+ ];
27
40
  function wongxy(options = {}, ...userConfigs) {
28
- const finalOptions = { ...options, react: options.react || options.reactnative };
29
- const configs = [];
30
- configs.push({
31
- name: "wongxy/general",
32
- rules: {
33
- "no-console": "off",
34
- "no-alert": "off",
35
- "no-multiple-empty-lines": "warn",
36
- "antfu/top-level-function": "off",
37
- "antfu/if-newline": "off",
38
- "import/order": ["error", { "newlines-between": "always" }],
39
- "style/brace-style": ["error", "1tbs", { allowSingleLine: true }]
40
- }
41
- });
42
- if (options.vue) {
43
- configs.push({
44
- name: "wongxy/vue",
45
- files: ["**/*.vue"],
46
- rules: {
41
+ const finalOptions = {
42
+ ...options,
43
+ vue: options.vue ?? VuePackages.some((i) => (0, import_local_pkg.isPackageExists)(i)),
44
+ typescript: options.typescript ?? (0, import_local_pkg.isPackageExists)("typescript"),
45
+ react: (options.react || options.reactnative) ?? ReactPackages.some((i) => (0, import_local_pkg.isPackageExists)(i)),
46
+ reactnative: options.reactnative ?? (0, import_local_pkg.isPackageExists)("react-native")
47
+ };
48
+ finalOptions.rules = {
49
+ "no-console": "off",
50
+ "no-alert": "off",
51
+ "no-multiple-empty-lines": "warn",
52
+ "antfu/top-level-function": "off",
53
+ "antfu/if-newline": "off",
54
+ "import/order": ["error", { "newlines-between": "always" }],
55
+ "style/brace-style": ["error", "1tbs", { allowSingleLine: true }],
56
+ ...finalOptions.rules
57
+ };
58
+ if (finalOptions.vue) {
59
+ const vue = typeof finalOptions.vue === "object" ? finalOptions.vue : {};
60
+ finalOptions.vue = {
61
+ ...vue,
62
+ overrides: {
47
63
  "vue/singleline-html-element-content-newline": "off",
48
64
  "vue/valid-template-root": "off",
49
65
  "vue/block-order": ["warn", { order: [["script", "template"], "style"] }],
50
- "vue/custom-event-name-casing": "off"
66
+ "vue/custom-event-name-casing": "off",
67
+ ...vue.overrides
51
68
  }
52
- });
69
+ };
53
70
  }
54
- if (options.react) {
55
- configs.push({
56
- name: "wongxy/react",
57
- rules: {
58
- "react/prefer-destructuring-assignment": "off"
71
+ if (finalOptions.react) {
72
+ const react = typeof finalOptions.react === "object" ? finalOptions.react : {};
73
+ finalOptions.react = {
74
+ ...react,
75
+ overrides: {
76
+ "react/prefer-destructuring-assignment": "off",
77
+ ...react.overrides
59
78
  }
60
- });
79
+ };
61
80
  }
62
- if (options.reactnative) {
63
- configs.push({
64
- name: "wongxy/reactnative",
65
- rules: {
66
- "ts/no-require-imports": "off",
67
- "ts/no-use-before-define": "off"
81
+ if (finalOptions.typescript) {
82
+ const typescript = typeof finalOptions.typescript === "object" ? finalOptions.typescript : {};
83
+ finalOptions.typescript = {
84
+ ...typescript,
85
+ overrides: {
86
+ "ts/consistent-type-imports": ["error", { disallowTypeAnnotations: false, fixStyle: "inline-type-imports", prefer: "type-imports" }],
87
+ ...finalOptions.reactnative ? {
88
+ "ts/no-require-imports": "off",
89
+ "ts/no-use-before-define": "off"
90
+ } : void 0,
91
+ ...typescript.overrides
68
92
  }
69
- });
93
+ };
70
94
  }
71
- return (0, import_eslint_config.antfu)(finalOptions, ...configs, ...userConfigs);
95
+ delete finalOptions.reactnative;
96
+ return (0, import_eslint_config.antfu)(finalOptions, ...userConfigs);
72
97
  }
73
98
  var src_default = wongxy;
package/dist/index.js CHANGED
@@ -1,50 +1,75 @@
1
1
  // src/index.ts
2
2
  import { antfu } from "@antfu/eslint-config";
3
+ import { isPackageExists } from "local-pkg";
4
+ var VuePackages = [
5
+ "vue",
6
+ "nuxt",
7
+ "vitepress",
8
+ "@slidev/cli"
9
+ ];
10
+ var ReactPackages = [
11
+ "react",
12
+ "react-native",
13
+ "react-dom",
14
+ "next"
15
+ ];
3
16
  function wongxy(options = {}, ...userConfigs) {
4
- const finalOptions = { ...options, react: options.react || options.reactnative };
5
- const configs = [];
6
- configs.push({
7
- name: "wongxy/general",
8
- rules: {
9
- "no-console": "off",
10
- "no-alert": "off",
11
- "no-multiple-empty-lines": "warn",
12
- "antfu/top-level-function": "off",
13
- "antfu/if-newline": "off",
14
- "import/order": ["error", { "newlines-between": "always" }],
15
- "style/brace-style": ["error", "1tbs", { allowSingleLine: true }]
16
- }
17
- });
18
- if (options.vue) {
19
- configs.push({
20
- name: "wongxy/vue",
21
- files: ["**/*.vue"],
22
- rules: {
17
+ const finalOptions = {
18
+ ...options,
19
+ vue: options.vue ?? VuePackages.some((i) => isPackageExists(i)),
20
+ typescript: options.typescript ?? isPackageExists("typescript"),
21
+ react: (options.react || options.reactnative) ?? ReactPackages.some((i) => isPackageExists(i)),
22
+ reactnative: options.reactnative ?? isPackageExists("react-native")
23
+ };
24
+ finalOptions.rules = {
25
+ "no-console": "off",
26
+ "no-alert": "off",
27
+ "no-multiple-empty-lines": "warn",
28
+ "antfu/top-level-function": "off",
29
+ "antfu/if-newline": "off",
30
+ "import/order": ["error", { "newlines-between": "always" }],
31
+ "style/brace-style": ["error", "1tbs", { allowSingleLine: true }],
32
+ ...finalOptions.rules
33
+ };
34
+ if (finalOptions.vue) {
35
+ const vue = typeof finalOptions.vue === "object" ? finalOptions.vue : {};
36
+ finalOptions.vue = {
37
+ ...vue,
38
+ overrides: {
23
39
  "vue/singleline-html-element-content-newline": "off",
24
40
  "vue/valid-template-root": "off",
25
41
  "vue/block-order": ["warn", { order: [["script", "template"], "style"] }],
26
- "vue/custom-event-name-casing": "off"
42
+ "vue/custom-event-name-casing": "off",
43
+ ...vue.overrides
27
44
  }
28
- });
45
+ };
29
46
  }
30
- if (options.react) {
31
- configs.push({
32
- name: "wongxy/react",
33
- rules: {
34
- "react/prefer-destructuring-assignment": "off"
47
+ if (finalOptions.react) {
48
+ const react = typeof finalOptions.react === "object" ? finalOptions.react : {};
49
+ finalOptions.react = {
50
+ ...react,
51
+ overrides: {
52
+ "react/prefer-destructuring-assignment": "off",
53
+ ...react.overrides
35
54
  }
36
- });
55
+ };
37
56
  }
38
- if (options.reactnative) {
39
- configs.push({
40
- name: "wongxy/reactnative",
41
- rules: {
42
- "ts/no-require-imports": "off",
43
- "ts/no-use-before-define": "off"
57
+ if (finalOptions.typescript) {
58
+ const typescript = typeof finalOptions.typescript === "object" ? finalOptions.typescript : {};
59
+ finalOptions.typescript = {
60
+ ...typescript,
61
+ overrides: {
62
+ "ts/consistent-type-imports": ["error", { disallowTypeAnnotations: false, fixStyle: "inline-type-imports", prefer: "type-imports" }],
63
+ ...finalOptions.reactnative ? {
64
+ "ts/no-require-imports": "off",
65
+ "ts/no-use-before-define": "off"
66
+ } : void 0,
67
+ ...typescript.overrides
44
68
  }
45
- });
69
+ };
46
70
  }
47
- return antfu(finalOptions, ...configs, ...userConfigs);
71
+ delete finalOptions.reactnative;
72
+ return antfu(finalOptions, ...userConfigs);
48
73
  }
49
74
  var src_default = wongxy;
50
75
  export {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wongxy/eslint-config",
3
3
  "type": "module",
4
- "version": "0.0.28",
4
+ "version": "1.0.0",
5
5
  "description": "xiyaowong's eslint config",
6
6
  "author": "xiyaowong (https://github.com/xiyaowong)",
7
7
  "license": "MIT",
@@ -23,7 +23,8 @@
23
23
  "eslint-plugin-react-refresh": "^0.4.4"
24
24
  },
25
25
  "dependencies": {
26
- "@antfu/eslint-config": "^2.24.1"
26
+ "@antfu/eslint-config": "^2.24.1",
27
+ "local-pkg": "^0.5.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@types/eslint": "^9.6.0",