@wongxy/eslint-config 2.0.1 → 3.0.1

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
@@ -1,4 +1,3 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
1
  //#region rolldown:runtime
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
@@ -6,12 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
6
  var __getProtoOf = Object.getPrototypeOf;
8
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
14
- };
15
8
  var __copyProps = (to, from, except, desc) => {
16
9
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
17
10
  key = keys[i];
@@ -22,31 +15,39 @@ var __copyProps = (to, from, except, desc) => {
22
15
  }
23
16
  return to;
24
17
  };
25
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
26
18
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
27
19
  value: mod,
28
20
  enumerable: true
29
21
  }) : target, mod));
30
22
 
31
23
  //#endregion
32
- const __antfu_eslint_config = __toESM(require("@antfu/eslint-config"));
33
- const local_pkg = __toESM(require("local-pkg"));
34
- const eslint_plugin_tailwindcss = __toESM(require("eslint-plugin-tailwindcss"));
24
+ let __antfu_eslint_config = require("@antfu/eslint-config");
25
+ __antfu_eslint_config = __toESM(__antfu_eslint_config);
26
+ let local_pkg = require("local-pkg");
27
+ local_pkg = __toESM(local_pkg);
28
+ let eslint_plugin_better_tailwindcss = require("eslint-plugin-better-tailwindcss");
29
+ eslint_plugin_better_tailwindcss = __toESM(eslint_plugin_better_tailwindcss);
35
30
 
36
31
  //#region src/tailwindcss.ts
