@daopk/eslint-config 0.2.0 → 0.4.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +8254 -6287
  2. package/dist/index.js +217 -201
  3. package/package.json +21 -18
package/dist/index.js CHANGED
@@ -1,231 +1,247 @@
1
- // src/configs/antfu.ts
1
+ import { isPackageExists } from "local-pkg";
2
2
  import antfuPlugin from "eslint-plugin-antfu";
3
+ import gitignore from "eslint-config-flat-gitignore";
4
+ import importX from "eslint-plugin-import-x";
5
+ import unusedImports from "eslint-plugin-unused-imports";
6
+ import nodePlugin from "eslint-plugin-n";
7
+ import perfectionistPlugin from "eslint-plugin-perfectionist";
8
+ import stylisticPlugin from "@stylistic/eslint-plugin";
9
+ import typescriptPlugin from "@typescript-eslint/eslint-plugin";
10
+ import tsParser from "@typescript-eslint/parser";
11
+ import vuePlugin from "eslint-plugin-vue";
12
+ import globals from "globals";
13
+
14
+ //#region src/configs/antfu.ts
3
15
  function antfu() {
4
- return {
5
- name: "daopk/antfu",
6
- plugins: {
7
- antfu: antfuPlugin
8
- },
9
- rules: {
10
- "antfu/consistent-chaining": "error",
11
- "antfu/consistent-list-newline": "error",
12
- "antfu/import-dedupe": "error"
13
- }
14
- };
16
+ return {
17
+ name: "daopk/antfu",
18
+ plugins: { antfu: antfuPlugin },
19
+ rules: {
20
+ "antfu/consistent-chaining": "error",
21
+ "antfu/consistent-list-newline": "error",
22
+ "antfu/import-dedupe": "error"
23
+ }
24
+ };
15
25
  }
16
26
 
17
- // src/configs/builtin.ts
27
+ //#endregion
28
+ //#region src/configs/builtin.ts
18
29
  function builtin() {
19
- return {
20
- name: "daopk/eslint",
21
- rules: {
22
- "eqeqeq": "error",
23
- "no-cond-assign": ["error", "always"],
24
- "no-extra-boolean-cast": "error",
25
- "no-regex-spaces": "error",
26
- "no-unused-labels": "error",
27
- "no-unused-vars": "off",
28
- "object-curly-newline": "off",
29
- "yoda": ["error", "never"]
30
- }
31
- };
30
+ return {
31
+ name: "daopk/eslint",
32
+ rules: {
33
+ "eqeqeq": "error",
34
+ "no-cond-assign": ["error", "always"],
35
+ "no-extra-boolean-cast": "error",
36
+ "no-regex-spaces": "error",
37
+ "no-unused-labels": "error",
38
+ "no-unused-vars": "off",
39
+ "yoda": ["error", "never"]
40
+ }
41
+ };
32
42
  }
33
43
 
34
- // src/configs/ignores.ts
35
- import gitignore from "eslint-config-flat-gitignore";
44
+ //#endregion
45
+ //#region src/configs/ignores.ts
36
46
  function ignores(userIgnores = []) {
37
- return {
38
- name: "daopk/ignores",
39
- ignores: [
40
- ...gitignore().ignores,
41
- ...userIgnores ?? []
42
- ]
43
- };
47
+ return {
48
+ name: "daopk/ignores",
49
+ ignores: [...gitignore().ignores, ...userIgnores ?? []]
50
+ };
44
51
  }
45
52
 
46
- // src/configs/imports.ts
47
- import importX from "eslint-plugin-import-x";
48
- import unusedImports from "eslint-plugin-unused-imports";
53
+ //#endregion
54
+ //#region src/configs/imports.ts
49
55
  function imports() {
50
- return {
51
- name: "daopk/imports",
52
- plugins: {
53
- "import": importX,
54
- "unused-imports": unusedImports
55
- },
56
- rules: {
57
- "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
58
- "import/first": "error",
59
- "import/no-duplicates": "error",
60
- "import/no-mutable-exports": "error",
61
- "import/no-named-default": "error",
62
- "import/no-self-import": "error",
63
- "import/no-webpack-loader-syntax": "error",
64
- "unused-imports/no-unused-imports": "error",
65
- "unused-imports/no-unused-vars": [
66
- "warn",
67
- {
68
- args: "after-used",
69
- argsIgnorePattern: "^_",
70
- vars: "all",
71
- varsIgnorePattern: "^_"
72
- }
73
- ]
74
- }
75
- };
56
+ return {
57
+ name: "daopk/imports",
58
+ plugins: {
59
+ "import": importX,
60
+ "unused-imports": unusedImports
61
+ },
62
+ rules: {
63
+ "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
64
+ "import/first": "error",
65
+ "import/no-duplicates": "error",
66
+ "import/no-mutable-exports": "error",
67
+ "import/no-named-default": "error",
68
+ "import/no-self-import": "error",
69
+ "import/no-webpack-loader-syntax": "error",
70
+ "unused-imports/no-unused-imports": "error",
71
+ "unused-imports/no-unused-vars": ["warn", {
72
+ args: "after-used",
73
+ argsIgnorePattern: "^_",
74
+ vars: "all",
75
+ varsIgnorePattern: "^_"
76
+ }]
77
+ }
78
+ };
76
79
  }
