@curev/eslint-config 0.3.0 → 0.3.2
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/chunk-TMQW6NVO.js +69 -0
- package/dist/dist-LIAOFFCU.js +226696 -0
- package/dist/index.cjs +228966 -0
- package/dist/index.d.cts +516 -0
- package/dist/index.d.ts +516 -0
- package/dist/index.js +2155 -0
- package/package.json +8 -5
- package/.eslintignore +0 -1
- package/.github/workflows/release.yml +0 -37
- package/.vscode/settings.json +0 -36
- package/CHANGELOG.md +0 -740
- package/eslint.config.ts +0 -3
- package/fixtures/input/css.css +0 -10
- package/fixtures/input/html.html +0 -17
- package/fixtures/input/javascript.js +0 -69
- package/fixtures/input/jsx.jsx +0 -27
- package/fixtures/input/markdown.md +0 -34
- package/fixtures/input/svelte.svelte +0 -8
- package/fixtures/input/toml.toml +0 -23
- package/fixtures/input/tsx.tsx +0 -32
- package/fixtures/input/typescript.ts +0 -84
- package/fixtures/input/vue-ts.vue +0 -35
- package/fixtures/input/vue.vue +0 -27
- package/fixtures/output/all/javascript.js +0 -72
- package/fixtures/output/all/jsx.jsx +0 -26
- package/fixtures/output/all/markdown.md +0 -33
- package/fixtures/output/all/svelte.svelte +0 -8
- package/fixtures/output/all/toml.toml +0 -23
- package/fixtures/output/all/tsx.tsx +0 -32
- package/fixtures/output/all/typescript.ts +0 -83
- package/fixtures/output/all/vue-ts.vue +0 -35
- package/fixtures/output/all/vue.vue +0 -24
- package/fixtures/output/js/javascript.js +0 -72
- package/fixtures/output/js/markdown.md +0 -33
- package/fixtures/output/js/toml.toml +0 -23
- package/fixtures/output/no-markdown-with-formatters/javascript.js +0 -72
- package/fixtures/output/no-markdown-with-formatters/jsx.jsx +0 -24
- package/fixtures/output/no-markdown-with-formatters/markdown.md +0 -33
- package/fixtures/output/no-markdown-with-formatters/toml.toml +0 -23
- package/fixtures/output/no-markdown-with-formatters/tsx.tsx +0 -23
- package/fixtures/output/no-markdown-with-formatters/typescript.ts +0 -83
- package/fixtures/output/no-style/javascript.js +0 -72
- package/fixtures/output/no-style/jsx.jsx +0 -21
- package/fixtures/output/no-style/toml.toml +0 -23
- package/fixtures/output/no-style/typescript.ts +0 -80
- package/fixtures/output/no-style/vue-ts.vue +0 -35
- package/fixtures/output/no-style/vue.vue +0 -24
- package/fixtures/output/tab-double-quotes/javascript.js +0 -72
- package/fixtures/output/tab-double-quotes/jsx.jsx +0 -26
- package/fixtures/output/tab-double-quotes/markdown.md +0 -33
- package/fixtures/output/tab-double-quotes/toml.toml +0 -23
- package/fixtures/output/tab-double-quotes/tsx.tsx +0 -32
- package/fixtures/output/tab-double-quotes/typescript.ts +0 -83
- package/fixtures/output/tab-double-quotes/vue-ts.vue +0 -35
- package/fixtures/output/tab-double-quotes/vue.vue +0 -24
- package/fixtures/output/ts-override/javascript.js +0 -72
- package/fixtures/output/ts-override/jsx.jsx +0 -26
- package/fixtures/output/ts-override/markdown.md +0 -33
- package/fixtures/output/ts-override/toml.toml +0 -23
- package/fixtures/output/ts-override/tsx.tsx +0 -32
- package/fixtures/output/ts-override/typescript.ts +0 -83
- package/fixtures/output/ts-override/vue-ts.vue +0 -35
- package/fixtures/output/ts-override/vue.vue +0 -24
- package/fixtures/output/with-formatters/css.css +0 -11
- package/fixtures/output/with-formatters/html.html +0 -28
- package/fixtures/output/with-formatters/javascript.js +0 -72
- package/fixtures/output/with-formatters/jsx.jsx +0 -26
- package/fixtures/output/with-formatters/markdown.md +0 -34
- package/fixtures/output/with-formatters/toml.toml +0 -23
- package/fixtures/output/with-formatters/tsx.tsx +0 -32
- package/fixtures/output/with-formatters/typescript.ts +0 -83
- package/fixtures/output/with-formatters/vue-ts.vue +0 -38
- package/fixtures/output/with-formatters/vue.vue +0 -24
- package/src/configs/comments.ts +0 -19
- package/src/configs/formatters.ts +0 -187
- package/src/configs/ignores.ts +0 -10
- package/src/configs/imports.ts +0 -46
- package/src/configs/index.ts +0 -21
- package/src/configs/javascript.ts +0 -277
- package/src/configs/jsdoc.ts +0 -41
- package/src/configs/jsonc.ts +0 -86
- package/src/configs/markdown.ts +0 -110
- package/src/configs/node.ts +0 -24
- package/src/configs/perfectionist.ts +0 -18
- package/src/configs/react.ts +0 -111
- package/src/configs/sort.ts +0 -223
- package/src/configs/stylistic.ts +0 -52
- package/src/configs/svelte.ts +0 -107
- package/src/configs/test.ts +0 -54
- package/src/configs/toml.ts +0 -72
- package/src/configs/typescript.ts +0 -171
- package/src/configs/unicorn.ts +0 -41
- package/src/configs/unocss.ts +0 -43
- package/src/configs/vue.ts +0 -170
- package/src/configs/yaml.ts +0 -72
- package/src/factory.ts +0 -255
- package/src/globs.ts +0 -81
- package/src/index.ts +0 -9
- package/src/plugins.ts +0 -10
- package/src/stub.d.ts +0 -3
- package/src/types.ts +0 -364
- package/src/utils.ts +0 -76
- package/src/vender/prettier-types.ts +0 -136
- package/test/cli.spec.ts +0 -90
- package/test/fixtures.test.ts +0 -127
- package/tsconfig.json +0 -17
- package/tsup.config.ts +0 -8
package/src/types.ts
DELETED
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
import type { FlatGitignoreOptions } from "eslint-config-flat-gitignore";
|
|
2
|
-
import type { ParserOptions } from "@typescript-eslint/parser";
|
|
3
|
-
import type { Options as VueBlocksOptions } from "eslint-processor-vue-blocks";
|
|
4
|
-
import type { Linter } from "eslint";
|
|
5
|
-
import type {
|
|
6
|
-
EslintCommentsRules,
|
|
7
|
-
EslintRules,
|
|
8
|
-
FlatESLintConfigItem,
|
|
9
|
-
ImportRules,
|
|
10
|
-
JsoncRules,
|
|
11
|
-
MergeIntersection,
|
|
12
|
-
NRules,
|
|
13
|
-
Prefix,
|
|
14
|
-
ReactHooksRules,
|
|
15
|
-
ReactRules,
|
|
16
|
-
RenamePrefix,
|
|
17
|
-
RuleConfig,
|
|
18
|
-
VitestRules,
|
|
19
|
-
VueRules,
|
|
20
|
-
YmlRules
|
|
21
|
-
} from "@antfu/eslint-define-config";
|
|
22
|
-
import type { RuleOptions as JSDocRules } from "@eslint-types/jsdoc/types";
|
|
23
|
-
import type { RuleOptions as TypeScriptRules } from "@eslint-types/typescript-eslint/types";
|
|
24
|
-
import type { RuleOptions as UnicornRules } from "@eslint-types/unicorn/types";
|
|
25
|
-
import type { Rules as AntfuRules } from "eslint-plugin-antfu";
|
|
26
|
-
import type { StylisticCustomizeOptions, UnprefixedRuleOptions as StylisticRules } from "@stylistic/eslint-plugin";
|
|
27
|
-
import type { VendoredPrettierOptions } from "./vender/prettier-types";
|
|
28
|
-
|
|
29
|
-
export type WrapRuleConfig<T extends { [key: string]: any }> = {
|
|
30
|
-
[K in keyof T]: T[K] extends RuleConfig ? T[K] : RuleConfig<T[K]>
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type Awaitable<T> = T | Promise<T>;
|
|
34
|
-
|
|
35
|
-
export type Rules = WrapRuleConfig<
|
|
36
|
-
MergeIntersection<
|
|
37
|
-
RenamePrefix<TypeScriptRules, "@typescript-eslint/", "ts/"> &
|
|
38
|
-
RenamePrefix<VitestRules, "vitest/", "test/"> &
|
|
39
|
-
RenamePrefix<YmlRules, "yml/", "yaml/"> &
|
|
40
|
-
RenamePrefix<NRules, "n/", "node/"> &
|
|
41
|
-
Prefix<StylisticRules, "style/"> &
|
|
42
|
-
Prefix<AntfuRules, "antfu/"> &
|
|
43
|
-
ReactHooksRules &
|
|
44
|
-
ReactRules &
|
|
45
|
-
JSDocRules &
|
|
46
|
-
ImportRules &
|
|
47
|
-
EslintRules &
|
|
48
|
-
JsoncRules &
|
|
49
|
-
VueRules &
|
|
50
|
-
UnicornRules &
|
|
51
|
-
EslintCommentsRules &
|
|
52
|
-
// TODO: TOML rules
|
|
53
|
-
{
|
|
54
|
-
"test/no-only-tests": RuleConfig<[]>;
|
|
55
|
-
}
|
|
56
|
-
>
|
|
57
|
-
>;
|
|
58
|
-
|
|
59
|
-
export type FlatConfigItem = Omit<FlatESLintConfigItem<Rules, false>, "plugins"> & {
|
|
60
|
-
/**
|
|
61
|
-
* Custom name of each config item
|
|
62
|
-
*/
|
|
63
|
-
name?: string;
|
|
64
|
-
|
|
65
|
-
// Relax plugins type limitation, as most of the plugins did not have correct type info yet.
|
|
66
|
-
/**
|
|
67
|
-
* An object containing a name-value mapping of plugin names to plugin objects. When `files` is specified, these plugins are only available to the matching files.
|
|
68
|
-
*
|
|
69
|
-
* @see [Using plugins in your configuration](https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#using-plugins-in-your-configuration)
|
|
70
|
-
*/
|
|
71
|
-
plugins?: Record<string, any>;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export type UserConfigItem = FlatConfigItem | Linter.FlatConfig;
|
|
75
|
-
|
|
76
|
-
export interface OptionsFiles {
|
|
77
|
-
/**
|
|
78
|
-
* Override the `files` option to provide custom globs.
|
|
79
|
-
*/
|
|
80
|
-
files?: string[];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export interface OptionsVue extends OptionsOverrides {
|
|
84
|
-
/**
|
|
85
|
-
* Create virtual files for Vue SFC blocks to enable linting.
|
|
86
|
-
*
|
|
87
|
-
* @see https://github.com/antfu/eslint-processor-vue-blocks
|
|
88
|
-
* @default true
|
|
89
|
-
*/
|
|
90
|
-
sfcBlocks?: boolean | VueBlocksOptions;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Vue version. Apply different rules set from `eslint-plugin-vue`.
|
|
94
|
-
*
|
|
95
|
-
* @default 3
|
|
96
|
-
*/
|
|
97
|
-
vueVersion?: 2 | 3;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export type OptionsTypescript =
|
|
101
|
-
(OptionsTypeScriptWithTypes & OptionsOverrides)
|
|
102
|
-
| (OptionsTypeScriptParserOptions & OptionsOverrides);
|
|
103
|
-
|
|
104
|
-
export interface OptionsFormatters {
|
|
105
|
-
/**
|
|
106
|
-
* Enable formatting support for CSS, Less, Sass, and SCSS.
|
|
107
|
-
*
|
|
108
|
-
* Currently only support Prettier.
|
|
109
|
-
*/
|
|
110
|
-
css?: "prettier" | boolean;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Enable formatting support for HTML.
|
|
114
|
-
*
|
|
115
|
-
* Currently only support Prettier.
|
|
116
|
-
*/
|
|
117
|
-
html?: "prettier" | boolean;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Enable formatting support for Markdown.
|
|
121
|
-
*
|
|
122
|
-
* Support both Prettier and dprint.
|
|
123
|
-
*
|
|
124
|
-
* When set to `true`, it will use Prettier.
|
|
125
|
-
*/
|
|
126
|
-
markdown?: "prettier" | "dprint" | boolean;
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Enable formatting support for GraphQL.
|
|
130
|
-
*/
|
|
131
|
-
graphql?: "prettier" | boolean;
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Custom options for Prettier.
|
|
135
|
-
*
|
|
136
|
-
* By default it's controlled by our own config.
|
|
137
|
-
*/
|
|
138
|
-
prettierOptions?: VendoredPrettierOptions;
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Custom options for dprint.
|
|
142
|
-
*
|
|
143
|
-
* By default it's controlled by our own config.
|
|
144
|
-
*/
|
|
145
|
-
dprintOptions?: boolean;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export interface OptionsComponentExts {
|
|
149
|
-
/**
|
|
150
|
-
* Additional extensions for components.
|
|
151
|
-
*
|
|
152
|
-
* @example ['vue']
|
|
153
|
-
* @default []
|
|
154
|
-
*/
|
|
155
|
-
componentExts?: string[];
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export interface OptionsTypeScriptParserOptions {
|
|
159
|
-
/**
|
|
160
|
-
* Additional parser options for TypeScript.
|
|
161
|
-
*/
|
|
162
|
-
parserOptions?: Partial<ParserOptions>;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Glob patterns for files that should be type aware.
|
|
166
|
-
* @default ['**\/*.{ts,tsx}']
|
|
167
|
-
*/
|
|
168
|
-
filesTypeAware?: string[];
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export interface OptionsTypeScriptWithTypes {
|
|
172
|
-
/**
|
|
173
|
-
* When this options is provided, type aware rules will be enabled.
|
|
174
|
-
* @see https://typescript-eslint.io/linting/typed-linting/
|
|
175
|
-
*/
|
|
176
|
-
tsconfigPath?: string | string[];
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export interface OptionsHasTypeScript {
|
|
180
|
-
typescript?: boolean;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export interface OptionsStylistic {
|
|
184
|
-
stylistic?: boolean | StylisticConfig;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export interface StylisticConfig extends StylisticCustomizeOptions {
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export interface OptionsOverrides {
|
|
191
|
-
overrides?: FlatConfigItem["rules"];
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export interface OptionsIsInEditor {
|
|
195
|
-
isInEditor?: boolean;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export interface OptionsUnoCSS extends OptionsOverrides {
|
|
199
|
-
/**
|
|
200
|
-
* Enable attributify support.
|
|
201
|
-
* @default true
|
|
202
|
-
*/
|
|
203
|
-
attributify?: boolean;
|
|
204
|
-
/**
|
|
205
|
-
* Enable strict mode by throwing errors about blocklisted classes.
|
|
206
|
-
* @default false
|
|
207
|
-
*/
|
|
208
|
-
strict?: boolean;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export interface OptionsConfig extends OptionsComponentExts {
|
|
212
|
-
/**
|
|
213
|
-
* Enable gitignore support.
|
|
214
|
-
*
|
|
215
|
-
* Passing an object to configure the options.
|
|
216
|
-
*
|
|
217
|
-
* @see https://github.com/antfu/eslint-config-flat-gitignore
|
|
218
|
-
* @default true
|
|
219
|
-
*/
|
|
220
|
-
gitignore?: boolean | FlatGitignoreOptions;
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Core rules. Can't be disabled.
|
|
224
|
-
*/
|
|
225
|
-
javascript?: OptionsOverrides;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Enable TypeScript support.
|
|
229
|
-
*
|
|
230
|
-
* Passing an object to enable TypeScript Language Server support.
|
|
231
|
-
*
|
|
232
|
-
* @default auto-detect based on the dependencies
|
|
233
|
-
*/
|
|
234
|
-
typescript?: boolean | OptionsTypescript;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Enable JSX related rules.
|
|
238
|
-
*
|
|
239
|
-
* Currently only stylistic rules are included.
|
|
240
|
-
*
|
|
241
|
-
* @default true
|
|
242
|
-
*/
|
|
243
|
-
jsx?: boolean;
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Enable test support.
|
|
247
|
-
*
|
|
248
|
-
* @default true
|
|
249
|
-
*/
|
|
250
|
-
test?: boolean | OptionsOverrides;
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Enable Vue support.
|
|
254
|
-
*
|
|
255
|
-
* @default auto-detect based on the dependencies
|
|
256
|
-
*/
|
|
257
|
-
vue?: boolean | OptionsVue;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Enable JSONC support.
|
|
261
|
-
*
|
|
262
|
-
* @default true
|
|
263
|
-
*/
|
|
264
|
-
jsonc?: boolean | OptionsOverrides;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Enable YAML support.
|
|
268
|
-
*
|
|
269
|
-
* @default true
|
|
270
|
-
*/
|
|
271
|
-
yaml?: boolean | OptionsOverrides;
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Enable TOML support.
|
|
275
|
-
*
|
|
276
|
-
* @default true
|
|
277
|
-
*/
|
|
278
|
-
toml?: boolean | OptionsOverrides;
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Enable linting for **code snippets** in Markdown.
|
|
282
|
-
*
|
|
283
|
-
* For formatting Markdown content, enable also `formatters.markdown`.
|
|
284
|
-
*
|
|
285
|
-
* @default true
|
|
286
|
-
*/
|
|
287
|
-
markdown?: boolean | OptionsOverrides;
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Enable stylistic rules.
|
|
291
|
-
*
|
|
292
|
-
* @default true
|
|
293
|
-
*/
|
|
294
|
-
stylistic?: boolean | (StylisticConfig & OptionsOverrides);
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Enable react rules.
|
|
298
|
-
*
|
|
299
|
-
* Requires installing:
|
|
300
|
-
* - `eslint-plugin-react`
|
|
301
|
-
* - `eslint-plugin-react-hooks`
|
|
302
|
-
* - `eslint-plugin-react-refresh`
|
|
303
|
-
*
|
|
304
|
-
* @default false
|
|
305
|
-
*/
|
|
306
|
-
react?: boolean | OptionsOverrides;
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Enable svelte rules.
|
|
310
|
-
*
|
|
311
|
-
* Requires installing:
|
|
312
|
-
* - `eslint-plugin-svelte`
|
|
313
|
-
*
|
|
314
|
-
* @default false
|
|
315
|
-
*/
|
|
316
|
-
svelte?: boolean;
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Enable unocss rules.
|
|
320
|
-
*
|
|
321
|
-
* Requires installing:
|
|
322
|
-
* - `@unocss/eslint-plugin`
|
|
323
|
-
*
|
|
324
|
-
* @default false
|
|
325
|
-
*/
|
|
326
|
-
unocss?: boolean | OptionsUnoCSS;
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Use external formatters to format files.
|
|
330
|
-
*
|
|
331
|
-
* Requires installing:
|
|
332
|
-
* - `eslint-plugin-format`
|
|
333
|
-
*
|
|
334
|
-
* When set to `true`, it will enable all formatters.
|
|
335
|
-
*
|
|
336
|
-
* @default false
|
|
337
|
-
*/
|
|
338
|
-
formatters?: boolean | OptionsFormatters;
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Control to disable some rules in editors.
|
|
342
|
-
* @default auto-detect based on the process.env
|
|
343
|
-
*/
|
|
344
|
-
isInEditor?: boolean;
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Provide overrides for rules for each integration.
|
|
348
|
-
*
|
|
349
|
-
* @deprecated use `overrides` option in each integration key instead
|
|
350
|
-
*/
|
|
351
|
-
overrides?: {
|
|
352
|
-
stylistic?: FlatConfigItem["rules"];
|
|
353
|
-
javascript?: FlatConfigItem["rules"];
|
|
354
|
-
typescript?: FlatConfigItem["rules"];
|
|
355
|
-
test?: FlatConfigItem["rules"];
|
|
356
|
-
vue?: FlatConfigItem["rules"];
|
|
357
|
-
jsonc?: FlatConfigItem["rules"];
|
|
358
|
-
markdown?: FlatConfigItem["rules"];
|
|
359
|
-
yaml?: FlatConfigItem["rules"];
|
|
360
|
-
toml?: FlatConfigItem["rules"];
|
|
361
|
-
react?: FlatConfigItem["rules"];
|
|
362
|
-
svelte?: FlatConfigItem["rules"];
|
|
363
|
-
};
|
|
364
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
import { isPackageExists } from "local-pkg";
|
|
3
|
-
import type { Awaitable, UserConfigItem } from "./types";
|
|
4
|
-
|
|
5
|
-
export const parserPlain = {
|
|
6
|
-
meta: {
|
|
7
|
-
name: "parser-plain"
|
|
8
|
-
},
|
|
9
|
-
parseForESLint: (code: string) => ({
|
|
10
|
-
ast: {
|
|
11
|
-
body: [],
|
|
12
|
-
comments: [],
|
|
13
|
-
loc: { end: code.length, start: 0 },
|
|
14
|
-
range: [0, code.length],
|
|
15
|
-
tokens: [],
|
|
16
|
-
type: "Program"
|
|
17
|
-
},
|
|
18
|
-
scopeManager: null,
|
|
19
|
-
services: { isPlain: true },
|
|
20
|
-
visitorKeys: {
|
|
21
|
-
Program: []
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Combine array and non-array configs into a single array.
|
|
28
|
-
*/
|
|
29
|
-
export async function combine(...configs: Awaitable<UserConfigItem | UserConfigItem[]>[]): Promise<UserConfigItem[]> {
|
|
30
|
-
const resolved = await Promise.all(configs);
|
|
31
|
-
return resolved.flat();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function renameRules(rules: Record<string, any>, from: string, to: string) {
|
|
35
|
-
return Object.fromEntries(
|
|
36
|
-
Object.entries(rules)
|
|
37
|
-
.map(([key, value]) => {
|
|
38
|
-
if (key.startsWith(from)) {
|
|
39
|
-
return [to + key.slice(from.length), value];
|
|
40
|
-
}
|
|
41
|
-
return [key, value];
|
|
42
|
-
})
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function toArray<T>(value: T | T[]): T[] {
|
|
47
|
-
return Array.isArray(value) ? value : [value];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function interopDefault<T>(m: Awaitable<T>): Promise<T extends { default: infer U } ? U : T> {
|
|
51
|
-
const resolved = await m;
|
|
52
|
-
return (resolved as any).default || resolved;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function ensurePackages(packages: string[]) {
|
|
56
|
-
if (process.env.CI || process.stdout.isTTY === false) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const nonExistingPackages = packages.filter(i => !isPackageExists(i));
|
|
61
|
-
if (nonExistingPackages.length === 0) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const { default: prompts } = await import("prompts");
|
|
66
|
-
const { result } = await prompts([
|
|
67
|
-
{
|
|
68
|
-
message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?`,
|
|
69
|
-
name: "result",
|
|
70
|
-
type: "confirm"
|
|
71
|
-
}
|
|
72
|
-
]);
|
|
73
|
-
if (result) {
|
|
74
|
-
await import("@antfu/install-pkg").then(i => i.installPackage(nonExistingPackages, { dev: true }));
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vendor types from Prettier so we don't rely on the dependency.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export type VendoredPrettierOptions = Partial<VendoredPrettierOptionsRequired>;
|
|
6
|
-
|
|
7
|
-
export interface VendoredPrettierOptionsRequired {
|
|
8
|
-
/**
|
|
9
|
-
* Specify the line length that the printer will wrap on.
|
|
10
|
-
* @default 120
|
|
11
|
-
*/
|
|
12
|
-
printWidth: number;
|
|
13
|
-
/**
|
|
14
|
-
* Specify the number of spaces per indentation-level.
|
|
15
|
-
*/
|
|
16
|
-
tabWidth: number;
|
|
17
|
-
/**
|
|
18
|
-
* Indent lines with tabs instead of spaces
|
|
19
|
-
*/
|
|
20
|
-
useTabs?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Print semicolons at the ends of statements.
|
|
23
|
-
*/
|
|
24
|
-
semi: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Use single quotes instead of double quotes.
|
|
27
|
-
*/
|
|
28
|
-
singleQuote: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Use single quotes in JSX.
|
|
31
|
-
*/
|
|
32
|
-
jsxSingleQuote: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* Print trailing commas wherever possible.
|
|
35
|
-
*/
|
|
36
|
-
trailingComma: "none" | "es5" | "all";
|
|
37
|
-
/**
|
|
38
|
-
* Print spaces between brackets in object literals.
|
|
39
|
-
*/
|
|
40
|
-
bracketSpacing: boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Put the `>` of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the last line instead of being
|
|
43
|
-
* alone on the next line (does not apply to self closing elements).
|
|
44
|
-
*/
|
|
45
|
-
bracketSameLine: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Put the `>` of a multi-line JSX element at the end of the last line instead of being alone on the next line.
|
|
48
|
-
* @deprecated use bracketSameLine instead
|
|
49
|
-
*/
|
|
50
|
-
jsxBracketSameLine: boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Format only a segment of a file.
|
|
53
|
-
*/
|
|
54
|
-
rangeStart: number;
|
|
55
|
-
/**
|
|
56
|
-
* Format only a segment of a file.
|
|
57
|
-
* @default Number.POSITIVE_INFINITY
|
|
58
|
-
*/
|
|
59
|
-
rangeEnd: number;
|
|
60
|
-
/**
|
|
61
|
-
* By default, Prettier will wrap markdown text as-is since some services use a linebreak-sensitive renderer.
|
|
62
|
-
* In some cases you may want to rely on editor/viewer soft wrapping instead, so this option allows you to opt out.
|
|
63
|
-
* @default "preserve"
|
|
64
|
-
*/
|
|
65
|
-
proseWrap: "always" | "never" | "preserve";
|
|
66
|
-
/**
|
|
67
|
-
* Include parentheses around a sole arrow function parameter.
|
|
68
|
-
* @default "always"
|
|
69
|
-
*/
|
|
70
|
-
arrowParens: "avoid" | "always";
|
|
71
|
-
/**
|
|
72
|
-
* Provide ability to support new languages to prettier.
|
|
73
|
-
*/
|
|
74
|
-
plugins: Array<string | any>;
|
|
75
|
-
/**
|
|
76
|
-
* How to handle whitespaces in HTML.
|
|
77
|
-
* @default "css"
|
|
78
|
-
*/
|
|
79
|
-
htmlWhitespaceSensitivity: "css" | "strict" | "ignore";
|
|
80
|
-
/**
|
|
81
|
-
* Which end of line characters to apply.
|
|
82
|
-
* @default "lf"
|
|
83
|
-
*/
|
|
84
|
-
endOfLine: "auto" | "lf" | "crlf" | "cr";
|
|
85
|
-
/**
|
|
86
|
-
* Change when properties in objects are quoted.
|
|
87
|
-
* @default "as-needed"
|
|
88
|
-
*/
|
|
89
|
-
quoteProps: "as-needed" | "consistent" | "preserve";
|
|
90
|
-
/**
|
|
91
|
-
* Whether or not to indent the code inside <script> and <style> tags in Vue files.
|
|
92
|
-
* @default false
|
|
93
|
-
*/
|
|
94
|
-
vueIndentScriptAndStyle: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Enforce single attribute per line in HTML, Vue and JSX.
|
|
97
|
-
* @default false
|
|
98
|
-
*/
|
|
99
|
-
singleAttributePerLine: boolean;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export type BuiltInParserName =
|
|
103
|
-
| "acorn"
|
|
104
|
-
| "angular"
|
|
105
|
-
| "babel-flow"
|
|
106
|
-
| "babel-ts"
|
|
107
|
-
| "babel"
|
|
108
|
-
| "css"
|
|
109
|
-
| "espree"
|
|
110
|
-
| "flow"
|
|
111
|
-
| "glimmer"
|
|
112
|
-
| "graphql"
|
|
113
|
-
| "html"
|
|
114
|
-
| "json-stringify"
|
|
115
|
-
| "json"
|
|
116
|
-
| "json5"
|
|
117
|
-
| "less"
|
|
118
|
-
| "lwc"
|
|
119
|
-
| "markdown"
|
|
120
|
-
| "mdx"
|
|
121
|
-
| "meriyah"
|
|
122
|
-
| "scss"
|
|
123
|
-
| "typescript"
|
|
124
|
-
| "vue"
|
|
125
|
-
| "yaml";
|
|
126
|
-
|
|
127
|
-
// This utility is here to handle the case where you have an explicit union
|
|
128
|
-
// between string literals and the generic string type. It would normally
|
|
129
|
-
// resolve out to just the string type, but this generic LiteralUnion maintains
|
|
130
|
-
// the intellisense of the original union.
|
|
131
|
-
//
|
|
132
|
-
// It comes from this issue: microsoft/TypeScript#29729:
|
|
133
|
-
// https://github.com/microsoft/TypeScript/issues/29729#issuecomment-700527227
|
|
134
|
-
export type LiteralUnion<T extends U, U = string> =
|
|
135
|
-
| T
|
|
136
|
-
| (Pick<U, never> & { _?: never | undefined });
|
package/test/cli.spec.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
import { execa } from "execa";
|
|
4
|
-
import fs from "fs-extra";
|
|
5
|
-
import { afterAll, beforeEach, expect, it } from "vitest";
|
|
6
|
-
|
|
7
|
-
const CLI_PATH = join(__dirname, "../bin/index.js");
|
|
8
|
-
const genPath = join(__dirname, "..", ".temp");
|
|
9
|
-
|
|
10
|
-
async function run(env = {
|
|
11
|
-
SKIP_PROMPT: "1",
|
|
12
|
-
SKIP_GIT_CHECK: "1"
|
|
13
|
-
}) {
|
|
14
|
-
return execa("node", [CLI_PATH, "migrate"], {
|
|
15
|
-
cwd: genPath,
|
|
16
|
-
env: {
|
|
17
|
-
...process.env,
|
|
18
|
-
NO_COLOR: "1",
|
|
19
|
-
...env
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
async function createMockDir() {
|
|
25
|
-
await fs.rm(genPath, { recursive: true, force: true });
|
|
26
|
-
await fs.ensureDir(genPath);
|
|
27
|
-
|
|
28
|
-
await Promise.all([
|
|
29
|
-
fs.writeFile(join(genPath, "package.json"), JSON.stringify({}, null, 2)),
|
|
30
|
-
fs.writeFile(join(genPath, ".eslintrc.yml"), ""),
|
|
31
|
-
fs.writeFile(join(genPath, ".eslintignore"), "some-path\nsome-file"),
|
|
32
|
-
fs.writeFile(join(genPath, ".prettierc"), ""),
|
|
33
|
-
fs.writeFile(join(genPath, ".prettierignore"), "some-path\nsome-file")
|
|
34
|
-
]);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
beforeEach(async () => await createMockDir());
|
|
38
|
-
afterAll(async () => await fs.rm(genPath, { recursive: true, force: true }));
|
|
39
|
-
|
|
40
|
-
it("package.json updated", async () => {
|
|
41
|
-
const { stdout } = await run();
|
|
42
|
-
|
|
43
|
-
const pkgContent: Record<string, any> = await fs.readJSON(join(genPath, "package.json"));
|
|
44
|
-
|
|
45
|
-
expect(JSON.stringify(pkgContent.devDependencies)).toContain("@antfu/eslint-config");
|
|
46
|
-
expect(stdout).toContain("changes wrote to package.json");
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("esm eslint.config.js", async () => {
|
|
50
|
-
const pkgContent = await fs.readFile("package.json", "utf-8");
|
|
51
|
-
await fs.writeFile(join(genPath, "package.json"), JSON.stringify({ ...JSON.parse(pkgContent), type: "module" }, null, 2));
|
|
52
|
-
|
|
53
|
-
const { stdout } = await run();
|
|
54
|
-
|
|
55
|
-
const eslintConfigContent = await fs.readFile(join(genPath, "eslint.config.js"), "utf-8");
|
|
56
|
-
expect(eslintConfigContent.includes("export default")).toBeTruthy();
|
|
57
|
-
expect(stdout).toContain("created eslint.config.js");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("cjs eslint.config.js", async () => {
|
|
61
|
-
const { stdout } = await run();
|
|
62
|
-
|
|
63
|
-
const eslintConfigContent = await fs.readFile(join(genPath, "eslint.config.js"), "utf-8");
|
|
64
|
-
expect(eslintConfigContent.includes("module.exports")).toBeTruthy();
|
|
65
|
-
expect(stdout).toContain("created eslint.config.js");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("ignores files added in eslint.config.js", async () => {
|
|
69
|
-
const { stdout } = await run();
|
|
70
|
-
|
|
71
|
-
const eslintConfigContent = (await fs.readFile(join(genPath, "eslint.config.js"), "utf-8")).replace(/\\/g, "/");
|
|
72
|
-
|
|
73
|
-
expect(stdout).toContain("created eslint.config.js");
|
|
74
|
-
expect(eslintConfigContent)
|
|
75
|
-
.toMatchInlineSnapshot(`
|
|
76
|
-
"const antfu = require('@antfu/eslint-config').default
|
|
77
|
-
|
|
78
|
-
module.exports = antfu({
|
|
79
|
-
ignores: ["some-path","**/some-path/**","some-file","**/some-file/**"]
|
|
80
|
-
})
|
|
81
|
-
"
|
|
82
|
-
`);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("suggest remove unnecessary files", async () => {
|
|
86
|
-
const { stdout } = await run();
|
|
87
|
-
|
|
88
|
-
expect(stdout).toContain("you can now remove those files manually");
|
|
89
|
-
expect(stdout).toContain(".eslintignore, .eslintrc.yml, .prettierc, .prettierignore, eslint.config.js");
|
|
90
|
-
});
|