37
- async function tailwindcss(options) {
38
- const { overrides = {} } = options ?? {};
32
+ async function tailwindcss(options = {}) {
33
+ const { overrides = {}, settings } = options;
34
+ const rules = {
35
+ "tw/enforce-consistent-class-order": "warn",
36
+ "tw/enforce-consistent-line-wrapping": ["warn", { printWidth: 100 }],
37
+ "tw/no-duplicate-classes": "warn",
38
+ "tw/no-unnecessary-whitespace": "warn",
39
+ "tw/no-conflicting-classes": "warn",
40
+ "tw/no-unregistered-classes": "warn"
41
+ };
39
42
  return [{
40
- name: "wongxy/tailwindcss",
41
- plugins: { tw: eslint_plugin_tailwindcss.default },
43
+ name: "wongxy/tailwindcss/setup",
44
+ plugins: { tw: eslint_plugin_better_tailwindcss.default },
42
45
  languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
46
+ ...!!settings && { settings: { "better-tailwindcss": settings } }
47
+ }, {
48
+ name: "wongxy/tailwindcss/rules",
43
49
  rules: {
44
- "tw/classnames-order": "warn",
45
- "tw/enforces-negative-arbitrary-values": "warn",
46
- "tw/enforces-shorthand": "warn",
47
- "tw/migration-from-tailwind-2": "warn",
48
- "tw/no-arbitrary-value": "off",
49
- "tw/no-contradicting-classname": "error",
50
+ ...rules,
50
51
  ...overrides
51
52
  }
52
53
  }];
@@ -54,11 +55,6 @@ async function tailwindcss(options) {
54
55
 
55
56
  //#endregion
56
57
  //#region src/index.ts
57
- var src_exports = {};
58
- __export(src_exports, {
59
- default: () => wongxy,
60
- tailwindcss: () => tailwindcss
61
- });
62
58
  const VuePackages = [
63
59
  "vue",
64
60
  "nuxt",
@@ -71,80 +67,80 @@ const ReactPackages = [
71
67
  "react-dom",
72
68
  "next"
73
69
  ];
74
- function wongxy(options, ...userConfigs) {
75
- options = options ?? {};
76
- const finalOptions = {
77
- ...options,
78
- vue: options.vue ?? VuePackages.some((i) => (0, local_pkg.isPackageExists)(i)),
79
- typescript: options.typescript ?? (0, local_pkg.isPackageExists)("typescript"),
80
- react: (options.react || options.reactnative) ?? ReactPackages.some((i) => (0, local_pkg.isPackageExists)(i)),
81
- reactnative: options.reactnative ?? (0, local_pkg.isPackageExists)("react-native"),
82
- tailwindcss: options.tailwindcss ?? (0, local_pkg.isPackageExists)("tailwindcss")
83
- };
84
- const rules = {
85
- "no-console": "off",
86
- "no-alert": "off",
87
- "no-multiple-empty-lines": "warn",
88
- "antfu/top-level-function": "off",
89
- "antfu/if-newline": "off",
90
- "style/brace-style": [
91
- "error",
92
- "1tbs",
93
- { allowSingleLine: true }
94
- ]
95
- };
96
- for (const key in finalOptions.rules) delete rules[key];
97
- userConfigs.splice(0, 0, {
98
- name: "wongxy/rules",
99
- rules
70
+ function resolveRules(overrides, rules) {
71
+ return Object.fromEntries(Object.entries(rules).filter(([k]) => !overrides[k]));
72
+ }
73
+ function wongxy(options = {}, ...userConfigs) {
74
+ const { react: enableReact = ReactPackages.some((i) => (0, local_pkg.isPackageExists)(i)), typescript: enableTypeScript = (0, local_pkg.isPackageExists)("typescript"), vue: enableVue = VuePackages.some((i) => (0, local_pkg.isPackageExists)(i)), tailwindcss: enableTailwind = (0, local_pkg.isPackageExists)("tailwindcss"), reactnative: enableReactNative = (0, local_pkg.isPackageExists)("react-native") } = options;
75
+ const configs = [];
76
+ configs.push({
77
+ name: "wongxy/common",
78
+ rules: resolveRules(options.rules ?? {}, {
79
+ "no-console": "off",
80
+ "no-alert": "off",
81
+ "no-multiple-empty-lines": "warn",
82
+ "antfu/top-level-function": "off",
83
+ "antfu/if-newline": "off",
84
+ "style/brace-style": [
85
+ "error",
86
+ "1tbs",
87
+ { allowSingleLine: true }
88
+ ],
89
+ "perfectionist/sort-jsx-props": ["warn", {
90
+ order: "asc",
91
+ type: "natural",
92
+ groups: [
93
+ "reserved-first",
94
+ "reserved-second",
95
+ "unknown",
96
+ "reserved-last"
97
+ ],
98
+ customGroups: {
99
+ "reserved-first": ["key", "ref"],
100
+ "reserved-second": ["id", "name"],
101
+ "reserved-last": ["asChild"]
102
+ }
103
+ }]
104
+ })
100
105
  });
101
- if (finalOptions.vue) {
102
- const vue = typeof finalOptions.vue === "object" ? finalOptions.vue : {};
103
- finalOptions.vue = {
104
- ...vue,
105
- overrides: {
106
- "vue/singleline-html-element-content-newline": "off",
107
- "vue/valid-template-root": "off",
108
- "vue/block-order": ["warn", { order: [["script", "template"], "style"] }],
109
- "vue/custom-event-name-casing": "off",
110
- ...vue.overrides
111
- }
112
- };
113
- }
114
- if (finalOptions.react) {
115
- const react = typeof finalOptions.react === "object" ? finalOptions.react : {};
116
- finalOptions.react = {
117
- ...react,
118
- overrides: {
119
- "react/prefer-destructuring-assignment": "off",
120
- ...react.overrides
121
- }
122
- };
123
- }
124
- if (finalOptions.typescript) {
125
- const typescript = typeof finalOptions.typescript === "object" ? finalOptions.typescript : {};
126
- finalOptions.typescript = {
127
- ...typescript,
128
- overrides: {
129
- "ts/consistent-type-imports": ["error", {
130
- disallowTypeAnnotations: false,
131
- fixStyle: "inline-type-imports",
132
- prefer: "type-imports"
133
- }],
134
- ...finalOptions.reactnative ? {
135
- "ts/no-require-imports": "off",
136
- "ts/no-use-before-define": "off"
137
- } : void 0,
138
- ...typescript.overrides
139
- }
140
- };
106
+ if (enableVue) configs.push({
107
+ name: "wongxy/vue",
108
+ files: [__antfu_eslint_config.GLOB_VUE],
109
+ rules: resolveRules((0, __antfu_eslint_config.getOverrides)(options, "vue"), {
110
+ "vue/singleline-html-element-content-newline": "off",
111
+ "vue/valid-template-root": "off",
112
+ "vue/block-order": ["warn", { order: [["script", "template"], "style"] }],
113
+ "vue/custom-event-name-casing": "off"
114
+ })
115
+ });
116
+ if (enableReact) configs.push({
117
+ name: "wongxy/react",
118
+ files: [__antfu_eslint_config.GLOB_SRC],
119
+ rules: resolveRules((0, __antfu_eslint_config.getOverrides)(options, "react"), { "react/prefer-destructuring-assignment": "off" })
120
+ });
121
+ if (enableTypeScript) configs.push({
122
+ name: "wongxy/typescript",
123
+ files: [__antfu_eslint_config.GLOB_TS, __antfu_eslint_config.GLOB_TSX],
124
+ rules: resolveRules((0, __antfu_eslint_config.getOverrides)(options, "typescript"), { "ts/consistent-type-imports": ["error", {
125
+ disallowTypeAnnotations: false,
126
+ fixStyle: "inline-type-imports",
127
+ prefer: "type-imports"
128
+ }] })
129
+ });
130
+ if (enableReactNative) configs.push({
131
+ name: "wongxy/reactnative",
132
+ files: [__antfu_eslint_config.GLOB_TS, __antfu_eslint_config.GLOB_TSX],
133
+ rules: resolveRules((0, __antfu_eslint_config.getOverrides)(options, "typescript"), {
134
+ "ts/no-require-imports": "off",
135
+ "ts/no-use-before-define": "off"
136
+ })
137
+ });
138
+ if (enableTailwind) {
139
+ const tw = typeof options.tailwindcss === "object" ? options.tailwindcss : void 0;
140
+ configs.push(tailwindcss(tw));
141
141
  }
142
- if (finalOptions.tailwindcss) userConfigs.splice(0, 0, tailwindcss({ overrides: typeof finalOptions.tailwindcss === "object" ? finalOptions.tailwindcss.overrides : void 0 }));
143
- delete finalOptions.reactnative;
144
- delete finalOptions.tailwindcss;
145
- return (0, __antfu_eslint_config.antfu)(finalOptions, ...userConfigs);
142
+ return (0, __antfu_eslint_config.antfu)(options, ...configs, ...userConfigs);
146
143
  }
147
144
 
148
145
  //#endregion
149
- exports.default = wongxy;
150
- exports.tailwindcss = tailwindcss;
146
+ module.exports = wongxy;