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