77
80
 
78
- // src/configs/node.ts
79
- import nodePlugin from "eslint-plugin-n";
81
+ //#endregion
82
+ //#region src/configs/node.ts
80
83
  function node() {
81
- return {
82
- name: "daopk/node",
83
- plugins: {
84
- node: nodePlugin
85
- },
86
- rules: {
87
- "node/prefer-node-protocol": "error"
88
- }
89
- };
84
+ return {
85
+ name: "daopk/node",
86
+ plugins: { node: nodePlugin },
87
+ rules: { "node/prefer-node-protocol": "error" }
88
+ };
90
89
  }
91
90
 
92
- // src/configs/perfectionist.ts
93
- import perfectionistPlugin from "eslint-plugin-perfectionist";
91
+ //#endregion
92
+ //#region src/configs/perfectionist.ts
94
93
  function perfectionist() {
95
- return {
96
- name: "daopk/perfectionist",
97
- plugins: {
98
- perfectionist: perfectionistPlugin
99
- },
100
- rules: {
101
- "perfectionist/sort-exports": ["error", { order: "asc", type: "natural" }],
102
- "perfectionist/sort-imports": ["error", {
103
- groups: [
104
- "type",
105
- ["parent-type", "sibling-type", "index-type", "internal-type"],
106
- "builtin",
107
- "external",
108
- "internal",
109
- ["parent", "sibling", "index"],
110
- "side-effect",
111
- "object",
112
- "unknown"
113
- ],
114
- newlinesBetween: "ignore",
115
- order: "asc",
116
- type: "natural"
117
- }],
118
- "perfectionist/sort-named-exports": ["error", { order: "asc", type: "natural" }],
119
- "perfectionist/sort-named-imports": ["error", { order: "asc", type: "natural" }]
120
- }
121
- };
94
+ return {
95
+ name: "daopk/perfectionist",
96
+ plugins: { perfectionist: perfectionistPlugin },
97
+ rules: {
98
+ "perfectionist/sort-exports": ["error", {
99
+ order: "asc",
100
+ type: "natural"
101
+ }],
102
+ "perfectionist/sort-imports": ["error", {
103
+ groups: [
104
+ "type",
105
+ [
106
+ "parent-type",
107
+ "sibling-type",
108
+ "index-type",
109
+ "internal-type"
110
+ ],
111
+ "builtin",
112
+ "external",
113
+ "internal",
114
+ [
115
+ "parent",
116
+ "sibling",
117
+ "index"
118
+ ],
119
+ "side-effect",
120
+ "object",
121
+ "unknown"
122
+ ],
123
+ newlinesBetween: "ignore",
124
+ order: "asc",
125
+ type: "natural"
126
+ }],
127
+ "perfectionist/sort-named-exports": ["error", {
128
+ order: "asc",
129
+ type: "natural"
130
+ }],
131
+ "perfectionist/sort-named-imports": ["error", {
132
+ order: "asc",
133
+ type: "natural"
134
+ }]
135
+ }
136
+ };
122
137
  }
123
138
 
