@curev/eslint-config 0.2.2 → 0.3.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/.eslintignore +1 -0
- package/.github/workflows/release.yml +37 -0
- package/.vscode/settings.json +36 -0
- package/CHANGELOG.md +740 -0
- package/README.md +70 -0
- package/eslint.config.ts +3 -0
- package/fixtures/input/css.css +10 -0
- package/fixtures/input/html.html +17 -0
- package/fixtures/input/javascript.js +69 -0
- package/fixtures/input/jsx.jsx +27 -0
- package/fixtures/input/markdown.md +34 -0
- package/fixtures/input/svelte.svelte +8 -0
- package/fixtures/input/toml.toml +23 -0
- package/fixtures/input/tsx.tsx +32 -0
- package/fixtures/input/typescript.ts +84 -0
- package/fixtures/input/vue-ts.vue +35 -0
- package/fixtures/input/vue.vue +27 -0
- package/fixtures/output/all/javascript.js +72 -0
- package/fixtures/output/all/jsx.jsx +26 -0
- package/fixtures/output/all/markdown.md +33 -0
- package/fixtures/output/all/svelte.svelte +8 -0
- package/fixtures/output/all/toml.toml +23 -0
- package/fixtures/output/all/tsx.tsx +32 -0
- package/fixtures/output/all/typescript.ts +83 -0
- package/fixtures/output/all/vue-ts.vue +35 -0
- package/fixtures/output/all/vue.vue +24 -0
- package/fixtures/output/js/javascript.js +72 -0
- package/fixtures/output/js/markdown.md +33 -0
- package/fixtures/output/js/toml.toml +23 -0
- package/fixtures/output/no-markdown-with-formatters/javascript.js +72 -0
- package/fixtures/output/no-markdown-with-formatters/jsx.jsx +24 -0
- package/fixtures/output/no-markdown-with-formatters/markdown.md +33 -0
- package/fixtures/output/no-markdown-with-formatters/toml.toml +23 -0
- package/fixtures/output/no-markdown-with-formatters/tsx.tsx +23 -0
- package/fixtures/output/no-markdown-with-formatters/typescript.ts +83 -0
- package/fixtures/output/no-style/javascript.js +72 -0
- package/fixtures/output/no-style/jsx.jsx +21 -0
- package/fixtures/output/no-style/toml.toml +23 -0
- package/fixtures/output/no-style/typescript.ts +80 -0
- package/fixtures/output/no-style/vue-ts.vue +35 -0
- package/fixtures/output/no-style/vue.vue +24 -0
- package/fixtures/output/tab-double-quotes/javascript.js +72 -0
- package/fixtures/output/tab-double-quotes/jsx.jsx +26 -0
- package/fixtures/output/tab-double-quotes/markdown.md +33 -0
- package/fixtures/output/tab-double-quotes/toml.toml +23 -0
- package/fixtures/output/tab-double-quotes/tsx.tsx +32 -0
- package/fixtures/output/tab-double-quotes/typescript.ts +83 -0
- package/fixtures/output/tab-double-quotes/vue-ts.vue +35 -0
- package/fixtures/output/tab-double-quotes/vue.vue +24 -0
- package/fixtures/output/ts-override/javascript.js +72 -0
- package/fixtures/output/ts-override/jsx.jsx +26 -0
- package/fixtures/output/ts-override/markdown.md +33 -0
- package/fixtures/output/ts-override/toml.toml +23 -0
- package/fixtures/output/ts-override/tsx.tsx +32 -0
- package/fixtures/output/ts-override/typescript.ts +83 -0
- package/fixtures/output/ts-override/vue-ts.vue +35 -0
- package/fixtures/output/ts-override/vue.vue +24 -0
- package/fixtures/output/with-formatters/css.css +11 -0
- package/fixtures/output/with-formatters/html.html +28 -0
- package/fixtures/output/with-formatters/javascript.js +72 -0
- package/fixtures/output/with-formatters/jsx.jsx +26 -0
- package/fixtures/output/with-formatters/markdown.md +34 -0
- package/fixtures/output/with-formatters/toml.toml +23 -0
- package/fixtures/output/with-formatters/tsx.tsx +32 -0
- package/fixtures/output/with-formatters/typescript.ts +83 -0
- package/fixtures/output/with-formatters/vue-ts.vue +38 -0
- package/fixtures/output/with-formatters/vue.vue +24 -0
- package/package.json +130 -12
- package/src/configs/comments.ts +19 -0
- package/src/configs/formatters.ts +187 -0
- package/src/configs/ignores.ts +10 -0
- package/src/configs/imports.ts +46 -0
- package/src/configs/index.ts +21 -0
- package/src/configs/javascript.ts +277 -0
- package/src/configs/jsdoc.ts +41 -0
- package/src/configs/jsonc.ts +86 -0
- package/src/configs/markdown.ts +110 -0
- package/src/configs/node.ts +24 -0
- package/src/configs/perfectionist.ts +18 -0
- package/src/configs/react.ts +111 -0
- package/src/configs/sort.ts +223 -0
- package/src/configs/stylistic.ts +52 -0
- package/src/configs/svelte.ts +107 -0
- package/src/configs/test.ts +54 -0
- package/src/configs/toml.ts +72 -0
- package/src/configs/typescript.ts +171 -0
- package/src/configs/unicorn.ts +41 -0
- package/src/configs/unocss.ts +43 -0
- package/src/configs/vue.ts +170 -0
- package/src/configs/yaml.ts +72 -0
- package/src/factory.ts +255 -0
- package/src/globs.ts +81 -0
- package/src/index.ts +9 -0
- package/src/plugins.ts +10 -0
- package/src/stub.d.ts +3 -0
- package/src/types.ts +364 -0
- package/src/utils.ts +76 -0
- package/src/vender/prettier-types.ts +136 -0
- package/test/cli.spec.ts +90 -0
- package/test/fixtures.test.ts +127 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +8 -0
- package/index.js +0 -5
package/src/factory.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { isPackageExists } from "local-pkg";
|
|
4
|
+
import type { Awaitable, FlatConfigItem, OptionsConfig, UserConfigItem } from "./types";
|
|
5
|
+
import {
|
|
6
|
+
comments,
|
|
7
|
+
ignores,
|
|
8
|
+
imports,
|
|
9
|
+
javascript,
|
|
10
|
+
jsdoc,
|
|
11
|
+
jsonc,
|
|
12
|
+
markdown,
|
|
13
|
+
node,
|
|
14
|
+
perfectionist,
|
|
15
|
+
react,
|
|
16
|
+
sortPackageJson,
|
|
17
|
+
sortTsconfig,
|
|
18
|
+
stylistic,
|
|
19
|
+
svelte,
|
|
20
|
+
test,
|
|
21
|
+
toml,
|
|
22
|
+
typescript,
|
|
23
|
+
unicorn,
|
|
24
|
+
unocss,
|
|
25
|
+
vue,
|
|
26
|
+
yaml
|
|
27
|
+
} from "./configs";
|
|
28
|
+
import { combine, interopDefault } from "./utils";
|
|
29
|
+
import { formatters } from "./configs/formatters";
|
|
30
|
+
|
|
31
|
+
const flatConfigProps: (keyof FlatConfigItem)[] = [
|
|
32
|
+
"name",
|
|
33
|
+
"files",
|
|
34
|
+
"ignores",
|
|
35
|
+
"languageOptions",
|
|
36
|
+
"linterOptions",
|
|
37
|
+
"processor",
|
|
38
|
+
"plugins",
|
|
39
|
+
"rules",
|
|
40
|
+
"settings"
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const VuePackages = [
|
|
44
|
+
"vue",
|
|
45
|
+
"nuxt",
|
|
46
|
+
"vitepress",
|
|
47
|
+
"@slidev/cli"
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Construct an array of ESLint flat config items.
|
|
52
|
+
*/
|
|
53
|
+
export async function curev(
|
|
54
|
+
options: OptionsConfig & FlatConfigItem = {},
|
|
55
|
+
...userConfigs: Awaitable<UserConfigItem | UserConfigItem[]>[]
|
|
56
|
+
): Promise<UserConfigItem[]> {
|
|
57
|
+
const {
|
|
58
|
+
componentExts = [],
|
|
59
|
+
gitignore: enableGitignore = true,
|
|
60
|
+
isInEditor = !!((process.env.VSCODE_PID || process.env.JETBRAINS_IDE || process.env.VIM) && !process.env.CI),
|
|
61
|
+
react: enableReact = false,
|
|
62
|
+
svelte: enableSvelte = false,
|
|
63
|
+
typescript: enableTypeScript = isPackageExists("typescript"),
|
|
64
|
+
unocss: enableUnoCSS = false,
|
|
65
|
+
vue: enableVue = VuePackages.some(i => isPackageExists(i))
|
|
66
|
+
} = options;
|
|
67
|
+
|
|
68
|
+
const stylisticOptions = options.stylistic === false
|
|
69
|
+
? false
|
|
70
|
+
: typeof options.stylistic === "object"
|
|
71
|
+
? options.stylistic
|
|
72
|
+
: {};
|
|
73
|
+
|
|
74
|
+
if (stylisticOptions && !("jsx" in stylisticOptions)) {
|
|
75
|
+
stylisticOptions.jsx = options.jsx ?? true;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const configs: Awaitable<FlatConfigItem[]>[] = [];
|
|
79
|
+
|
|
80
|
+
if (enableGitignore) {
|
|
81
|
+
if (typeof enableGitignore !== "boolean") {
|
|
82
|
+
configs.push(interopDefault(import("eslint-config-flat-gitignore")).then(r => [r(enableGitignore)]));
|
|
83
|
+
} else {
|
|
84
|
+
if (fs.existsSync(".gitignore")) {
|
|
85
|
+
configs.push(interopDefault(import("eslint-config-flat-gitignore")).then(r => [r()]));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Base configs
|
|
91
|
+
configs.push(
|
|
92
|
+
ignores(),
|
|
93
|
+
javascript({
|
|
94
|
+
isInEditor,
|
|
95
|
+
overrides: getOverrides(options, "javascript")
|
|
96
|
+
}),
|
|
97
|
+
comments(),
|
|
98
|
+
node(),
|
|
99
|
+
jsdoc({
|
|
100
|
+
stylistic: stylisticOptions
|
|
101
|
+
}),
|
|
102
|
+
imports({
|
|
103
|
+
stylistic: stylisticOptions
|
|
104
|
+
}),
|
|
105
|
+
unicorn(),
|
|
106
|
+
|
|
107
|
+
// Optional plugins (installed but not enabled by default)
|
|
108
|
+
perfectionist()
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if (enableVue) {
|
|
112
|
+
componentExts.push("vue");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (enableTypeScript) {
|
|
116
|
+
configs.push(typescript({
|
|
117
|
+
...resolveSubOptions(options, "typescript"),
|
|
118
|
+
componentExts,
|
|
119
|
+
overrides: getOverrides(options, "typescript")
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (stylisticOptions) {
|
|
124
|
+
configs.push(stylistic({
|
|
125
|
+
...stylisticOptions,
|
|
126
|
+
overrides: getOverrides(options, "stylistic")
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (options.test ?? true) {
|
|
131
|
+
configs.push(test({
|
|
132
|
+
isInEditor,
|
|
133
|
+
overrides: getOverrides(options, "test")
|
|
134
|
+
}));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (enableVue) {
|
|
138
|
+
configs.push(vue({
|
|
139
|
+
...resolveSubOptions(options, "vue"),
|
|
140
|
+
overrides: getOverrides(options, "vue"),
|
|
141
|
+
stylistic: stylisticOptions,
|
|
142
|
+
typescript: !!enableTypeScript
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (enableReact) {
|
|
147
|
+
configs.push(react({
|
|
148
|
+
overrides: getOverrides(options, "react"),
|
|
149
|
+
typescript: !!enableTypeScript
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (enableSvelte) {
|
|
154
|
+
configs.push(svelte({
|
|
155
|
+
overrides: getOverrides(options, "svelte"),
|
|
156
|
+
stylistic: stylisticOptions,
|
|
157
|
+
typescript: !!enableTypeScript
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (enableUnoCSS) {
|
|
162
|
+
configs.push(unocss({
|
|
163
|
+
...resolveSubOptions(options, "unocss"),
|
|
164
|
+
overrides: getOverrides(options, "unocss")
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (options.jsonc ?? true) {
|
|
169
|
+
configs.push(
|
|
170
|
+
jsonc({
|
|
171
|
+
overrides: getOverrides(options, "jsonc"),
|
|
172
|
+
stylistic: stylisticOptions
|
|
173
|
+
}),
|
|
174
|
+
sortPackageJson(),
|
|
175
|
+
sortTsconfig()
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (options.yaml ?? true) {
|
|
180
|
+
configs.push(yaml({
|
|
181
|
+
overrides: getOverrides(options, "yaml"),
|
|
182
|
+
stylistic: stylisticOptions
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (options.toml ?? true) {
|
|
187
|
+
configs.push(toml({
|
|
188
|
+
overrides: getOverrides(options, "toml"),
|
|
189
|
+
stylistic: stylisticOptions
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (options.markdown ?? true) {
|
|
194
|
+
configs.push(
|
|
195
|
+
markdown(
|
|
196
|
+
{
|
|
197
|
+
componentExts,
|
|
198
|
+
overrides: getOverrides(options, "markdown")
|
|
199
|
+
}
|
|
200
|
+
)
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (options.formatters) {
|
|
205
|
+
configs.push(formatters(
|
|
206
|
+
options.formatters,
|
|
207
|
+
typeof stylisticOptions === "boolean" ? {} : stylisticOptions
|
|
208
|
+
));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// User can optionally pass a flat config item to the first argument
|
|
212
|
+
// We pick the known keys as ESLint would do schema validation
|
|
213
|
+
const fusedConfig = flatConfigProps.reduce((acc, key) => {
|
|
214
|
+
if (key in options) {
|
|
215
|
+
acc[key] = options[key] as any;
|
|
216
|
+
}
|
|
217
|
+
return acc;
|
|
218
|
+
}, {} as FlatConfigItem);
|
|
219
|
+
if (Object.keys(fusedConfig).length) {
|
|
220
|
+
configs.push([fusedConfig]);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const merged = combine(
|
|
224
|
+
...configs,
|
|
225
|
+
...userConfigs
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
return merged;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export type ResolvedOptions<T> = T extends boolean
|
|
232
|
+
? never
|
|
233
|
+
: NonNullable<T>;
|
|
234
|
+
|
|
235
|
+
export function resolveSubOptions<K extends keyof OptionsConfig>(
|
|
236
|
+
options: OptionsConfig,
|
|
237
|
+
key: K
|
|
238
|
+
): ResolvedOptions<OptionsConfig[K]> {
|
|
239
|
+
return typeof options[key] === "boolean"
|
|
240
|
+
? {} as any
|
|
241
|
+
: options[key] || {};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function getOverrides<K extends keyof OptionsConfig>(
|
|
245
|
+
options: OptionsConfig,
|
|
246
|
+
key: K
|
|
247
|
+
) {
|
|
248
|
+
const sub = resolveSubOptions(options, key);
|
|
249
|
+
return {
|
|
250
|
+
...(options.overrides as any)?.[key],
|
|
251
|
+
..."overrides" in sub
|
|
252
|
+
? sub.overrides
|
|
253
|
+
: {}
|
|
254
|
+
};
|
|
255
|
+
}
|
package/src/globs.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
|
|
2
|
+
export const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
|
|
3
|
+
|
|
4
|
+
export const GLOB_JS = "**/*.?([cm])js";
|
|
5
|
+
export const GLOB_JSX = "**/*.?([cm])jsx";
|
|
6
|
+
|
|
7
|
+
export const GLOB_TS = "**/*.?([cm])ts";
|
|
8
|
+
export const GLOB_TSX = "**/*.?([cm])tsx";
|
|
9
|
+
|
|
10
|
+
export const GLOB_STYLE = "**/*.{c,le,sc}ss";
|
|
11
|
+
export const GLOB_CSS = "**/*.css";
|
|
12
|
+
export const GLOB_POSTCSS = "**/*.{p,post}css";
|
|
13
|
+
export const GLOB_LESS = "**/*.less";
|
|
14
|
+
export const GLOB_SCSS = "**/*.scss";
|
|
15
|
+
|
|
16
|
+
export const GLOB_JSON = "**/*.json";
|
|
17
|
+
export const GLOB_JSON5 = "**/*.json5";
|
|
18
|
+
export const GLOB_JSONC = "**/*.jsonc";
|
|
19
|
+
|
|
20
|
+
export const GLOB_MARKDOWN = "**/*.md";
|
|
21
|
+
export const GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
|
|
22
|
+
export const GLOB_SVELTE = "**/*.svelte";
|
|
23
|
+
export const GLOB_VUE = "**/*.vue";
|
|
24
|
+
export const GLOB_YAML = "**/*.y?(a)ml";
|
|
25
|
+
export const GLOB_TOML = "**/*.toml";
|
|
26
|
+
export const GLOB_HTML = "**/*.htm?(l)";
|
|
27
|
+
|
|
28
|
+
export const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
|
|
29
|
+
|
|
30
|
+
export const GLOB_TESTS = [
|
|
31
|
+
`**/__tests__/**/*.${GLOB_SRC_EXT}`,
|
|
32
|
+
`**/*.spec.${GLOB_SRC_EXT}`,
|
|
33
|
+
`**/*.test.${GLOB_SRC_EXT}`,
|
|
34
|
+
`**/*.bench.${GLOB_SRC_EXT}`,
|
|
35
|
+
`**/*.benchmark.${GLOB_SRC_EXT}`
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
export const GLOB_ALL_SRC = [
|
|
39
|
+
GLOB_SRC,
|
|
40
|
+
GLOB_STYLE,
|
|
41
|
+
GLOB_JSON,
|
|
42
|
+
GLOB_JSON5,
|
|
43
|
+
GLOB_MARKDOWN,
|
|
44
|
+
GLOB_SVELTE,
|
|
45
|
+
GLOB_VUE,
|
|
46
|
+
GLOB_YAML,
|
|
47
|
+
GLOB_HTML
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export const GLOB_EXCLUDE = [
|
|
51
|
+
"**/node_modules",
|
|
52
|
+
"**/dist",
|
|
53
|
+
"**/package-lock.json",
|
|
54
|
+
"**/yarn.lock",
|
|
55
|
+
"**/pnpm-lock.yaml",
|
|
56
|
+
"**/bun.lockb",
|
|
57
|
+
|
|
58
|
+
"**/output",
|
|
59
|
+
"**/coverage",
|
|
60
|
+
"**/temp",
|
|
61
|
+
"**/.temp",
|
|
62
|
+
"**/tmp",
|
|
63
|
+
"**/.tmp",
|
|
64
|
+
"**/.history",
|
|
65
|
+
"**/.vitepress/cache",
|
|
66
|
+
"**/.nuxt",
|
|
67
|
+
"**/.next",
|
|
68
|
+
"**/.vercel",
|
|
69
|
+
"**/.changeset",
|
|
70
|
+
"**/.idea",
|
|
71
|
+
"**/.cache",
|
|
72
|
+
"**/.output",
|
|
73
|
+
"**/.vite-inspect",
|
|
74
|
+
|
|
75
|
+
"**/CHANGELOG*.md",
|
|
76
|
+
"**/*.min.*",
|
|
77
|
+
"**/LICENSE*",
|
|
78
|
+
"**/__snapshots__",
|
|
79
|
+
"**/auto-import?(s).d.ts",
|
|
80
|
+
"**/components.d.ts"
|
|
81
|
+
];
|
package/src/index.ts
ADDED
package/src/plugins.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// eslint-disable-next-line ts/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
|
|
4
|
+
export { default as pluginAntfu } from "eslint-plugin-antfu";
|
|
5
|
+
export { default as pluginComments } from "eslint-plugin-eslint-comments";
|
|
6
|
+
export * as pluginImport from "eslint-plugin-i";
|
|
7
|
+
export { default as pluginNode } from "eslint-plugin-n";
|
|
8
|
+
export { default as pluginUnicorn } from "eslint-plugin-unicorn";
|
|
9
|
+
export { default as pluginUnusedImports } from "eslint-plugin-unused-imports";
|
|
10
|
+
export { default as pluginPerfectionist } from "eslint-plugin-perfectionist";
|
package/src/stub.d.ts
ADDED