@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.
Files changed (103) hide show
  1. package/.eslintignore +1 -0
  2. package/.github/workflows/release.yml +37 -0
  3. package/.vscode/settings.json +36 -0
  4. package/CHANGELOG.md +740 -0
  5. package/README.md +70 -0
  6. package/eslint.config.ts +3 -0
  7. package/fixtures/input/css.css +10 -0
  8. package/fixtures/input/html.html +17 -0
  9. package/fixtures/input/javascript.js +69 -0
  10. package/fixtures/input/jsx.jsx +27 -0
  11. package/fixtures/input/markdown.md +34 -0
  12. package/fixtures/input/svelte.svelte +8 -0
  13. package/fixtures/input/toml.toml +23 -0
  14. package/fixtures/input/tsx.tsx +32 -0
  15. package/fixtures/input/typescript.ts +84 -0
  16. package/fixtures/input/vue-ts.vue +35 -0
  17. package/fixtures/input/vue.vue +27 -0
  18. package/fixtures/output/all/javascript.js +72 -0
  19. package/fixtures/output/all/jsx.jsx +26 -0
  20. package/fixtures/output/all/markdown.md +33 -0
  21. package/fixtures/output/all/svelte.svelte +8 -0
  22. package/fixtures/output/all/toml.toml +23 -0
  23. package/fixtures/output/all/tsx.tsx +32 -0
  24. package/fixtures/output/all/typescript.ts +83 -0
  25. package/fixtures/output/all/vue-ts.vue +35 -0
  26. package/fixtures/output/all/vue.vue +24 -0
  27. package/fixtures/output/js/javascript.js +72 -0
  28. package/fixtures/output/js/markdown.md +33 -0
  29. package/fixtures/output/js/toml.toml +23 -0
  30. package/fixtures/output/no-markdown-with-formatters/javascript.js +72 -0
  31. package/fixtures/output/no-markdown-with-formatters/jsx.jsx +24 -0
  32. package/fixtures/output/no-markdown-with-formatters/markdown.md +33 -0
  33. package/fixtures/output/no-markdown-with-formatters/toml.toml +23 -0
  34. package/fixtures/output/no-markdown-with-formatters/tsx.tsx +23 -0
  35. package/fixtures/output/no-markdown-with-formatters/typescript.ts +83 -0
  36. package/fixtures/output/no-style/javascript.js +72 -0
  37. package/fixtures/output/no-style/jsx.jsx +21 -0
  38. package/fixtures/output/no-style/toml.toml +23 -0
  39. package/fixtures/output/no-style/typescript.ts +80 -0
  40. package/fixtures/output/no-style/vue-ts.vue +35 -0
  41. package/fixtures/output/no-style/vue.vue +24 -0
  42. package/fixtures/output/tab-double-quotes/javascript.js +72 -0
  43. package/fixtures/output/tab-double-quotes/jsx.jsx +26 -0
  44. package/fixtures/output/tab-double-quotes/markdown.md +33 -0
  45. package/fixtures/output/tab-double-quotes/toml.toml +23 -0
  46. package/fixtures/output/tab-double-quotes/tsx.tsx +32 -0
  47. package/fixtures/output/tab-double-quotes/typescript.ts +83 -0
  48. package/fixtures/output/tab-double-quotes/vue-ts.vue +35 -0
  49. package/fixtures/output/tab-double-quotes/vue.vue +24 -0
  50. package/fixtures/output/ts-override/javascript.js +72 -0
  51. package/fixtures/output/ts-override/jsx.jsx +26 -0
  52. package/fixtures/output/ts-override/markdown.md +33 -0
  53. package/fixtures/output/ts-override/toml.toml +23 -0
  54. package/fixtures/output/ts-override/tsx.tsx +32 -0
  55. package/fixtures/output/ts-override/typescript.ts +83 -0
  56. package/fixtures/output/ts-override/vue-ts.vue +35 -0
  57. package/fixtures/output/ts-override/vue.vue +24 -0
  58. package/fixtures/output/with-formatters/css.css +11 -0
  59. package/fixtures/output/with-formatters/html.html +28 -0
  60. package/fixtures/output/with-formatters/javascript.js +72 -0
  61. package/fixtures/output/with-formatters/jsx.jsx +26 -0
  62. package/fixtures/output/with-formatters/markdown.md +34 -0
  63. package/fixtures/output/with-formatters/toml.toml +23 -0
  64. package/fixtures/output/with-formatters/tsx.tsx +32 -0
  65. package/fixtures/output/with-formatters/typescript.ts +83 -0
  66. package/fixtures/output/with-formatters/vue-ts.vue +38 -0
  67. package/fixtures/output/with-formatters/vue.vue +24 -0
  68. package/package.json +130 -12
  69. package/src/configs/comments.ts +19 -0
  70. package/src/configs/formatters.ts +187 -0
  71. package/src/configs/ignores.ts +10 -0
  72. package/src/configs/imports.ts +46 -0
  73. package/src/configs/index.ts +21 -0
  74. package/src/configs/javascript.ts +277 -0
  75. package/src/configs/jsdoc.ts +41 -0
  76. package/src/configs/jsonc.ts +86 -0
  77. package/src/configs/markdown.ts +110 -0
  78. package/src/configs/node.ts +24 -0
  79. package/src/configs/perfectionist.ts +18 -0
  80. package/src/configs/react.ts +111 -0
  81. package/src/configs/sort.ts +223 -0
  82. package/src/configs/stylistic.ts +52 -0
  83. package/src/configs/svelte.ts +107 -0
  84. package/src/configs/test.ts +54 -0
  85. package/src/configs/toml.ts +72 -0
  86. package/src/configs/typescript.ts +171 -0
  87. package/src/configs/unicorn.ts +41 -0
  88. package/src/configs/unocss.ts +43 -0
  89. package/src/configs/vue.ts +170 -0
  90. package/src/configs/yaml.ts +72 -0
  91. package/src/factory.ts +255 -0
  92. package/src/globs.ts +81 -0
  93. package/src/index.ts +9 -0
  94. package/src/plugins.ts +10 -0
  95. package/src/stub.d.ts +3 -0
  96. package/src/types.ts +364 -0
  97. package/src/utils.ts +76 -0
  98. package/src/vender/prettier-types.ts +136 -0
  99. package/test/cli.spec.ts +90 -0
  100. package/test/fixtures.test.ts +127 -0
  101. package/tsconfig.json +17 -0
  102. package/tsup.config.ts +8 -0
  103. 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
@@ -0,0 +1,9 @@
1
+ import { curev } from "./factory";
2
+
3
+ export * from "./configs";
4
+ export * from "./factory";
5
+ export * from "./globs";
6
+ export * from "./types";
7
+ export * from "./utils";
8
+
9
+ export default curev;
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
@@ -0,0 +1,3 @@
1
+ declare module "eslint-plugin-react"
2
+ declare module "eslint-plugin-react-hooks"
3
+ declare module "eslint-plugin-react-refresh"