124
- // src/configs/stylistic.ts
125
- import stylisticPlugin from "@stylistic/eslint-plugin";
139
+ //#endregion
140
+ //#region src/configs/stylistic.ts
126
141
  function stylistic(options = {}) {
127
- const stylisticConfig = stylisticPlugin.configs.customize({
128
- arrowParens: options.arrowParens ?? true,
129
- blockSpacing: options.blockSpacing,
130
- braceStyle: options.braceStyle,
131
- commaDangle: options.commaDangle,
132
- indent: options.indent ?? 4,
133
- jsx: options.jsx,
134
- pluginName: "stylistic",
135
- quoteProps: options.quoteProps,
136
- quotes: options.quotes ?? "single",
137
- semi: options.semi ?? false
138
- });
139
- return {
140
- name: "daopk/stylistic",
141
- plugins: {
142
- stylistic: {
143
- rules: stylisticPlugin.rules
144
- }
145
- },
146
- rules: {
147
- ...stylisticConfig.rules,
148
- "stylistic/array-bracket-newline": ["error", "consistent"],
149
- "stylistic/array-element-newline": ["error", "consistent"]
150
- }
151
- };
142
+ const stylisticConfig = stylisticPlugin.configs.customize({
143
+ arrowParens: options.arrowParens ?? true,
144
+ blockSpacing: options.blockSpacing,
145
+ braceStyle: options.braceStyle,
146
+ commaDangle: options.commaDangle,
147
+ indent: options.indent ?? 4,
148
+ jsx: options.jsx,
149
+ pluginName: "stylistic",
150
+ quoteProps: options.quoteProps,
151
+ quotes: options.quotes ?? "single",
152
+ semi: options.semi ?? false
153
+ });
154
+ return {
155
+ name: "daopk/stylistic",
156
+ plugins: { stylistic: { rules: stylisticPlugin.rules } },
157
+ rules: {
158
+ ...stylisticConfig.rules,
159
+ "stylistic/array-bracket-newline": ["error", "consistent"],
160
+ "stylistic/array-element-newline": ["error", "consistent"]
161
+ }
162
+ };
152
163
  }
153
164
 
154
- // src/configs/typescript.ts
155
- import typescriptPlugin from "@typescript-eslint/eslint-plugin";
156
- import tsParser from "@typescript-eslint/parser";
165
+ //#endregion
166
+ //#region src/configs/typescript.ts
157
167
  function typescript({ rules } = {}) {
158
- return {
159
- files: ["**/*.ts"],
160
- languageOptions: {
161
- ecmaVersion: "latest",
162
- parser: tsParser,
163
- sourceType: "module"
164
- },
165
- name: "daopk/typescript",
166
- plugins: {
167
- typescript: typescriptPlugin
168
- },
169
- rules: {
170
- "typescript/consistent-type-imports": ["error", {
171
- disallowTypeAnnotations: false,
172
- fixStyle: "separate-type-imports",
173
- prefer: "type-imports"
174
- }],
175
- "typescript/no-unused-vars": "off",
176
- ...rules
177
- }
178
- };
168
+ return {
169
+ files: ["**/*.ts"],
170
+ languageOptions: {
171
+ ecmaVersion: "latest",
172
+ parser: tsParser,
173
+ sourceType: "module"
174
+ },
175
+ name: "daopk/typescript",
176
+ plugins: { typescript: typescriptPlugin },
177
+ rules: {
178
+ "typescript/consistent-type-imports": ["error", {
179
+ disallowTypeAnnotations: false,
180
+ fixStyle: "separate-type-imports",
181
+ prefer: "type-imports"
182
+ }],
183
+ "typescript/no-unused-vars": "off",
184
+ ...rules
185
+ }
186
+ };
179
187
  }
180
188
 
181
- // src/presets/nestjs.ts
189
+ //#endregion
190
+ //#region src/configs/vue.ts
191
+ function vue() {
192
+ return [...vuePlugin.configs["flat/recommended"], {
193
+ name: "daopk/vue",
194
+ files: ["**/*.vue"],
195
+ languageOptions: {
196
+ ecmaVersion: "latest",
197
+ sourceType: "module",
198
+ globals: globals.browser,
199
+ parserOptions: { parser: tsParser }
200
+ }
201
+ }];
202
+ }
203
+
204
+ //#endregion
205
+ //#region src/presets/nestjs.ts
182
206
  function presetNestjs(options = {}) {
183
- return [
184
- ignores(options.ignores),
185
- builtin(),
186
- stylistic({
187
- semi: true,
188
- jsx: false,
189
- ...options.stylistic
190
- }),
191
- typescript({
192
- rules: {
193
- "typescript/consistent-type-imports": ["warn", { prefer: "no-type-imports" }]
194
- }
195
- }),
196
- imports(),
197
- antfu(),
198
- node(),
199
- perfectionist()
200
- ];
207
+ return [
208
+ ignores(options.ignores),
209
+ builtin(),
210
+ stylistic({
211
+ semi: true,
212
+ jsx: false,
213
+ ...options.stylistic
214
+ }),
215
+ typescript({ rules: { "typescript/consistent-type-imports": ["warn", { prefer: "no-type-imports" }] } }),
216
+ imports(),
217
+ antfu(),
218
+ node(),
219
+ perfectionist()
220
+ ];
201
221
  }
202
222
 
203
- // src/index.ts
223
+ //#endregion
224
+ //#region src/index.ts
204
225
  function daopk(options = {}, ...userConfigs) {
205
- const configs = [
206
- ignores(options.ignores),
207
- builtin(),
208
- stylistic(options.stylistic),
209
- typescript(),
210
- imports(),
211
- antfu(),
212
- node(),
213
- perfectionist()
214
- ];
215
- if (options.rules) {
216
- configs.push({
217
- name: "daopk/rules",
218
- rules: {
219
- ...options.rules
220
- }
221
- });
222
- }
223
- if (userConfigs.length > 0) {
224
- configs.push(...userConfigs);
225
- }
226
- return configs;
226
+ const { vue: enableVue = isPackageExists("vue") } = options;
227
+ const configs = [
228
+ ignores(options.ignores),
229
+ builtin(),
230
+ stylistic(options.stylistic),
231
+ typescript(),
232
+ imports(),
233
+ antfu(),
234
+ node(),
235
+ perfectionist()
236
+ ];
237
+ if (enableVue) configs.push(...vue());
238
+ if (options.rules) configs.push({
239
+ name: "daopk/rules",
240
+ rules: { ...options.rules }
241
+ });
242
+ if (userConfigs.length > 0) configs.push(...userConfigs);
243
+ return configs;
227
244
  }
228
- export {
229
- daopk as default,
230
- presetNestjs
231
- };
245
+
246
+ //#endregion
247
+ export { daopk as default, presetNestjs };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@daopk/eslint-config",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.4.0",
5
5
  "license": "ISC",
6
6
  "repository": "github:daopk/eslint-config",
7
7
  "exports": {
@@ -13,31 +13,34 @@
13
13
  "dist"
14
14
  ],
15
15
  "dependencies": {
16
- "@stylistic/eslint-plugin": "^4.2.0",
17
- "@typescript-eslint/eslint-plugin": "^8.32.0",
18
- "@typescript-eslint/parser": "^8.32.0",
16
+ "@stylistic/eslint-plugin": "^5.5.0",
17
+ "@typescript-eslint/eslint-plugin": "^8.46.3",
18
+ "@typescript-eslint/parser": "^8.46.3",
19
19
  "eslint-config-flat-gitignore": "^2.1.0",
20
20
  "eslint-plugin-antfu": "^3.1.1",
21
- "eslint-plugin-import-x": "^4.11.0",
22
- "eslint-plugin-n": "^17.17.0",
23
- "eslint-plugin-perfectionist": "^4.12.3",
24
- "eslint-plugin-unused-imports": "^4.1.4"
21
+ "eslint-plugin-import-x": "^4.16.1",
22
+ "eslint-plugin-n": "^17.23.1",
23
+ "eslint-plugin-perfectionist": "^4.15.1",
24
+ "eslint-plugin-unused-imports": "^4.3.0",
25
+ "eslint-plugin-vue": "^10.5.1",
26
+ "globals": "^16.5.0",
27
+ "local-pkg": "^1.1.2"
25
28
  },
26
29
  "devDependencies": {
27
- "@eslint/config-inspector": "^1.0.2",
28
- "@types/node": "^22.15.16",
29
- "bumpp": "^10.1.0",
30
- "eslint": "^9.26.0",
31
- "eslint-typegen": "^2.1.0",
32
- "jiti": "^2.4.2",
33
- "tsup": "^8.4.0",
34
- "tsx": "^4.19.4",
35
- "typescript": "^5.8.3"
30
+ "@eslint/config-inspector": "^1.3.0",
31
+ "@types/node": "^24.10.0",
32
+ "bumpp": "^10.3.1",
33
+ "eslint": "^9.39.1",
34
+ "eslint-typegen": "^2.3.0",
35
+ "jiti": "^2.6.1",
36
+ "tsdown": "^0.15.12",
37
+ "tsx": "^4.20.6",
38
+ "typescript": "^5.9.3"
36
39
  },
37
40
  "scripts": {
38
41
  "dev": "eslint-config-inspector",
39
42
  "typegen": "tsx scripts/typegen.ts",
40
- "build": "pnpm typegen && tsup",
43
+ "build": "pnpm typegen && tsdown",
41
44
  "build:inspector": "pnpm build && eslint-config-inspector build",
42
45
  "lint": "eslint .",
43
46
  "release": "bumpp && pnpm publish"