@ghettoddos/eslint-config 1.3.0 → 1.5.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 +7636 -7629
  2. package/dist/index.js +1677 -1981
  3. package/package.json +35 -20
package/dist/index.js CHANGED
@@ -1,2078 +1,1774 @@
1
- // src/factory.ts
2
1
  import { FlatConfigComposer } from "eslint-flat-config-utils";
3
- import { isPackageExists as isPackageExists3 } from "local-pkg";
4
-
5
- // src/plugins.ts
6
- import { default as default2 } from "@eslint-community/eslint-plugin-eslint-comments";
7
- import { default as default3 } from "eslint-plugin-antfu";
2
+ import { isPackageExists } from "local-pkg";
3
+ import pluginComments from "@eslint-community/eslint-plugin-eslint-comments";
4
+ import pluginAntfu from "eslint-plugin-antfu";
8
5
  import * as pluginImport from "eslint-plugin-import-x";
9
- import { default as default4 } from "eslint-plugin-n";
10
- import { default as default5 } from "eslint-plugin-perfectionist";
11
- import { default as default6 } from "eslint-plugin-unicorn";
12
- import { default as default7 } from "eslint-plugin-unused-imports";
6
+ import pluginNode from "eslint-plugin-n";
7
+ import pluginPerfectionist from "eslint-plugin-perfectionist";
8
+ import pluginUnicorn from "eslint-plugin-unicorn";
9
+ import pluginUnusedImports from "eslint-plugin-unused-imports";
10
+ import process from "node:process";
11
+ import { fileURLToPath } from "node:url";
12
+ import globals from "globals";
13
+ import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
14
+ import { configs } from "eslint-plugin-regexp";
13
15
 
14
- // src/configs/comments.ts
16
+ //#region src/configs/comments.ts
15
17
  async function comments() {
16
- return [
17
- {
18
- name: "eslint-comments/rules",
19
- plugins: {
20
- "eslint-comments": default2
21
- },
22
- rules: {
23
- "eslint-comments/no-aggregating-enable": "error",
24
- "eslint-comments/no-duplicate-disable": "error",
25
- "eslint-comments/no-unlimited-disable": "error",
26
- "eslint-comments/no-unused-enable": "error"
27
- }
28
- }
29
- ];
18
+ return [{
19
+ name: "eslint-comments/rules",
20
+ plugins: { "eslint-comments": pluginComments },
21
+ rules: {
22
+ "eslint-comments/no-aggregating-enable": "error",
23
+ "eslint-comments/no-duplicate-disable": "error",
24
+ "eslint-comments/no-unlimited-disable": "error",
25
+ "eslint-comments/no-unused-enable": "error"
26
+ }
27
+ }];
30
28
  }
31
29
 
32
- // src/globs.ts
33
- var GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
34
- var GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
35
- var GLOB_JS = "**/*.?([cm])js";
36
- var GLOB_JSX = "**/*.?([cm])jsx";
37
- var GLOB_TS = "**/*.?([cm])ts";
38
- var GLOB_TSX = "**/*.?([cm])tsx";
39
- var GLOB_STYLE = "**/*.{c,le,sc}ss";
40
- var GLOB_CSS = "**/*.css";
41
- var GLOB_POSTCSS = "**/*.{p,post}css";
42
- var GLOB_SCSS = "**/*.scss";
43
- var GLOB_JSON = "**/*.json";
44
- var GLOB_JSON5 = "**/*.json5";
45
- var GLOB_JSONC = "**/*.jsonc";
46
- var GLOB_MARKDOWN = "**/*.md";
47
- var GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
48
- var GLOB_YAML = "**/*.y?(a)ml";
49
- var GLOB_TOML = "**/*.toml";
50
- var GLOB_XML = "**/*.xml";
51
- var GLOB_SVG = "**/*.svg";
52
- var GLOB_HTML = "**/*.htm?(l)";
53
- var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
54
- var GLOB_ALL_SRC = [
55
- GLOB_SRC,
56
- GLOB_STYLE,
57
- GLOB_JSON,
58
- GLOB_JSON5,
59
- GLOB_MARKDOWN,
60
- GLOB_YAML,
61
- GLOB_XML,
62
- GLOB_HTML
30
+ //#endregion
31
+ //#region src/globs.ts
32
+ const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
33
+ const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
34
+ const GLOB_JS = "**/*.?([cm])js";
35
+ const GLOB_JSX = "**/*.?([cm])jsx";
36
+ const GLOB_TS = "**/*.?([cm])ts";
37
+ const GLOB_TSX = "**/*.?([cm])tsx";
38
+ const GLOB_STYLE = "**/*.{c,le,sc}ss";
39
+ const GLOB_CSS = "**/*.css";
40
+ const GLOB_POSTCSS = "**/*.{p,post}css";
41
+ const GLOB_SCSS = "**/*.scss";
42
+ const GLOB_JSON = "**/*.json";
43
+ const GLOB_JSON5 = "**/*.json5";
44
+ const GLOB_JSONC = "**/*.jsonc";
45
+ const GLOB_MARKDOWN = "**/*.md";
46
+ const GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
47
+ const GLOB_YAML = "**/*.y?(a)ml";
48
+ const GLOB_TOML = "**/*.toml";
49
+ const GLOB_XML = "**/*.xml";
50
+ const GLOB_SVG = "**/*.svg";
51
+ const GLOB_HTML = "**/*.htm?(l)";
52
+ const GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
53
+ const GLOB_ALL_SRC = [
54
+ GLOB_SRC,
55
+ GLOB_STYLE,
56
+ GLOB_JSON,
57
+ GLOB_JSON5,
58
+ GLOB_MARKDOWN,
59
+ GLOB_YAML,
60
+ GLOB_XML,
61
+ GLOB_HTML
63
62
  ];
64
- var GLOB_EXCLUDE = [
65
- "**/node_modules",
66
- "**/dist",
67
- "**/package-lock.json",
68
- "**/yarn.lock",
69
- "**/pnpm-lock.yaml",
70
- "**/bun.lockb",
71
- "**/output",
72
- "**/coverage",
73
- "**/temp",
74
- "**/.temp",
75
- "**/tmp",
76
- "**/.tmp",
77
- "**/.history",
78
- "**/.vitepress/cache",
79
- "**/.nuxt",
80
- "**/.next",
81
- "**/.svelte-kit",
82
- "**/.vercel",
83
- "**/.changeset",
84
- "**/.idea",
85
- "**/.cache",
86
- "**/.output",
87
- "**/.vite-inspect",
88
- "**/.yarn",
89
- "**/vite.config.*.timestamp-*",
90
- "**/CHANGELOG*.md",
91
- "**/*.min.*",
92
- "**/LICENSE*",
93
- "**/__snapshots__",
94
- "**/auto-import?(s).d.ts",
95
- "**/components.d.ts"
63
+ const GLOB_EXCLUDE = [
64
+ "**/node_modules",
65
+ "**/dist",
66
+ "**/package-lock.json",
67
+ "**/yarn.lock",
68
+ "**/pnpm-lock.yaml",
69
+ "**/bun.lockb",
70
+ "**/output",
71
+ "**/coverage",
72
+ "**/temp",
73
+ "**/.temp",
74
+ "**/tmp",
75
+ "**/.tmp",
76
+ "**/.history",
77
+ "**/.vitepress/cache",
78
+ "**/.nuxt",
79
+ "**/.next",
80
+ "**/.svelte-kit",
81
+ "**/.vercel",
82
+ "**/.changeset",
83
+ "**/.idea",
84
+ "**/.cache",
85
+ "**/.output",
86
+ "**/.vite-inspect",
87
+ "**/.yarn",
88
+ "**/vite.config.*.timestamp-*",
89
+ "**/CHANGELOG*.md",
90
+ "**/*.min.*",
91
+ "**/LICENSE*",
92
+ "**/__snapshots__",
93
+ "**/auto-import?(s).d.ts",
94
+ "**/components.d.ts"
96
95
  ];
97
96
 
98
- // src/configs/disables.ts
97
+ //#endregion
98
+ //#region src/configs/disables.ts
99
99
  async function disables() {
100
- return [
101
- {
102
- files: [`**/scripts/${GLOB_SRC}`],
103
- name: "disables/scripts",
104
- rules: {
105
- "antfu/no-top-level-await": "off",
106
- "no-console": "off",
107
- "ts/explicit-function-return-type": "off"
108
- }
109
- },
110
- {
111
- files: ["**/*.d.?([cm])ts"],
112
- name: "disables/dts",
113
- rules: {
114
- "eslint-comments/no-unlimited-disable": "off",
115
- "import/no-duplicates": "off",
116
- "no-restricted-syntax": "off",
117
- "unused-imports/no-unused-vars": "off"
118
- }
119
- },
120
- {
121
- files: ["**/*.js", "**/*.cjs"],
122
- name: "disables/cjs",
123
- rules: {
124
- "ts/no-require-imports": "off"
125
- }
126
- }
127
- ];
100
+ return [
101
+ {
102
+ files: [`**/scripts/${GLOB_SRC}`],
103
+ name: "disables/scripts",
104
+ rules: {
105
+ "antfu/no-top-level-await": "off",
106
+ "no-console": "off",
107
+ "ts/explicit-function-return-type": "off"
108
+ }
109
+ },
110
+ {
111
+ files: ["**/*.d.?([cm])ts"],
112
+ name: "disables/dts",
113
+ rules: {
114
+ "eslint-comments/no-unlimited-disable": "off",
115
+ "import/no-duplicates": "off",
116
+ "no-restricted-syntax": "off",
117
+ "unused-imports/no-unused-vars": "off"
118
+ }
119
+ },
120
+ {
121
+ files: ["**/*.js", "**/*.cjs"],
122
+ name: "disables/cjs",
123
+ rules: { "ts/no-require-imports": "off" }
124
+ }
125
+ ];
128
126
  }
129
127
 
130
- // src/utils.ts
131
- import process from "node:process";
132
- import { fileURLToPath } from "node:url";
133
- import { isPackageExists } from "local-pkg";
134
- var scopeUrl = fileURLToPath(new URL(".", import.meta.url));
135
- var isCwdInScope = isPackageExists("@ghettoddos/eslint-config");
136
- var parserPlain = {
137
- meta: {
138
- name: "parser-plain"
139
- },
140
- parseForESLint: (code) => ({
141
- ast: {
142
- body: [],
143
- comments: [],
144
- loc: { end: code.length, start: 0 },
145
- range: [0, code.length],
146
- tokens: [],
147
- type: "Program"
148
- },
149
- scopeManager: null,
150
- services: { isPlain: true },
151
- visitorKeys: {
152
- Program: []
153
- }
154
- })
128
+ //#endregion
129
+ //#region src/constants.ts
130
+ const ReactPackages = ["react", "nest"];
131
+ const ReactRefreshAllowConstantExportPackages = ["vite"];
132
+ const ReactRouterPackages = [
133
+ "@react-router/node",
134
+ "@react-router/react",
135
+ "@react-router/serve",
136
+ "@react-router/dev"
137
+ ];
138
+ const NextJsPackages = ["next"];
139
+
140
+ //#endregion
141
+ //#region src/utils.ts
142
+ const scopeUrl = fileURLToPath(new URL(".", import.meta.url));
143
+ const isCwdInScope = isPackageExists("@ghettoddos/eslint-config");
144
+ const parserPlain = {
145
+ meta: { name: "parser-plain" },
146
+ parseForESLint: (code) => ({
147
+ ast: {
148
+ body: [],
149
+ comments: [],
150
+ loc: {
151
+ end: code.length,
152
+ start: 0
153
+ },
154
+ range: [0, code.length],
155
+ tokens: [],
156
+ type: "Program"
157
+ },
158
+ scopeManager: null,
159
+ services: { isPlain: true },
160
+ visitorKeys: { Program: [] }
161
+ })
155
162
  };
156
- async function combine(...configs2) {
157
- const resolved = await Promise.all(configs2);
158
- return resolved.flat();
163
+ /**
164
+ * Combine array and non-array configs into a single array.
165
+ */
166
+ async function combine(...configs$1) {
167
+ const resolved = await Promise.all(configs$1);
168
+ return resolved.flat();
159
169
  }
170
+ /**
171
+ * Rename plugin prefixes in a rule object.
172
+ * Accepts a map of prefixes to rename.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * import { renameRules } from '@ghettoddos/eslint-config'
177
+ *
178
+ * export default [{
179
+ * rules: renameRules(
180
+ * {
181
+ * '@typescript-eslint/indent': 'error'
182
+ * },
183
+ * { '@typescript-eslint': 'ts' }
184
+ * )
185
+ * }]
186
+ * ```
187
+ */
160
188
  function renameRules(rules, map) {
161
- return Object.fromEntries(
162
- Object.entries(rules).map(([key, value]) => {
163
- for (const [from, to] of Object.entries(map)) {
164
- if (key.startsWith(`${from}/`)) {
165
- return [to + key.slice(from.length), value];
166
- }
167
- }
168
- return [key, value];
169
- })
170
- );
189
+ return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
190
+ for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
191
+ return [key, value];
192
+ }));
171
193
  }
172
194
  async function interopDefault(m) {
173
- const resolved = await m;
174
- return resolved.default || resolved;
195
+ const resolved = await m;
196
+ return resolved.default || resolved;
175
197
  }
176
198
  function isPackageInScope(name) {
177
- return isPackageExists(name, { paths: [scopeUrl] });
199
+ return isPackageExists(name, { paths: [scopeUrl] });
178
200
  }
179
201
  async function ensurePackages(packages) {
180
- if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) {
181
- return;
182
- }
183
- const nonExistingPackages = packages.filter(
184
- (i) => i && !isPackageInScope(i)
185
- );
186
- if (nonExistingPackages.length === 0) {
187
- return;
188
- }
189
- const p = await import("@clack/prompts");
190
- const result = await p.confirm({
191
- message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(
192
- ", "
193
- )}. Do you want to install them?`
194
- });
195
- if (result) {
196
- await import("@antfu/install-pkg").then(
197
- (i) => i.installPackage(nonExistingPackages, { dev: true })
198
- );
199
- }
202
+ if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false) return;
203
+ const nonExistingPackages = packages.filter((i) => i && !isPackageInScope(i));
204
+ if (nonExistingPackages.length === 0) return;
205
+ const p = await import("@clack/prompts");
206
+ const result = await p.confirm({ message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(", ")}. Do you want to install them?` });
207
+ if (result) await import("@antfu/install-pkg").then((i) => i.installPackage(nonExistingPackages, { dev: true }));
200
208
  }
201
209
  function isInEditorEnv() {
202
- if (process.env.CI) {
203
- return false;
204
- }
205
- if (isInGitHooksOrLintStaged()) {
206
- return false;
207
- }
208
- return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
210
+ if (process.env.CI) return false;
211
+ if (isInGitHooksOrLintStaged()) return false;
212
+ return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
209
213
  }
210
214
  function isInGitHooksOrLintStaged() {
211
- return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
215
+ return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged"));
212
216
  }
213
217
 
214
- // src/configs/stylistic.ts
215
- var StylisticConfigDefaults = {
216
- indent: 2,
217
- jsx: true,
218
- quotes: "single",
219
- semi: false
218
+ //#endregion
219
+ //#region src/configs/effector.ts
220
+ async function effector(options = {}) {
221
+ const { future = false, overrides = {}, patronum = isPackageExists("patronum"), react: react$1 = ReactPackages.some((i) => isPackageExists(i)), scope = false } = options;
222
+ await ensurePackages(["eslint-plugin-effector"]);
223
+ const [pluginEffector] = await Promise.all([interopDefault(import("eslint-plugin-effector"))]);
224
+ return [{
225
+ name: "effector/setup",
226
+ plugins: { effector: pluginEffector }
227
+ }, {
228
+ name: "effector/rules",
229
+ rules: {
230
+ "effector/enforce-effect-naming-convention": "error",
231
+ "effector/enforce-store-naming-convention": "error",
232
+ "effector/keep-options-order": "warn",
233
+ "effector/no-ambiguity-target": "warn",
234
+ "effector/no-duplicate-on": "error",
235
+ "effector/no-getState": "error",
236
+ "effector/no-unnecessary-combination": "warn",
237
+ "effector/no-unnecessary-duplication": "warn",
238
+ "effector/no-useless-methods": "error",
239
+ "effector/no-watch": "warn",
240
+ "effector/prefer-sample-over-forward-with-mapping": "warn",
241
+ ...react$1 ? {
242
+ "effector/enforce-gate-naming-convention": "error",
243
+ "effector/mandatory-scope-binding": "error",
244
+ "effector/prefer-useUnit": "warn"
245
+ } : {},
246
+ ...patronum ? { "effector/no-patronum-debug": "error" } : {},
247
+ ...scope ? {
248
+ "effector/require-pickup-in-persist": "error",
249
+ "effector/strict-effect-handlers": "error"
250
+ } : {},
251
+ ...future ? {
252
+ "effector/no-forward": "warn",
253
+ "effector/no-guard": "warn",
254
+ "effector/prefer-sample-over-forward-with-mapping": "off"
255
+ } : {},
256
+ ...overrides
257
+ }
258
+ }];
259
+ }
260
+
261
+ //#endregion
262
+ //#region src/configs/stylistic.ts
263
+ const StylisticConfigDefaults = {
264
+ indent: 2,
265
+ jsx: true,
266
+ quotes: "single",
267
+ semi: false
220
268
  };
221
269
  async function stylistic(options = {}) {
222
- const {
223
- indent,
224
- jsx: jsx2,
225
- overrides = {},
226
- quotes,
227
- semi
228
- } = {
229
- ...StylisticConfigDefaults,
230
- ...options
231
- };
232
- const pluginStylistic = await interopDefault(
233
- import("@stylistic/eslint-plugin")
234
- );
235
- const config2 = pluginStylistic.configs.customize({
236
- indent,
237
- jsx: jsx2,
238
- pluginName: "style",
239
- quotes,
240
- semi
241
- });
242
- return [
243
- {
244
- name: "stylistic/rules",
245
- plugins: {
246
- antfu: default3,
247
- style: pluginStylistic
248
- },
249
- rules: {
250
- ...config2.rules,
251
- "antfu/consistent-chaining": "error",
252
- "antfu/consistent-list-newline": "error",
253
- "antfu/curly": "error",
254
- "antfu/if-newline": "error",
255
- "antfu/top-level-function": "error",
256
- "style/generator-star-spacing": [
257
- "error",
258
- { after: true, before: false }
259
- ],
260
- "style/yield-star-spacing": ["error", { after: true, before: false }],
261
- ...overrides
262
- }
263
- }
264
- ];
270
+ const { indent, jsx: jsx$1, overrides = {}, quotes, semi } = {
271
+ ...StylisticConfigDefaults,
272
+ ...options
273
+ };
274
+ const pluginStylistic = await interopDefault(import("@stylistic/eslint-plugin"));
275
+ const config$1 = pluginStylistic.configs.customize({
276
+ indent,
277
+ jsx: jsx$1,
278
+ pluginName: "style",
279
+ quotes,
280
+ semi
281
+ });
282
+ return [{
283
+ name: "stylistic/rules",
284
+ plugins: {
285
+ antfu: pluginAntfu,
286
+ style: pluginStylistic
287
+ },
288
+ rules: {
289
+ ...config$1.rules,
290
+ "antfu/consistent-chaining": "error",
291
+ "antfu/consistent-list-newline": "error",
292
+ "antfu/curly": "error",
293
+ "antfu/if-newline": "error",
294
+ "antfu/top-level-function": "error",
295
+ "style/generator-star-spacing": ["error", {
296
+ after: true,
297
+ before: false
298
+ }],
299
+ "style/yield-star-spacing": ["error", {
300
+ after: true,
301
+ before: false
302
+ }],
303
+ ...overrides
304
+ }
305
+ }];
265
306
  }
266
307
 
267
- // src/configs/formatters.ts
308
+ //#endregion
309
+ //#region src/configs/formatters.ts
268
310
  function mergePrettierOptions(options, overrides = {}) {
269
- return {
270
- ...options,
271
- ...overrides,
272
- plugins: [...overrides.plugins || [], ...options.plugins || []]
273
- };
311
+ return {
312
+ ...options,
313
+ ...overrides,
314
+ plugins: [...overrides.plugins || [], ...options.plugins || []]
315
+ };
274
316
  }
275
- async function formatters(options = {}, stylistic2 = {}) {
276
- if (options === true) {
277
- const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
278
- options = {
279
- css: true,
280
- html: true,
281
- markdown: true,
282
- svg: isPrettierPluginXmlInScope,
283
- xml: isPrettierPluginXmlInScope
284
- };
285
- }
286
- await ensurePackages([
287
- "eslint-plugin-format",
288
- options.xml || options.svg ? "@prettier/plugin-xml" : void 0
289
- ]);
290
- const { indent, quotes, semi } = {
291
- ...StylisticConfigDefaults,
292
- ...stylistic2
293
- };
294
- const prettierOptions = Object.assign(
295
- {
296
- endOfLine: "auto",
297
- printWidth: 120,
298
- semi,
299
- singleQuote: quotes === "single",
300
- tabWidth: typeof indent === "number" ? indent : 2,
301
- trailingComma: "all",
302
- useTabs: indent === "tab"
303
- },
304
- options.prettierOptions || {}
305
- );
306
- const prettierXmlOptions = {
307
- xmlQuoteAttributes: "double",
308
- xmlSelfClosingSpace: true,
309
- xmlSortAttributesByKey: false,
310
- xmlWhitespaceSensitivity: "ignore"
311
- };
312
- const pluginFormat = await interopDefault(import("eslint-plugin-format"));
313
- const configs2 = [
314
- {
315
- name: "formatter/setup",
316
- plugins: {
317
- format: pluginFormat
318
- }
319
- }
320
- ];
321
- if (options.css) {
322
- configs2.push(
323
- {
324
- files: [GLOB_CSS, GLOB_POSTCSS],
325
- languageOptions: {
326
- parser: parserPlain
327
- },
328
- name: "formatter/css",
329
- rules: {
330
- "format/prettier": [
331
- "error",
332
- mergePrettierOptions(prettierOptions, {
333
- parser: "css"
334
- })
335
- ]
336
- }
337
- },
338
- {
339
- files: [GLOB_SCSS],
340
- languageOptions: {
341
- parser: parserPlain
342
- },
343
- name: "formatter/scss",
344
- rules: {
345
- "format/prettier": [
346
- "error",
347
- mergePrettierOptions(prettierOptions, {
348
- parser: "scss"
349
- })
350
- ]
351
- }
352
- }
353
- );
354
- }
355
- if (options.html) {
356
- configs2.push({
357
- files: [GLOB_HTML],
358
- languageOptions: {
359
- parser: parserPlain
360
- },
361
- name: "formatter/html",
362
- rules: {
363
- "format/prettier": [
364
- "error",
365
- mergePrettierOptions(prettierOptions, {
366
- parser: "html"
367
- })
368
- ]
369
- }
370
- });
371
- }
372
- if (options.xml) {
373
- configs2.push({
374
- files: [GLOB_XML],
375
- languageOptions: {
376
- parser: parserPlain
377
- },
378
- name: "formatter/xml",
379
- rules: {
380
- "format/prettier": [
381
- "error",
382
- mergePrettierOptions(
383
- { ...prettierXmlOptions, ...prettierOptions },
384
- {
385
- parser: "xml",
386
- plugins: ["@prettier/plugin-xml"]
387
- }
388
- )
389
- ]
390
- }
391
- });
392
- }
393
- if (options.svg) {
394
- configs2.push({
395
- files: [GLOB_SVG],
396
- languageOptions: {
397
- parser: parserPlain
398
- },
399
- name: "formatter/svg",
400
- rules: {
401
- "format/prettier": [
402
- "error",
403
- mergePrettierOptions(
404
- { ...prettierXmlOptions, ...prettierOptions },
405
- {
406
- parser: "xml",
407
- plugins: ["@prettier/plugin-xml"]
408
- }
409
- )
410
- ]
411
- }
412
- });
413
- }
414
- if (options.markdown) {
415
- configs2.push({
416
- files: [GLOB_MARKDOWN],
417
- languageOptions: {
418
- parser: parserPlain
419
- },
420
- name: "formatter/markdown",
421
- rules: {
422
- "format/prettier": [
423
- "error",
424
- mergePrettierOptions(prettierOptions, {
425
- embeddedLanguageFormatting: "off",
426
- parser: "markdown"
427
- })
428
- ]
429
- }
430
- });
431
- }
432
- return configs2;
317
+ async function formatters(options = {}, stylistic$1 = {}) {
318
+ if (options === true) {
319
+ const isPrettierPluginXmlInScope = isPackageInScope("@prettier/plugin-xml");
320
+ options = {
321
+ css: true,
322
+ html: true,
323
+ markdown: true,
324
+ svg: isPrettierPluginXmlInScope,
325
+ xml: isPrettierPluginXmlInScope
326
+ };
327
+ }
328
+ await ensurePackages(["eslint-plugin-format", options.xml || options.svg ? "@prettier/plugin-xml" : void 0]);
329
+ const { indent, quotes, semi } = {
330
+ ...StylisticConfigDefaults,
331
+ ...stylistic$1
332
+ };
333
+ const prettierOptions = Object.assign({
334
+ endOfLine: "auto",
335
+ printWidth: 120,
336
+ semi,
337
+ singleQuote: quotes === "single",
338
+ tabWidth: typeof indent === "number" ? indent : 2,
339
+ trailingComma: "all",
340
+ useTabs: indent === "tab"
341
+ }, options.prettierOptions || {});
342
+ const prettierXmlOptions = {
343
+ xmlQuoteAttributes: "double",
344
+ xmlSelfClosingSpace: true,
345
+ xmlSortAttributesByKey: false,
346
+ xmlWhitespaceSensitivity: "ignore"
347
+ };
348
+ const pluginFormat = await interopDefault(import("eslint-plugin-format"));
349
+ const configs$1 = [{
350
+ name: "formatter/setup",
351
+ plugins: { format: pluginFormat }
352
+ }];
353
+ if (options.css) configs$1.push({
354
+ files: [GLOB_CSS, GLOB_POSTCSS],
355
+ languageOptions: { parser: parserPlain },
356
+ name: "formatter/css",
357
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "css" })] }
358
+ }, {
359
+ files: [GLOB_SCSS],
360
+ languageOptions: { parser: parserPlain },
361
+ name: "formatter/scss",
362
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "scss" })] }
363
+ });
364
+ if (options.html) configs$1.push({
365
+ files: [GLOB_HTML],
366
+ languageOptions: { parser: parserPlain },
367
+ name: "formatter/html",
368
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, { parser: "html" })] }
369
+ });
370
+ if (options.xml) configs$1.push({
371
+ files: [GLOB_XML],
372
+ languageOptions: { parser: parserPlain },
373
+ name: "formatter/xml",
374
+ rules: { "format/prettier": ["error", mergePrettierOptions({
375
+ ...prettierXmlOptions,
376
+ ...prettierOptions
377
+ }, {
378
+ parser: "xml",
379
+ plugins: ["@prettier/plugin-xml"]
380
+ })] }
381
+ });
382
+ if (options.svg) configs$1.push({
383
+ files: [GLOB_SVG],
384
+ languageOptions: { parser: parserPlain },
385
+ name: "formatter/svg",
386
+ rules: { "format/prettier": ["error", mergePrettierOptions({
387
+ ...prettierXmlOptions,
388
+ ...prettierOptions
389
+ }, {
390
+ parser: "xml",
391
+ plugins: ["@prettier/plugin-xml"]
392
+ })] }
393
+ });
394
+ if (options.markdown) configs$1.push({
395
+ files: [GLOB_MARKDOWN],
396
+ languageOptions: { parser: parserPlain },
397
+ name: "formatter/markdown",
398
+ rules: { "format/prettier": ["error", mergePrettierOptions(prettierOptions, {
399
+ embeddedLanguageFormatting: "off",
400
+ parser: "markdown"
401
+ })] }
402
+ });
403
+ return configs$1;
433
404
  }
434
405
 
435
- // src/configs/ignores.ts
406
+ //#endregion
407
+ //#region src/configs/ignores.ts
436
408
  async function ignores(userIgnores = []) {
437
- return [
438
- {
439
- ignores: [...GLOB_EXCLUDE, ...userIgnores],
440
- name: "ignores"
441
- }
442
- ];
409
+ return [{
410
+ ignores: [...GLOB_EXCLUDE, ...userIgnores],
411
+ name: "ignores"
412
+ }];
443
413
  }
444
414
 
445
- // src/configs/imports.ts
415
+ //#endregion
416
+ //#region src/configs/imports.ts
446
417
  async function imports(options = {}) {
447
- const { stylistic: stylistic2 = true } = options;
448
- return [
449
- {
450
- name: "imports/rules",
451
- plugins: {
452
- antfu: default3,
453
- import: pluginImport
454
- },
455
- rules: {
456
- "antfu/import-dedupe": "error",
457
- "antfu/no-import-dist": "error",
458
- "antfu/no-import-node-modules-by-path": "error",
459
- "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
460
- "import/first": "error",
461
- "import/no-duplicates": "error",
462
- "import/no-mutable-exports": "error",
463
- "import/no-named-default": "error",
464
- "import/no-self-import": "error",
465
- "import/no-webpack-loader-syntax": "error",
466
- ...stylistic2 ? {
467
- "import/newline-after-import": ["error", { count: 1 }]
468
- } : {}
469
- }
470
- }
471
- ];
418
+ const { stylistic: stylistic$1 = true } = options;
419
+ return [{
420
+ name: "imports/rules",
421
+ plugins: {
422
+ antfu: pluginAntfu,
423
+ import: pluginImport
424
+ },
425
+ rules: {
426
+ "antfu/import-dedupe": "error",
427
+ "antfu/no-import-dist": "error",
428
+ "antfu/no-import-node-modules-by-path": "error",
429
+ "import/consistent-type-specifier-style": ["error", "prefer-top-level"],
430
+ "import/first": "error",
431
+ "import/no-duplicates": "error",
432
+ "import/no-mutable-exports": "error",
433
+ "import/no-named-default": "error",
434
+ "import/no-self-import": "error",
435
+ "import/no-webpack-loader-syntax": "error",
436
+ ...stylistic$1 ? { "import/newline-after-import": ["error", { count: 1 }] } : {}
437
+ }
438
+ }];
472
439
  }
473
440
 
474
- // src/configs/javascript.ts
475
- import globals from "globals";
441
+ //#endregion
442
+ //#region src/configs/javascript.ts
476
443
  async function javascript(options = {}) {
477
- const { isInEditor = false, overrides = {} } = options;
478
- return [
479
- {
480
- languageOptions: {
481
- ecmaVersion: 2022,
482
- globals: {
483
- ...globals.browser,
484
- ...globals.es2021,
485
- ...globals.node,
486
- document: "readonly",
487
- navigator: "readonly",
488
- window: "readonly"
489
- },
490
- parserOptions: {
491
- ecmaFeatures: {
492
- jsx: true
493
- },
494
- ecmaVersion: 2022,
495
- sourceType: "module"
496
- },
497
- sourceType: "module"
498
- },
499
- linterOptions: {
500
- reportUnusedDisableDirectives: true
501
- },
502
- name: "javascript/setup"
503
- },
504
- {
505
- name: "javascript/rules",
506
- plugins: {
507
- "antfu": default3,
508
- "unused-imports": default7
509
- },
510
- rules: {
511
- "accessor-pairs": [
512
- "error",
513
- { enforceForClassMembers: true, setWithoutGet: true }
514
- ],
515
- "antfu/no-top-level-await": "error",
516
- "array-callback-return": "error",
517
- "block-scoped-var": "error",
518
- "constructor-super": "error",
519
- "default-case-last": "error",
520
- "dot-notation": ["error", { allowKeywords: true }],
521
- "eqeqeq": ["error", "smart"],
522
- "new-cap": [
523
- "error",
524
- { capIsNew: false, newIsCap: true, properties: true }
525
- ],
526
- "no-alert": "error",
527
- "no-array-constructor": "error",
528
- "no-async-promise-executor": "error",
529
- "no-caller": "error",
530
- "no-case-declarations": "error",
531
- "no-class-assign": "error",
532
- "no-compare-neg-zero": "error",
533
- "no-cond-assign": ["error", "always"],
534
- "no-console": ["error", { allow: ["warn", "error"] }],
535
- "no-const-assign": "error",
536
- "no-control-regex": "error",
537
- "no-debugger": "error",
538
- "no-delete-var": "error",
539
- "no-dupe-args": "error",
540
- "no-dupe-class-members": "error",
541
- "no-dupe-keys": "error",
542
- "no-duplicate-case": "error",
543
- "no-empty": ["error", { allowEmptyCatch: true }],
544
- "no-empty-character-class": "error",
545
- "no-empty-pattern": "error",
546
- "no-eval": "error",
547
- "no-ex-assign": "error",
548
- "no-extend-native": "error",
549
- "no-extra-bind": "error",
550
- "no-extra-boolean-cast": "error",
551
- "no-fallthrough": "error",
552
- "no-func-assign": "error",
553
- "no-global-assign": "error",
554
- "no-implied-eval": "error",
555
- "no-import-assign": "error",
556
- "no-invalid-regexp": "error",
557
- "no-irregular-whitespace": "error",
558
- "no-iterator": "error",
559
- "no-labels": ["error", { allowLoop: false, allowSwitch: false }],
560
- "no-lone-blocks": "error",
561
- "no-loss-of-precision": "error",
562
- "no-misleading-character-class": "error",
563
- "no-multi-str": "error",
564
- "no-new": "error",
565
- "no-new-func": "error",
566
- "no-new-native-nonconstructor": "error",
567
- "no-new-wrappers": "error",
568
- "no-obj-calls": "error",
569
- "no-octal": "error",
570
- "no-octal-escape": "error",
571
- "no-proto": "error",
572
- "no-prototype-builtins": "error",
573
- "no-redeclare": ["error", { builtinGlobals: false }],
574
- "no-regex-spaces": "error",
575
- "no-restricted-globals": [
576
- "error",
577
- { message: "Use `globalThis` instead.", name: "global" },
578
- { message: "Use `globalThis` instead.", name: "self" }
579
- ],
580
- "no-restricted-properties": [
581
- "error",
582
- {
583
- message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
584
- property: "__proto__"
585
- },
586
- {
587
- message: "Use `Object.defineProperty` instead.",
588
- property: "__defineGetter__"
589
- },
590
- {
591
- message: "Use `Object.defineProperty` instead.",
592
- property: "__defineSetter__"
593
- },
594
- {
595
- message: "Use `Object.getOwnPropertyDescriptor` instead.",
596
- property: "__lookupGetter__"
597
- },
598
- {
599
- message: "Use `Object.getOwnPropertyDescriptor` instead.",
600
- property: "__lookupSetter__"
601
- }
602
- ],
603
- "no-restricted-syntax": [
604
- "error",
605
- "TSEnumDeclaration[const=true]",
606
- "TSExportAssignment"
607
- ],
608
- "no-self-assign": ["error", { props: true }],
609
- "no-self-compare": "error",
610
- "no-sequences": "error",
611
- "no-shadow-restricted-names": "error",
612
- "no-sparse-arrays": "error",
613
- "no-template-curly-in-string": "error",
614
- "no-this-before-super": "error",
615
- "no-throw-literal": "error",
616
- "no-undef": "error",
617
- "no-undef-init": "error",
618
- "no-unexpected-multiline": "error",
619
- "no-unmodified-loop-condition": "error",
620
- "no-unneeded-ternary": ["error", { defaultAssignment: false }],
621
- "no-unreachable": "error",
622
- "no-unreachable-loop": "error",
623
- "no-unsafe-finally": "error",
624
- "no-unsafe-negation": "error",
625
- "no-unused-expressions": [
626
- "error",
627
- {
628
- allowShortCircuit: true,
629
- allowTaggedTemplates: true,
630
- allowTernary: true
631
- }
632
- ],
633
- "no-unused-vars": [
634
- "error",
635
- {
636
- args: "none",
637
- caughtErrors: "none",
638
- ignoreRestSiblings: true,
639
- vars: "all"
640
- }
641
- ],
642
- "no-use-before-define": [
643
- "error",
644
- { classes: false, functions: false, variables: true }
645
- ],
646
- "no-useless-backreference": "error",
647
- "no-useless-call": "error",
648
- "no-useless-catch": "error",
649
- "no-useless-computed-key": "error",
650
- "no-useless-constructor": "error",
651
- "no-useless-rename": "error",
652
- "no-useless-return": "error",
653
- "no-var": "error",
654
- "no-with": "error",
655
- "object-shorthand": [
656
- "error",
657
- "always",
658
- {
659
- avoidQuotes: true,
660
- ignoreConstructors: false
661
- }
662
- ],
663
- "one-var": ["error", { initialized: "never" }],
664
- "prefer-arrow-callback": [
665
- "error",
666
- {
667
- allowNamedFunctions: false,
668
- allowUnboundThis: true
669
- }
670
- ],
671
- "prefer-const": [
672
- isInEditor ? "warn" : "error",
673
- {
674
- destructuring: "all",
675
- ignoreReadBeforeAssign: true
676
- }
677
- ],
678
- "prefer-exponentiation-operator": "error",
679
- "prefer-promise-reject-errors": "error",
680
- "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
681
- "prefer-rest-params": "error",
682
- "prefer-spread": "error",
683
- "prefer-template": "error",
684
- "symbol-description": "error",
685
- "unicode-bom": ["error", "never"],
686
- "unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
687
- "unused-imports/no-unused-vars": [
688
- "error",
689
- {
690
- args: "after-used",
691
- argsIgnorePattern: "^_",
692
- ignoreRestSiblings: true,
693
- vars: "all",
694
- varsIgnorePattern: "^_"
695
- }
696
- ],
697
- "use-isnan": [
698
- "error",
699
- { enforceForIndexOf: true, enforceForSwitchCase: true }
700
- ],
701
- "valid-typeof": ["error", { requireStringLiterals: true }],
702
- "vars-on-top": "error",
703
- "yoda": ["error", "never"],
704
- ...overrides
705
- }
706
- }
707
- ];
444
+ const { isInEditor = false, overrides = {} } = options;
445
+ return [{
446
+ languageOptions: {
447
+ ecmaVersion: 2022,
448
+ globals: {
449
+ ...globals.browser,
450
+ ...globals.es2021,
451
+ ...globals.node,
452
+ document: "readonly",
453
+ navigator: "readonly",
454
+ window: "readonly"
455
+ },
456
+ parserOptions: {
457
+ ecmaFeatures: { jsx: true },
458
+ ecmaVersion: 2022,
459
+ sourceType: "module"
460
+ },
461
+ sourceType: "module"
462
+ },
463
+ linterOptions: { reportUnusedDisableDirectives: true },
464
+ name: "javascript/setup"
465
+ }, {
466
+ name: "javascript/rules",
467
+ plugins: {
468
+ "antfu": pluginAntfu,
469
+ "unused-imports": pluginUnusedImports
470
+ },
471
+ rules: {
472
+ "accessor-pairs": ["error", {
473
+ enforceForClassMembers: true,
474
+ setWithoutGet: true
475
+ }],
476
+ "antfu/no-top-level-await": "error",
477
+ "array-callback-return": "error",
478
+ "block-scoped-var": "error",
479
+ "constructor-super": "error",
480
+ "default-case-last": "error",
481
+ "dot-notation": ["error", { allowKeywords: true }],
482
+ "eqeqeq": ["error", "smart"],
483
+ "new-cap": ["error", {
484
+ capIsNew: false,
485
+ newIsCap: true,
486
+ properties: true
487
+ }],
488
+ "no-alert": "error",
489
+ "no-array-constructor": "error",
490
+ "no-async-promise-executor": "error",
491
+ "no-caller": "error",
492
+ "no-case-declarations": "error",
493
+ "no-class-assign": "error",
494
+ "no-compare-neg-zero": "error",
495
+ "no-cond-assign": ["error", "always"],
496
+ "no-console": ["error", { allow: ["warn", "error"] }],
497
+ "no-const-assign": "error",
498
+ "no-control-regex": "error",
499
+ "no-debugger": "error",
500
+ "no-delete-var": "error",
501
+ "no-dupe-args": "error",
502
+ "no-dupe-class-members": "error",
503
+ "no-dupe-keys": "error",
504
+ "no-duplicate-case": "error",
505
+ "no-empty": ["error", { allowEmptyCatch: true }],
506
+ "no-empty-character-class": "error",
507
+ "no-empty-pattern": "error",
508
+ "no-eval": "error",
509
+ "no-ex-assign": "error",
510
+ "no-extend-native": "error",
511
+ "no-extra-bind": "error",
512
+ "no-extra-boolean-cast": "error",
513
+ "no-fallthrough": "error",
514
+ "no-func-assign": "error",
515
+ "no-global-assign": "error",
516
+ "no-implied-eval": "error",
517
+ "no-import-assign": "error",
518
+ "no-invalid-regexp": "error",
519
+ "no-irregular-whitespace": "error",
520
+ "no-iterator": "error",
521
+ "no-labels": ["error", {
522
+ allowLoop: false,
523
+ allowSwitch: false
524
+ }],
525
+ "no-lone-blocks": "error",
526
+ "no-loss-of-precision": "error",
527
+ "no-misleading-character-class": "error",
528
+ "no-multi-str": "error",
529
+ "no-new": "error",
530
+ "no-new-func": "error",
531
+ "no-new-native-nonconstructor": "error",
532
+ "no-new-wrappers": "error",
533
+ "no-obj-calls": "error",
534
+ "no-octal": "error",
535
+ "no-octal-escape": "error",
536
+ "no-proto": "error",
537
+ "no-prototype-builtins": "error",
538
+ "no-redeclare": ["error", { builtinGlobals: false }],
539
+ "no-regex-spaces": "error",
540
+ "no-restricted-globals": [
541
+ "error",
542
+ {
543
+ message: "Use `globalThis` instead.",
544
+ name: "global"
545
+ },
546
+ {
547
+ message: "Use `globalThis` instead.",
548
+ name: "self"
549
+ }
550
+ ],
551
+ "no-restricted-properties": [
552
+ "error",
553
+ {
554
+ message: "Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.",
555
+ property: "__proto__"
556
+ },
557
+ {
558
+ message: "Use `Object.defineProperty` instead.",
559
+ property: "__defineGetter__"
560
+ },
561
+ {
562
+ message: "Use `Object.defineProperty` instead.",
563
+ property: "__defineSetter__"
564
+ },
565
+ {
566
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
567
+ property: "__lookupGetter__"
568
+ },
569
+ {
570
+ message: "Use `Object.getOwnPropertyDescriptor` instead.",
571
+ property: "__lookupSetter__"
572
+ }
573
+ ],
574
+ "no-restricted-syntax": [
575
+ "error",
576
+ "TSEnumDeclaration[const=true]",
577
+ "TSExportAssignment"
578
+ ],
579
+ "no-self-assign": ["error", { props: true }],
580
+ "no-self-compare": "error",
581
+ "no-sequences": "error",
582
+ "no-shadow-restricted-names": "error",
583
+ "no-sparse-arrays": "error",
584
+ "no-template-curly-in-string": "error",
585
+ "no-this-before-super": "error",
586
+ "no-throw-literal": "error",
587
+ "no-undef": "error",
588
+ "no-undef-init": "error",
589
+ "no-unexpected-multiline": "error",
590
+ "no-unmodified-loop-condition": "error",
591
+ "no-unneeded-ternary": ["error", { defaultAssignment: false }],
592
+ "no-unreachable": "error",
593
+ "no-unreachable-loop": "error",
594
+ "no-unsafe-finally": "error",
595
+ "no-unsafe-negation": "error",
596
+ "no-unused-expressions": ["error", {
597
+ allowShortCircuit: true,
598
+ allowTaggedTemplates: true,
599
+ allowTernary: true
600
+ }],
601
+ "no-unused-vars": ["error", {
602
+ args: "none",
603
+ caughtErrors: "none",
604
+ ignoreRestSiblings: true,
605
+ vars: "all"
606
+ }],
607
+ "no-use-before-define": ["error", {
608
+ classes: false,
609
+ functions: false,
610
+ variables: true
611
+ }],
612
+ "no-useless-backreference": "error",
613
+ "no-useless-call": "error",
614
+ "no-useless-catch": "error",
615
+ "no-useless-computed-key": "error",
616
+ "no-useless-constructor": "error",
617
+ "no-useless-rename": "error",
618
+ "no-useless-return": "error",
619
+ "no-var": "error",
620
+ "no-with": "error",
621
+ "object-shorthand": [
622
+ "error",
623
+ "always",
624
+ {
625
+ avoidQuotes: true,
626
+ ignoreConstructors: false
627
+ }
628
+ ],
629
+ "one-var": ["error", { initialized: "never" }],
630
+ "prefer-arrow-callback": ["error", {
631
+ allowNamedFunctions: false,
632
+ allowUnboundThis: true
633
+ }],
634
+ "prefer-const": [isInEditor ? "warn" : "error", {
635
+ destructuring: "all",
636
+ ignoreReadBeforeAssign: true
637
+ }],
638
+ "prefer-exponentiation-operator": "error",
639
+ "prefer-promise-reject-errors": "error",
640
+ "prefer-regex-literals": ["error", { disallowRedundantWrapping: true }],
641
+ "prefer-rest-params": "error",
642
+ "prefer-spread": "error",
643
+ "prefer-template": "error",
644
+ "symbol-description": "error",
645
+ "unicode-bom": ["error", "never"],
646
+ "unused-imports/no-unused-imports": isInEditor ? "warn" : "error",
647
+ "unused-imports/no-unused-vars": ["error", {
648
+ args: "after-used",
649
+ argsIgnorePattern: "^_",
650
+ ignoreRestSiblings: true,
651
+ vars: "all",
652
+ varsIgnorePattern: "^_"
653
+ }],
654
+ "use-isnan": ["error", {
655
+ enforceForIndexOf: true,
656
+ enforceForSwitchCase: true
657
+ }],
658
+ "valid-typeof": ["error", { requireStringLiterals: true }],
659
+ "vars-on-top": "error",
660
+ "yoda": ["error", "never"],
661
+ ...overrides
662
+ }
663
+ }];
708
664
  }
709
665
 
710
- // src/configs/jsonc.ts
666
+ //#endregion
667
+ //#region src/configs/jsonc.ts
711
668
  async function jsonc(options = {}) {
712
- const {
713
- files = [GLOB_JSON, GLOB_JSON5, GLOB_JSONC],
714
- overrides = {},
715
- stylistic: stylistic2 = true
716
- } = options;
717
- const { indent = 2 } = typeof stylistic2 === "boolean" ? {} : stylistic2;
718
- const [pluginJsonc, parserJsonc] = await Promise.all([
719
- interopDefault(import("eslint-plugin-jsonc")),
720
- interopDefault(import("jsonc-eslint-parser"))
721
- ]);
722
- return [
723
- {
724
- name: "jsonc/setup",
725
- plugins: {
726
- jsonc: pluginJsonc
727
- }
728
- },
729
- {
730
- files,
731
- languageOptions: {
732
- parser: parserJsonc
733
- },
734
- name: "jsonc/rules",
735
- rules: {
736
- "jsonc/no-bigint-literals": "error",
737
- "jsonc/no-binary-expression": "error",
738
- "jsonc/no-binary-numeric-literals": "error",
739
- "jsonc/no-dupe-keys": "error",
740
- "jsonc/no-escape-sequence-in-identifier": "error",
741
- "jsonc/no-floating-decimal": "error",
742
- "jsonc/no-hexadecimal-numeric-literals": "error",
743
- "jsonc/no-infinity": "error",
744
- "jsonc/no-multi-str": "error",
745
- "jsonc/no-nan": "error",
746
- "jsonc/no-number-props": "error",
747
- "jsonc/no-numeric-separators": "error",
748
- "jsonc/no-octal": "error",
749
- "jsonc/no-octal-escape": "error",
750
- "jsonc/no-octal-numeric-literals": "error",
751
- "jsonc/no-parenthesized": "error",
752
- "jsonc/no-plus-sign": "error",
753
- "jsonc/no-regexp-literals": "error",
754
- "jsonc/no-sparse-arrays": "error",
755
- "jsonc/no-template-literals": "error",
756
- "jsonc/no-undefined-value": "error",
757
- "jsonc/no-unicode-codepoint-escapes": "error",
758
- "jsonc/no-useless-escape": "error",
759
- "jsonc/space-unary-ops": "error",
760
- "jsonc/valid-json-number": "error",
761
- "jsonc/vue-custom-block/no-parsing-error": "error",
762
- ...stylistic2 ? {
763
- "jsonc/array-bracket-spacing": ["error", "never"],
764
- "jsonc/comma-dangle": ["error", "never"],
765
- "jsonc/comma-style": ["error", "last"],
766
- "jsonc/indent": ["error", indent],
767
- "jsonc/key-spacing": [
768
- "error",
769
- { afterColon: true, beforeColon: false }
770
- ],
771
- "jsonc/object-curly-newline": [
772
- "error",
773
- { consistent: true, multiline: true }
774
- ],
775
- "jsonc/object-curly-spacing": ["error", "always"],
776
- "jsonc/object-property-newline": [
777
- "error",
778
- { allowMultiplePropertiesPerLine: true }
779
- ],
780
- "jsonc/quote-props": "error",
781
- "jsonc/quotes": "error"
782
- } : {},
783
- ...overrides
784
- }
785
- }
786
- ];
669
+ const { files = [
670
+ GLOB_JSON,
671
+ GLOB_JSON5,
672
+ GLOB_JSONC
673
+ ], overrides = {}, stylistic: stylistic$1 = true } = options;
674
+ const { indent = 2 } = typeof stylistic$1 === "boolean" ? {} : stylistic$1;
675
+ const [pluginJsonc, parserJsonc] = await Promise.all([interopDefault(import("eslint-plugin-jsonc")), interopDefault(import("jsonc-eslint-parser"))]);
676
+ return [{
677
+ name: "jsonc/setup",
678
+ plugins: { jsonc: pluginJsonc }
679
+ }, {
680
+ files,
681
+ languageOptions: { parser: parserJsonc },
682
+ name: "jsonc/rules",
683
+ rules: {
684
+ "jsonc/no-bigint-literals": "error",
685
+ "jsonc/no-binary-expression": "error",
686
+ "jsonc/no-binary-numeric-literals": "error",
687
+ "jsonc/no-dupe-keys": "error",
688
+ "jsonc/no-escape-sequence-in-identifier": "error",
689
+ "jsonc/no-floating-decimal": "error",
690
+ "jsonc/no-hexadecimal-numeric-literals": "error",
691
+ "jsonc/no-infinity": "error",
692
+ "jsonc/no-multi-str": "error",
693
+ "jsonc/no-nan": "error",
694
+ "jsonc/no-number-props": "error",
695
+ "jsonc/no-numeric-separators": "error",
696
+ "jsonc/no-octal": "error",
697
+ "jsonc/no-octal-escape": "error",
698
+ "jsonc/no-octal-numeric-literals": "error",
699
+ "jsonc/no-parenthesized": "error",
700
+ "jsonc/no-plus-sign": "error",
701
+ "jsonc/no-regexp-literals": "error",
702
+ "jsonc/no-sparse-arrays": "error",
703
+ "jsonc/no-template-literals": "error",
704
+ "jsonc/no-undefined-value": "error",
705
+ "jsonc/no-unicode-codepoint-escapes": "error",
706
+ "jsonc/no-useless-escape": "error",
707
+ "jsonc/space-unary-ops": "error",
708
+ "jsonc/valid-json-number": "error",
709
+ "jsonc/vue-custom-block/no-parsing-error": "error",
710
+ ...stylistic$1 ? {
711
+ "jsonc/array-bracket-spacing": ["error", "never"],
712
+ "jsonc/comma-dangle": ["error", "never"],
713
+ "jsonc/comma-style": ["error", "last"],
714
+ "jsonc/indent": ["error", indent],
715
+ "jsonc/key-spacing": ["error", {
716
+ afterColon: true,
717
+ beforeColon: false
718
+ }],
719
+ "jsonc/object-curly-newline": ["error", {
720
+ consistent: true,
721
+ multiline: true
722
+ }],
723
+ "jsonc/object-curly-spacing": ["error", "always"],
724
+ "jsonc/object-property-newline": ["error", { allowMultiplePropertiesPerLine: true }],
725
+ "jsonc/quote-props": "error",
726
+ "jsonc/quotes": "error"
727
+ } : {},
728
+ ...overrides
729
+ }
730
+ }];
787
731
  }
788
732
 
789
- // src/configs/jsx.ts
733
+ //#endregion
734
+ //#region src/configs/jsx.ts
790
735
  async function jsx() {
791
- return [
792
- {
793
- files: [GLOB_JSX, GLOB_TSX],
794
- languageOptions: {
795
- parserOptions: {
796
- ecmaFeatures: {
797
- jsx: true
798
- }
799
- }
800
- },
801
- name: "jsx/setup"
802
- }
803
- ];
736
+ return [{
737
+ files: [GLOB_JSX, GLOB_TSX],
738
+ languageOptions: { parserOptions: { ecmaFeatures: { jsx: true } } },
739
+ name: "jsx/setup"
740
+ }];
804
741
  }
805
742
 
806
- // src/configs/markdown.ts
807
- import { mergeProcessors, processorPassThrough } from "eslint-merge-processors";
743
+ //#endregion
744
+ //#region src/configs/jsx-a11y.ts
745
+ async function jsxA11y(options = {}) {
746
+ const { overrides = {} } = options;
747
+ await ensurePackages(["eslint-plugin-jsx-a11y"]);
748
+ const [pluginJsxA11y] = await Promise.all([interopDefault(import("eslint-plugin-jsx-a11y"))]);
749
+ const isUsingNext = NextJsPackages.some((i) => isPackageExists(i));
750
+ return [{
751
+ name: "jsx-a11y/rules",
752
+ plugins: { "jsx-a11y": pluginJsxA11y },
753
+ rules: {
754
+ "jsx-a11y/alt-text": ["warn", {
755
+ elements: ["img"],
756
+ img: [...isUsingNext ? ["Image"] : []]
757
+ }],
758
+ "jsx-a11y/aria-props": "warn",
759
+ "jsx-a11y/aria-proptypes": "warn",
760
+ "jsx-a11y/aria-unsupported-elements": "warn",
761
+ "jsx-a11y/role-has-required-aria-props": "warn",
762
+ "jsx-a11y/role-supports-aria-props": "warn",
763
+ ...overrides
764
+ }
765
+ }];
766
+ }
767
+
768
+ //#endregion
769
+ //#region src/configs/markdown.ts
808
770
  async function markdown(options = {}) {
809
- const {
810
- componentExts = [],
811
- files = [GLOB_MARKDOWN],
812
- overrides = {}
813
- } = options;
814
- const markdown2 = await interopDefault(import("@eslint/markdown"));
815
- return [
816
- {
817
- name: "markdown/setup",
818
- plugins: {
819
- markdown: markdown2
820
- }
821
- },
822
- {
823
- files,
824
- ignores: [GLOB_MARKDOWN_IN_MARKDOWN],
825
- name: "markdown/processor",
826
- // `eslint-plugin-markdown` only creates virtual files for code blocks,
827
- // but not the markdown file itself. We use `eslint-merge-processors` to
828
- // add a pass-through processor for the markdown file itself.
829
- processor: mergeProcessors([
830
- markdown2.processors.markdown,
831
- processorPassThrough
832
- ])
833
- },
834
- {
835
- files,
836
- languageOptions: {
837
- parser: parserPlain
838
- },
839
- name: "markdown/parser"
840
- },
841
- {
842
- files: [
843
- GLOB_MARKDOWN_CODE,
844
- ...componentExts.map((ext) => `${GLOB_MARKDOWN}/**/*.${ext}`)
845
- ],
846
- languageOptions: {
847
- parserOptions: {
848
- ecmaFeatures: {
849
- impliedStrict: true
850
- }
851
- }
852
- },
853
- name: "markdown/disables",
854
- rules: {
855
- "antfu/no-top-level-await": "off",
856
- "import/newline-after-import": "off",
857
- "no-alert": "off",
858
- "no-console": "off",
859
- "no-labels": "off",
860
- "no-lone-blocks": "off",
861
- "no-restricted-syntax": "off",
862
- "no-undef": "off",
863
- "no-unused-expressions": "off",
864
- "no-unused-labels": "off",
865
- "no-unused-vars": "off",
866
- "node/prefer-global/process": "off",
867
- "style/comma-dangle": "off",
868
- "style/eol-last": "off",
869
- "ts/consistent-type-imports": "off",
870
- "ts/explicit-function-return-type": "off",
871
- "ts/no-namespace": "off",
872
- "ts/no-redeclare": "off",
873
- "ts/no-require-imports": "off",
874
- "ts/no-unused-expressions": "off",
875
- "ts/no-unused-vars": "off",
876
- "ts/no-use-before-define": "off",
877
- "unicode-bom": "off",
878
- "unused-imports/no-unused-imports": "off",
879
- "unused-imports/no-unused-vars": "off",
880
- ...overrides
881
- }
882
- }
883
- ];
771
+ const { componentExts = [], files = [GLOB_MARKDOWN], overrides = {} } = options;
772
+ const markdown$1 = await interopDefault(import("@eslint/markdown"));
773
+ return [
774
+ {
775
+ name: "markdown/setup",
776
+ plugins: { markdown: markdown$1 }
777
+ },
778
+ {
779
+ files,
780
+ ignores: [GLOB_MARKDOWN_IN_MARKDOWN],
781
+ name: "markdown/processor",
782
+ processor: mergeProcessors([markdown$1.processors.markdown, processorPassThrough])
783
+ },
784
+ {
785
+ files,
786
+ languageOptions: { parser: parserPlain },
787
+ name: "markdown/parser"
788
+ },
789
+ {
790
+ files: [GLOB_MARKDOWN_CODE, ...componentExts.map((ext) => `${GLOB_MARKDOWN}/**/*.${ext}`)],
791
+ languageOptions: { parserOptions: { ecmaFeatures: { impliedStrict: true } } },
792
+ name: "markdown/disables",
793
+ rules: {
794
+ "antfu/no-top-level-await": "off",
795
+ "import/newline-after-import": "off",
796
+ "no-alert": "off",
797
+ "no-console": "off",
798
+ "no-labels": "off",
799
+ "no-lone-blocks": "off",
800
+ "no-restricted-syntax": "off",
801
+ "no-undef": "off",
802
+ "no-unused-expressions": "off",
803
+ "no-unused-labels": "off",
804
+ "no-unused-vars": "off",
805
+ "node/prefer-global/process": "off",
806
+ "style/comma-dangle": "off",
807
+ "style/eol-last": "off",
808
+ "ts/consistent-type-imports": "off",
809
+ "ts/explicit-function-return-type": "off",
810
+ "ts/no-namespace": "off",
811
+ "ts/no-redeclare": "off",
812
+ "ts/no-require-imports": "off",
813
+ "ts/no-unused-expressions": "off",
814
+ "ts/no-unused-vars": "off",
815
+ "ts/no-use-before-define": "off",
816
+ "unicode-bom": "off",
817
+ "unused-imports/no-unused-imports": "off",
818
+ "unused-imports/no-unused-vars": "off",
819
+ ...overrides
820
+ }
821
+ }
822
+ ];
884
823
  }
885
824
 
886
- // src/configs/node.ts
825
+ //#endregion
826
+ //#region src/configs/next.ts
827
+ async function next(options = {}) {
828
+ const { overrides = {} } = options;
829
+ await ensurePackages(["@next/eslint-plugin-next"]);
830
+ const [pluginNext] = await Promise.all([interopDefault(import("@next/eslint-plugin-next"))]);
831
+ return [{
832
+ name: "next/rules",
833
+ plugins: { next: pluginNext },
834
+ rules: {
835
+ "next/google-font-display": "warn",
836
+ "next/google-font-preconnect": "warn",
837
+ "next/inline-script-id": "error",
838
+ "next/next-script-for-ga": "warn",
839
+ "next/no-assign-module-variable": "error",
840
+ "next/no-async-client-component": "warn",
841
+ "next/no-before-interactive-script-outside-document": "warn",
842
+ "next/no-css-tags": "warn",
843
+ "next/no-document-import-in-page": "error",
844
+ "next/no-duplicate-head": "error",
845
+ "next/no-head-element": "warn",
846
+ "next/no-head-import-in-document": "error",
847
+ "next/no-html-link-for-pages": "warn",
848
+ "next/no-img-element": "warn",
849
+ "next/no-page-custom-font": "warn",
850
+ "next/no-script-component-in-head": "error",
851
+ "next/no-styled-jsx-in-document": "warn",
852
+ "next/no-sync-scripts": "warn",
853
+ "next/no-title-in-document-head": "warn",
854
+ "next/no-typos": "warn",
855
+ "next/no-unwanted-polyfillio": "warn",
856
+ ...overrides
857
+ }
858
+ }];
859
+ }
860
+
861
+ //#endregion
862
+ //#region src/configs/node.ts
887
863
  async function node() {
888
- return [
889
- {
890
- name: "node/rules",
891
- plugins: {
892
- node: default4
893
- },
894
- rules: {
895
- "node/handle-callback-err": ["error", "^(err|error)$"],
896
- "node/no-deprecated-api": "error",
897
- "node/no-exports-assign": "error",
898
- "node/no-new-require": "error",
899
- "node/no-path-concat": "error",
900
- "node/prefer-global/buffer": ["error", "never"],
901
- "node/prefer-global/process": ["error", "never"],
902
- "node/process-exit-as-throw": "error"
903
- }
904
- }
905
- ];
864
+ return [{
865
+ name: "node/rules",
866
+ plugins: { node: pluginNode },
867
+ rules: {
868
+ "node/handle-callback-err": ["error", "^(err|error)$"],
869
+ "node/no-deprecated-api": "error",
870
+ "node/no-exports-assign": "error",
871
+ "node/no-new-require": "error",
872
+ "node/no-path-concat": "error",
873
+ "node/prefer-global/buffer": ["error", "never"],
874
+ "node/prefer-global/process": ["error", "never"],
875
+ "node/process-exit-as-throw": "error"
876
+ }
877
+ }];
906
878
  }
907
879
 
908
- // src/configs/perfectionist.ts
880
+ //#endregion
881
+ //#region src/configs/perfectionist.ts
882
+ /**
883
+ * Perfectionist plugin for props and items sorting.
884
+ *
885
+ * @see https://github.com/azat-io/eslint-plugin-perfectionist
886
+ */
909
887
  async function perfectionist() {
910
- return [
911
- {
912
- name: "perfectionist/setup",
913
- plugins: {
914
- perfectionist: default5
915
- },
916
- rules: {
917
- "perfectionist/sort-exports": [
918
- "error",
919
- { order: "asc", type: "natural" }
920
- ],
921
- "perfectionist/sort-imports": [
922
- "error",
923
- {
924
- groups: [
925
- "type",
926
- ["parent-type", "sibling-type", "index-type", "internal-type"],
927
- "builtin",
928
- "external",
929
- "internal",
930
- ["parent", "sibling", "index"],
931
- "side-effect",
932
- "object",
933
- "unknown"
934
- ],
935
- newlinesBetween: "always",
936
- order: "asc",
937
- type: "natural"
938
- }
939
- ],
940
- "perfectionist/sort-named-exports": [
941
- "error",
942
- { order: "asc", type: "natural" }
943
- ],
944
- "perfectionist/sort-named-imports": [
945
- "error",
946
- { order: "asc", type: "natural" }
947
- ]
948
- }
949
- }
950
- ];
888
+ return [{
889
+ name: "perfectionist/setup",
890
+ plugins: { perfectionist: pluginPerfectionist },
891
+ rules: {
892
+ "perfectionist/sort-exports": ["error", {
893
+ order: "asc",
894
+ type: "natural"
895
+ }],
896
+ "perfectionist/sort-imports": ["error", {
897
+ groups: [
898
+ "type",
899
+ [
900
+ "parent-type",
901
+ "sibling-type",
902
+ "index-type",
903
+ "internal-type"
904
+ ],
905
+ "builtin",
906
+ "external",
907
+ "internal",
908
+ [
909
+ "parent",
910
+ "sibling",
911
+ "index"
912
+ ],
913
+ "side-effect",
914
+ "object",
915
+ "unknown"
916
+ ],
917
+ newlinesBetween: "always",
918
+ order: "asc",
919
+ type: "natural"
920
+ }],
921
+ "perfectionist/sort-named-exports": ["error", {
922
+ order: "asc",
923
+ type: "natural"
924
+ }],
925
+ "perfectionist/sort-named-imports": ["error", {
926
+ order: "asc",
927
+ type: "natural"
928
+ }]
929
+ }
930
+ }];
951
931
  }
952
932
 
953
- // src/configs/pnpm.ts
933
+ //#endregion
934
+ //#region src/configs/pnpm.ts
954
935
  async function pnpm() {
955
- const [
956
- pluginPnpm,
957
- yamlParser,
958
- jsoncParser
959
- ] = await Promise.all([
960
- interopDefault(import("eslint-plugin-pnpm")),
961
- interopDefault(import("yaml-eslint-parser")),
962
- interopDefault(import("jsonc-eslint-parser"))
963
- ]);
964
- return [
965
- {
966
- files: [
967
- "package.json",
968
- "**/package.json"
969
- ],
970
- languageOptions: {
971
- parser: jsoncParser
972
- },
973
- name: "pnpm/package-json",
974
- plugins: {
975
- pnpm: pluginPnpm
976
- },
977
- rules: {
978
- "pnpm/json-enforce-catalog": "error",
979
- "pnpm/json-prefer-workspace-settings": "error",
980
- "pnpm/json-valid-catalog": "error"
981
- }
982
- },
983
- {
984
- files: ["pnpm-workspace.yaml"],
985
- languageOptions: {
986
- parser: yamlParser
987
- },
988
- name: "pnpm/pnpm-workspace-yaml",
989
- plugins: {
990
- pnpm: pluginPnpm
991
- },
992
- rules: {
993
- "pnpm/yaml-no-duplicate-catalog-item": "error",
994
- "pnpm/yaml-no-unused-catalog-item": "error"
995
- }
996
- }
997
- ];
936
+ const [pluginPnpm, yamlParser, jsoncParser] = await Promise.all([
937
+ interopDefault(import("eslint-plugin-pnpm")),
938
+ interopDefault(import("yaml-eslint-parser")),
939
+ interopDefault(import("jsonc-eslint-parser"))
940
+ ]);
941
+ return [{
942
+ files: ["package.json", "**/package.json"],
943
+ languageOptions: { parser: jsoncParser },
944
+ name: "pnpm/package-json",
945
+ plugins: { pnpm: pluginPnpm },
946
+ rules: {
947
+ "pnpm/json-enforce-catalog": "error",
948
+ "pnpm/json-prefer-workspace-settings": "error",
949
+ "pnpm/json-valid-catalog": "error"
950
+ }
951
+ }, {
952
+ files: ["pnpm-workspace.yaml"],
953
+ languageOptions: { parser: yamlParser },
954
+ name: "pnpm/pnpm-workspace-yaml",
955
+ plugins: { pnpm: pluginPnpm },
956
+ rules: {
957
+ "pnpm/yaml-no-duplicate-catalog-item": "error",
958
+ "pnpm/yaml-no-unused-catalog-item": "error"
959
+ }
960
+ }];
998
961
  }
999
962
 
1000
- // src/configs/react.ts
1001
- import { isPackageExists as isPackageExists2 } from "local-pkg";
1002
- var ReactRefreshAllowConstantExportPackages = ["vite"];
1003
- var ReactRouterPackages = [
1004
- "@react-router/node",
1005
- "@react-router/react",
1006
- "@react-router/serve",
1007
- "@react-router/dev"
1008
- ];
1009
- var NextJsPackages = ["next"];
963
+ //#endregion
964
+ //#region src/configs/react.ts
1010
965
  async function react(options = {}) {
1011
- const {
1012
- files = [GLOB_SRC],
1013
- filesTypeAware = [GLOB_TS, GLOB_TSX],
1014
- ignoresTypeAware = [`${GLOB_MARKDOWN}/**`],
1015
- overrides = {},
1016
- tsconfigPath
1017
- } = options;
1018
- const isTypeAware = !!tsconfigPath;
1019
- const typeAwareRules = {
1020
- "react/no-leaked-conditional-rendering": "warn"
1021
- };
1022
- const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all(
1023
- [
1024
- interopDefault(import("@eslint-react/eslint-plugin")),
1025
- interopDefault(import("eslint-plugin-react-hooks")),
1026
- interopDefault(import("eslint-plugin-react-refresh"))
1027
- ]
1028
- );
1029
- const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some(
1030
- (i) => isPackageExists2(i)
1031
- );
1032
- const isUsingReactRouter = ReactRouterPackages.some(
1033
- (i) => isPackageExists2(i)
1034
- );
1035
- const isUsingNext = NextJsPackages.some((i) => isPackageExists2(i));
1036
- const plugins = pluginReact.configs.all.plugins;
1037
- return [
1038
- {
1039
- name: "react/setup",
1040
- plugins: {
1041
- "react": plugins["@eslint-react"],
1042
- "react-dom": plugins["@eslint-react/dom"],
1043
- "react-hooks": pluginReactHooks,
1044
- "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
1045
- "react-naming-convention": plugins["@eslint-react/naming-convention"],
1046
- "react-refresh": pluginReactRefresh,
1047
- "react-web-api": plugins["@eslint-react/web-api"]
1048
- }
1049
- },
1050
- {
1051
- files,
1052
- languageOptions: {
1053
- parserOptions: {
1054
- ecmaFeatures: {
1055
- jsx: true
1056
- }
1057
- },
1058
- sourceType: "module"
1059
- },
1060
- name: "react/rules",
1061
- rules: {
1062
- // recommended rules from eslint-plugin-react-x https://eslint-react.xyz/docs/rules/overview#core-rules
1063
- "react/jsx-no-duplicate-props": "warn",
1064
- "react/jsx-uses-vars": "warn",
1065
- "react/no-access-state-in-setstate": "error",
1066
- "react/no-array-index-key": "warn",
1067
- "react/no-children-count": "warn",
1068
- "react/no-children-for-each": "warn",
1069
- "react/no-children-map": "warn",
1070
- "react/no-children-only": "warn",
1071
- "react/no-children-to-array": "warn",
1072
- "react/no-clone-element": "warn",
1073
- "react/no-comment-textnodes": "warn",
1074
- "react/no-component-will-mount": "error",
1075
- "react/no-component-will-receive-props": "error",
1076
- "react/no-component-will-update": "error",
1077
- "react/no-context-provider": "warn",
1078
- "react/no-create-ref": "error",
1079
- "react/no-default-props": "error",
1080
- "react/no-direct-mutation-state": "error",
1081
- "react/no-duplicate-key": "warn",
1082
- "react/no-forward-ref": "warn",
1083
- "react/no-implicit-key": "warn",
1084
- "react/no-missing-key": "error",
1085
- "react/no-nested-component-definitions": "error",
1086
- "react/no-prop-types": "error",
1087
- "react/no-redundant-should-component-update": "error",
1088
- "react/no-set-state-in-component-did-mount": "warn",
1089
- "react/no-set-state-in-component-did-update": "warn",
1090
- "react/no-set-state-in-component-will-update": "warn",
1091
- "react/no-string-refs": "error",
1092
- "react/no-unsafe-component-will-mount": "warn",
1093
- "react/no-unsafe-component-will-receive-props": "warn",
1094
- "react/no-unsafe-component-will-update": "warn",
1095
- "react/no-unstable-context-value": "warn",
1096
- "react/no-unstable-default-props": "warn",
1097
- "react/no-unused-class-component-members": "warn",
1098
- "react/no-unused-state": "warn",
1099
- "react/no-use-context": "warn",
1100
- "react/no-useless-forward-ref": "warn",
1101
- // recommended rules from eslint-plugin-react-dom https://eslint-react.xyz/docs/rules/overview#dom-rules
1102
- "react-dom/no-dangerously-set-innerhtml": "warn",
1103
- "react-dom/no-dangerously-set-innerhtml-with-children": "error",
1104
- "react-dom/no-find-dom-node": "error",
1105
- "react-dom/no-flush-sync": "error",
1106
- "react-dom/no-hydrate": "error",
1107
- "react-dom/no-missing-button-type": "warn",
1108
- "react-dom/no-missing-iframe-sandbox": "warn",
1109
- "react-dom/no-namespace": "error",
1110
- "react-dom/no-render": "error",
1111
- "react-dom/no-render-return-value": "error",
1112
- "react-dom/no-script-url": "warn",
1113
- "react-dom/no-unsafe-iframe-sandbox": "warn",
1114
- "react-dom/no-unsafe-target-blank": "warn",
1115
- "react-dom/no-use-form-state": "error",
1116
- "react-dom/no-void-elements-with-children": "error",
1117
- // recommended rules eslint-plugin-react-hooks https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks/src/rules
1118
- "react-hooks/exhaustive-deps": "warn",
1119
- "react-hooks/rules-of-hooks": "error",
1120
- // recommended rules from eslint-plugin-react-hooks-extra https://eslint-react.xyz/docs/rules/overview#hooks-extra-rules
1121
- "react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
1122
- "react-hooks-extra/no-unnecessary-use-prefix": "warn",
1123
- "react-hooks-extra/prefer-use-state-lazy-initialization": "warn",
1124
- // recommended rules from eslint-plugin-react-web-api https://eslint-react.xyz/docs/rules/overview#web-api-rules
1125
- "react-web-api/no-leaked-event-listener": "warn",
1126
- "react-web-api/no-leaked-interval": "warn",
1127
- "react-web-api/no-leaked-resize-observer": "warn",
1128
- "react-web-api/no-leaked-timeout": "warn",
1129
- // preconfigured rules from eslint-plugin-react-refresh https://github.com/ArnaudBarre/eslint-plugin-react-refresh/tree/main/src
1130
- "react-refresh/only-export-components": [
1131
- "warn",
1132
- {
1133
- allowConstantExport: isAllowConstantExport,
1134
- allowExportNames: [
1135
- ...isUsingNext ? [
1136
- "dynamic",
1137
- "dynamicParams",
1138
- "revalidate",
1139
- "fetchCache",
1140
- "runtime",
1141
- "preferredRegion",
1142
- "maxDuration",
1143
- "config",
1144
- "generateStaticParams",
1145
- "metadata",
1146
- "generateMetadata",
1147
- "viewport",
1148
- "generateViewport"
1149
- ] : [],
1150
- ...isUsingReactRouter ? ["meta", "links", "headers", "loader", "action"] : []
1151
- ]
1152
- }
1153
- ],
1154
- // overrides
1155
- ...overrides
1156
- }
1157
- },
1158
- ...isTypeAware ? [
1159
- {
1160
- files: filesTypeAware,
1161
- ignores: ignoresTypeAware,
1162
- name: "react/type-aware-rules",
1163
- rules: {
1164
- ...typeAwareRules
1165
- }
1166
- }
1167
- ] : []
1168
- ];
966
+ const { files = [GLOB_SRC], filesTypeAware = [GLOB_TS, GLOB_TSX], ignoresTypeAware = [`${GLOB_MARKDOWN}/**`], overrides = {}, tsconfigPath } = options;
967
+ const isTypeAware = !!tsconfigPath;
968
+ const typeAwareRules = { "react/no-leaked-conditional-rendering": "warn" };
969
+ const [pluginReact, pluginReactHooks, pluginReactRefresh] = await Promise.all([
970
+ interopDefault(import("@eslint-react/eslint-plugin")),
971
+ interopDefault(import("eslint-plugin-react-hooks")),
972
+ interopDefault(import("eslint-plugin-react-refresh"))
973
+ ]);
974
+ const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => isPackageExists(i));
975
+ const isUsingReactRouter = ReactRouterPackages.some((i) => isPackageExists(i));
976
+ const isUsingNext = NextJsPackages.some((i) => isPackageExists(i));
977
+ const plugins = pluginReact.configs.all.plugins;
978
+ return [
979
+ {
980
+ name: "react/setup",
981
+ plugins: {
982
+ "react": plugins["@eslint-react"],
983
+ "react-dom": plugins["@eslint-react/dom"],
984
+ "react-hooks": pluginReactHooks,
985
+ "react-hooks-extra": plugins["@eslint-react/hooks-extra"],
986
+ "react-naming-convention": plugins["@eslint-react/naming-convention"],
987
+ "react-refresh": pluginReactRefresh,
988
+ "react-web-api": plugins["@eslint-react/web-api"]
989
+ }
990
+ },
991
+ {
992
+ files,
993
+ languageOptions: {
994
+ parserOptions: { ecmaFeatures: { jsx: true } },
995
+ sourceType: "module"
996
+ },
997
+ name: "react/rules",
998
+ rules: {
999
+ "react/jsx-no-duplicate-props": "warn",
1000
+ "react/jsx-uses-vars": "warn",
1001
+ "react/no-access-state-in-setstate": "error",
1002
+ "react/no-array-index-key": "warn",
1003
+ "react/no-children-count": "warn",
1004
+ "react/no-children-for-each": "warn",
1005
+ "react/no-children-map": "warn",
1006
+ "react/no-children-only": "warn",
1007
+ "react/no-children-to-array": "warn",
1008
+ "react/no-clone-element": "warn",
1009
+ "react/no-comment-textnodes": "warn",
1010
+ "react/no-component-will-mount": "error",
1011
+ "react/no-component-will-receive-props": "error",
1012
+ "react/no-component-will-update": "error",
1013
+ "react/no-context-provider": "warn",
1014
+ "react/no-create-ref": "error",
1015
+ "react/no-default-props": "error",
1016
+ "react/no-direct-mutation-state": "error",
1017
+ "react/no-duplicate-key": "warn",
1018
+ "react/no-forward-ref": "warn",
1019
+ "react/no-implicit-key": "warn",
1020
+ "react/no-missing-key": "error",
1021
+ "react/no-nested-component-definitions": "error",
1022
+ "react/no-prop-types": "error",
1023
+ "react/no-redundant-should-component-update": "error",
1024
+ "react/no-set-state-in-component-did-mount": "warn",
1025
+ "react/no-set-state-in-component-did-update": "warn",
1026
+ "react/no-set-state-in-component-will-update": "warn",
1027
+ "react/no-string-refs": "error",
1028
+ "react/no-unsafe-component-will-mount": "warn",
1029
+ "react/no-unsafe-component-will-receive-props": "warn",
1030
+ "react/no-unsafe-component-will-update": "warn",
1031
+ "react/no-unstable-context-value": "warn",
1032
+ "react/no-unstable-default-props": "warn",
1033
+ "react/no-unused-class-component-members": "warn",
1034
+ "react/no-unused-state": "warn",
1035
+ "react/no-use-context": "warn",
1036
+ "react/no-useless-forward-ref": "warn",
1037
+ "react-dom/no-dangerously-set-innerhtml": "warn",
1038
+ "react-dom/no-dangerously-set-innerhtml-with-children": "error",
1039
+ "react-dom/no-find-dom-node": "error",
1040
+ "react-dom/no-flush-sync": "error",
1041
+ "react-dom/no-hydrate": "error",
1042
+ "react-dom/no-missing-button-type": "warn",
1043
+ "react-dom/no-missing-iframe-sandbox": "warn",
1044
+ "react-dom/no-namespace": "error",
1045
+ "react-dom/no-render": "error",
1046
+ "react-dom/no-render-return-value": "error",
1047
+ "react-dom/no-script-url": "warn",
1048
+ "react-dom/no-unsafe-iframe-sandbox": "warn",
1049
+ "react-dom/no-unsafe-target-blank": "warn",
1050
+ "react-dom/no-use-form-state": "error",
1051
+ "react-dom/no-void-elements-with-children": "error",
1052
+ "react-hooks/exhaustive-deps": "warn",
1053
+ "react-hooks/rules-of-hooks": "error",
1054
+ "react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
1055
+ "react-hooks-extra/no-unnecessary-use-prefix": "warn",
1056
+ "react-hooks-extra/prefer-use-state-lazy-initialization": "warn",
1057
+ "react-web-api/no-leaked-event-listener": "warn",
1058
+ "react-web-api/no-leaked-interval": "warn",
1059
+ "react-web-api/no-leaked-resize-observer": "warn",
1060
+ "react-web-api/no-leaked-timeout": "warn",
1061
+ "react-refresh/only-export-components": ["warn", {
1062
+ allowConstantExport: isAllowConstantExport,
1063
+ allowExportNames: [...isUsingNext ? [
1064
+ "dynamic",
1065
+ "dynamicParams",
1066
+ "revalidate",
1067
+ "fetchCache",
1068
+ "runtime",
1069
+ "preferredRegion",
1070
+ "maxDuration",
1071
+ "config",
1072
+ "generateStaticParams",
1073
+ "metadata",
1074
+ "generateMetadata",
1075
+ "viewport",
1076
+ "generateViewport"
1077
+ ] : [], ...isUsingReactRouter ? [
1078
+ "meta",
1079
+ "links",
1080
+ "headers",
1081
+ "loader",
1082
+ "action"
1083
+ ] : []]
1084
+ }],
1085
+ ...overrides
1086
+ }
1087
+ },
1088
+ ...isTypeAware ? [{
1089
+ files: filesTypeAware,
1090
+ ignores: ignoresTypeAware,
1091
+ name: "react/type-aware-rules",
1092
+ rules: { ...typeAwareRules }
1093
+ }] : []
1094
+ ];
1169
1095
  }
1170
1096
 
1171
- // src/configs/regexp.ts
1172
- import { configs } from "eslint-plugin-regexp";
1097
+ //#endregion
1098
+ //#region src/configs/regexp.ts
1173
1099
  async function regexp(options = {}) {
1174
- const config2 = configs["flat/recommended"];
1175
- const rules = {
1176
- ...config2.rules
1177
- };
1178
- if (options.level === "warn") {
1179
- for (const key in rules) {
1180
- if (rules[key] === "error") {
1181
- rules[key] = "warn";
1182
- }
1183
- }
1184
- }
1185
- return [
1186
- {
1187
- ...config2,
1188
- name: "regexp/rules",
1189
- rules: {
1190
- ...rules,
1191
- ...options.overrides
1192
- }
1193
- }
1194
- ];
1100
+ const config$1 = configs["flat/recommended"];
1101
+ const rules = { ...config$1.rules };
1102
+ if (options.level === "warn") {
1103
+ for (const key in rules) if (rules[key] === "error") rules[key] = "warn";
1104
+ }
1105
+ return [{
1106
+ ...config$1,
1107
+ name: "regexp/rules",
1108
+ rules: {
1109
+ ...rules,
1110
+ ...options.overrides
1111
+ }
1112
+ }];
1195
1113
  }
1196
1114
 
1197
- // src/configs/sort.ts
1115
+ //#endregion
1116
+ //#region src/configs/sort.ts
1117
+ /**
1118
+ * Sort package.json
1119
+ *
1120
+ * Requires `jsonc` config
1121
+ */
1198
1122
  async function sortPackageJson() {
1199
- return [
1200
- {
1201
- files: ["**/package.json"],
1202
- name: "sort/package-json",
1203
- rules: {
1204
- "jsonc/sort-array-values": [
1205
- "error",
1206
- {
1207
- order: { type: "asc" },
1208
- pathPattern: "^files$"
1209
- }
1210
- ],
1211
- "jsonc/sort-keys": [
1212
- "error",
1213
- {
1214
- order: [
1215
- "publisher",
1216
- "name",
1217
- "displayName",
1218
- "type",
1219
- "version",
1220
- "private",
1221
- "packageManager",
1222
- "description",
1223
- "author",
1224
- "contributors",
1225
- "license",
1226
- "funding",
1227
- "homepage",
1228
- "repository",
1229
- "bugs",
1230
- "keywords",
1231
- "categories",
1232
- "sideEffects",
1233
- "imports",
1234
- "exports",
1235
- "main",
1236
- "module",
1237
- "unpkg",
1238
- "jsdelivr",
1239
- "types",
1240
- "typesVersions",
1241
- "bin",
1242
- "icon",
1243
- "files",
1244
- "engines",
1245
- "activationEvents",
1246
- "contributes",
1247
- "scripts",
1248
- "peerDependencies",
1249
- "peerDependenciesMeta",
1250
- "dependencies",
1251
- "optionalDependencies",
1252
- "devDependencies",
1253
- "pnpm",
1254
- "overrides",
1255
- "resolutions",
1256
- "husky",
1257
- "simple-git-hooks",
1258
- "lint-staged",
1259
- "eslintConfig"
1260
- ],
1261
- pathPattern: "^$"
1262
- },
1263
- {
1264
- order: { type: "asc" },
1265
- pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
1266
- },
1267
- {
1268
- order: { type: "asc" },
1269
- pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
1270
- },
1271
- {
1272
- order: ["types", "import", "require", "default"],
1273
- pathPattern: "^exports.*$"
1274
- },
1275
- {
1276
- order: [
1277
- // client hooks only
1278
- "pre-commit",
1279
- "prepare-commit-msg",
1280
- "commit-msg",
1281
- "post-commit",
1282
- "pre-rebase",
1283
- "post-rewrite",
1284
- "post-checkout",
1285
- "post-merge",
1286
- "pre-push",
1287
- "pre-auto-gc"
1288
- ],
1289
- pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
1290
- }
1291
- ]
1292
- }
1293
- }
1294
- ];
1123
+ return [{
1124
+ files: ["**/package.json"],
1125
+ name: "sort/package-json",
1126
+ rules: {
1127
+ "jsonc/sort-array-values": ["error", {
1128
+ order: { type: "asc" },
1129
+ pathPattern: "^files$"
1130
+ }],
1131
+ "jsonc/sort-keys": [
1132
+ "error",
1133
+ {
1134
+ order: [
1135
+ "publisher",
1136
+ "name",
1137
+ "displayName",
1138
+ "type",
1139
+ "version",
1140
+ "private",
1141
+ "packageManager",
1142
+ "description",
1143
+ "author",
1144
+ "contributors",
1145
+ "license",
1146
+ "funding",
1147
+ "homepage",
1148
+ "repository",
1149
+ "bugs",
1150
+ "keywords",
1151
+ "categories",
1152
+ "sideEffects",
1153
+ "imports",
1154
+ "exports",
1155
+ "main",
1156
+ "module",
1157
+ "unpkg",
1158
+ "jsdelivr",
1159
+ "types",
1160
+ "typesVersions",
1161
+ "bin",
1162
+ "icon",
1163
+ "files",
1164
+ "engines",
1165
+ "activationEvents",
1166
+ "contributes",
1167
+ "scripts",
1168
+ "peerDependencies",
1169
+ "peerDependenciesMeta",
1170
+ "dependencies",
1171
+ "optionalDependencies",
1172
+ "devDependencies",
1173
+ "pnpm",
1174
+ "overrides",
1175
+ "resolutions",
1176
+ "husky",
1177
+ "simple-git-hooks",
1178
+ "lint-staged",
1179
+ "eslintConfig"
1180
+ ],
1181
+ pathPattern: "^$"
1182
+ },
1183
+ {
1184
+ order: { type: "asc" },
1185
+ pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies(Meta)?$"
1186
+ },
1187
+ {
1188
+ order: { type: "asc" },
1189
+ pathPattern: "^(?:resolutions|overrides|pnpm.overrides)$"
1190
+ },
1191
+ {
1192
+ order: [
1193
+ "types",
1194
+ "import",
1195
+ "require",
1196
+ "default"
1197
+ ],
1198
+ pathPattern: "^exports.*$"
1199
+ },
1200
+ {
1201
+ order: [
1202
+ "pre-commit",
1203
+ "prepare-commit-msg",
1204
+ "commit-msg",
1205
+ "post-commit",
1206
+ "pre-rebase",
1207
+ "post-rewrite",
1208
+ "post-checkout",
1209
+ "post-merge",
1210
+ "pre-push",
1211
+ "pre-auto-gc"
1212
+ ],
1213
+ pathPattern: "^(?:gitHooks|husky|simple-git-hooks)$"
1214
+ }
1215
+ ]
1216
+ }
1217
+ }];
1295
1218
  }
1219
+ /**
1220
+ * Sort tsconfig.json
1221
+ *
1222
+ * Requires `jsonc` config
1223
+ */
1296
1224
  function sortTsconfig() {
1297
- return [
1298
- {
1299
- files: ["**/tsconfig.json", "**/tsconfig.*.json"],
1300
- name: "sort/tsconfig-json",
1301
- rules: {
1302
- "jsonc/sort-keys": [
1303
- "error",
1304
- {
1305
- order: [
1306
- "extends",
1307
- "compilerOptions",
1308
- "references",
1309
- "files",
1310
- "include",
1311
- "exclude"
1312
- ],
1313
- pathPattern: "^$"
1314
- },
1315
- {
1316
- order: [
1317
- /* Projects */
1318
- "incremental",
1319
- "composite",
1320
- "tsBuildInfoFile",
1321
- "disableSourceOfProjectReferenceRedirect",
1322
- "disableSolutionSearching",
1323
- "disableReferencedProjectLoad",
1324
- /* Language and Environment */
1325
- "target",
1326
- "jsx",
1327
- "jsxFactory",
1328
- "jsxFragmentFactory",
1329
- "jsxImportSource",
1330
- "lib",
1331
- "moduleDetection",
1332
- "noLib",
1333
- "reactNamespace",
1334
- "useDefineForClassFields",
1335
- "emitDecoratorMetadata",
1336
- "experimentalDecorators",
1337
- "libReplacement",
1338
- /* Modules */
1339
- "baseUrl",
1340
- "rootDir",
1341
- "rootDirs",
1342
- "customConditions",
1343
- "module",
1344
- "moduleResolution",
1345
- "moduleSuffixes",
1346
- "noResolve",
1347
- "paths",
1348
- "resolveJsonModule",
1349
- "resolvePackageJsonExports",
1350
- "resolvePackageJsonImports",
1351
- "typeRoots",
1352
- "types",
1353
- "allowArbitraryExtensions",
1354
- "allowImportingTsExtensions",
1355
- "allowUmdGlobalAccess",
1356
- /* JavaScript Support */
1357
- "allowJs",
1358
- "checkJs",
1359
- "maxNodeModuleJsDepth",
1360
- /* Type Checking */
1361
- "strict",
1362
- "strictBindCallApply",
1363
- "strictFunctionTypes",
1364
- "strictNullChecks",
1365
- "strictPropertyInitialization",
1366
- "allowUnreachableCode",
1367
- "allowUnusedLabels",
1368
- "alwaysStrict",
1369
- "exactOptionalPropertyTypes",
1370
- "noFallthroughCasesInSwitch",
1371
- "noImplicitAny",
1372
- "noImplicitOverride",
1373
- "noImplicitReturns",
1374
- "noImplicitThis",
1375
- "noPropertyAccessFromIndexSignature",
1376
- "noUncheckedIndexedAccess",
1377
- "noUnusedLocals",
1378
- "noUnusedParameters",
1379
- "useUnknownInCatchVariables",
1380
- /* Emit */
1381
- "declaration",
1382
- "declarationDir",
1383
- "declarationMap",
1384
- "downlevelIteration",
1385
- "emitBOM",
1386
- "emitDeclarationOnly",
1387
- "importHelpers",
1388
- "importsNotUsedAsValues",
1389
- "inlineSourceMap",
1390
- "inlineSources",
1391
- "mapRoot",
1392
- "newLine",
1393
- "noEmit",
1394
- "noEmitHelpers",
1395
- "noEmitOnError",
1396
- "outDir",
1397
- "outFile",
1398
- "preserveConstEnums",
1399
- "preserveValueImports",
1400
- "removeComments",
1401
- "sourceMap",
1402
- "sourceRoot",
1403
- "stripInternal",
1404
- /* Interop Constraints */
1405
- "allowSyntheticDefaultImports",
1406
- "esModuleInterop",
1407
- "forceConsistentCasingInFileNames",
1408
- "isolatedDeclarations",
1409
- "isolatedModules",
1410
- "preserveSymlinks",
1411
- "verbatimModuleSyntax",
1412
- "erasableSyntaxOnly",
1413
- /* Completeness */
1414
- "skipDefaultLibCheck",
1415
- "skipLibCheck"
1416
- ],
1417
- pathPattern: "^compilerOptions$"
1418
- }
1419
- ]
1420
- }
1421
- }
1422
- ];
1225
+ return [{
1226
+ files: ["**/tsconfig.json", "**/tsconfig.*.json"],
1227
+ name: "sort/tsconfig-json",
1228
+ rules: { "jsonc/sort-keys": [
1229
+ "error",
1230
+ {
1231
+ order: [
1232
+ "extends",
1233
+ "compilerOptions",
1234
+ "references",
1235
+ "files",
1236
+ "include",
1237
+ "exclude"
1238
+ ],
1239
+ pathPattern: "^$"
1240
+ },
1241
+ {
1242
+ order: [
1243
+ "incremental",
1244
+ "composite",
1245
+ "tsBuildInfoFile",
1246
+ "disableSourceOfProjectReferenceRedirect",
1247
+ "disableSolutionSearching",
1248
+ "disableReferencedProjectLoad",
1249
+ "target",
1250
+ "jsx",
1251
+ "jsxFactory",
1252
+ "jsxFragmentFactory",
1253
+ "jsxImportSource",
1254
+ "lib",
1255
+ "moduleDetection",
1256
+ "noLib",
1257
+ "reactNamespace",
1258
+ "useDefineForClassFields",
1259
+ "emitDecoratorMetadata",
1260
+ "experimentalDecorators",
1261
+ "libReplacement",
1262
+ "baseUrl",
1263
+ "rootDir",
1264
+ "rootDirs",
1265
+ "customConditions",
1266
+ "module",
1267
+ "moduleResolution",
1268
+ "moduleSuffixes",
1269
+ "noResolve",
1270
+ "paths",
1271
+ "resolveJsonModule",
1272
+ "resolvePackageJsonExports",
1273
+ "resolvePackageJsonImports",
1274
+ "typeRoots",
1275
+ "types",
1276
+ "allowArbitraryExtensions",
1277
+ "allowImportingTsExtensions",
1278
+ "allowUmdGlobalAccess",
1279
+ "allowJs",
1280
+ "checkJs",
1281
+ "maxNodeModuleJsDepth",
1282
+ "strict",
1283
+ "strictBindCallApply",
1284
+ "strictFunctionTypes",
1285
+ "strictNullChecks",
1286
+ "strictPropertyInitialization",
1287
+ "allowUnreachableCode",
1288
+ "allowUnusedLabels",
1289
+ "alwaysStrict",
1290
+ "exactOptionalPropertyTypes",
1291
+ "noFallthroughCasesInSwitch",
1292
+ "noImplicitAny",
1293
+ "noImplicitOverride",
1294
+ "noImplicitReturns",
1295
+ "noImplicitThis",
1296
+ "noPropertyAccessFromIndexSignature",
1297
+ "noUncheckedIndexedAccess",
1298
+ "noUnusedLocals",
1299
+ "noUnusedParameters",
1300
+ "useUnknownInCatchVariables",
1301
+ "declaration",
1302
+ "declarationDir",
1303
+ "declarationMap",
1304
+ "downlevelIteration",
1305
+ "emitBOM",
1306
+ "emitDeclarationOnly",
1307
+ "importHelpers",
1308
+ "importsNotUsedAsValues",
1309
+ "inlineSourceMap",
1310
+ "inlineSources",
1311
+ "mapRoot",
1312
+ "newLine",
1313
+ "noEmit",
1314
+ "noEmitHelpers",
1315
+ "noEmitOnError",
1316
+ "outDir",
1317
+ "outFile",
1318
+ "preserveConstEnums",
1319
+ "preserveValueImports",
1320
+ "removeComments",
1321
+ "sourceMap",
1322
+ "sourceRoot",
1323
+ "stripInternal",
1324
+ "allowSyntheticDefaultImports",
1325
+ "esModuleInterop",
1326
+ "forceConsistentCasingInFileNames",
1327
+ "isolatedDeclarations",
1328
+ "isolatedModules",
1329
+ "preserveSymlinks",
1330
+ "verbatimModuleSyntax",
1331
+ "erasableSyntaxOnly",
1332
+ "skipDefaultLibCheck",
1333
+ "skipLibCheck"
1334
+ ],
1335
+ pathPattern: "^compilerOptions$"
1336
+ }
1337
+ ] }
1338
+ }];
1423
1339
  }
1424
1340
 
1425
- // src/configs/toml.ts
1341
+ //#endregion
1342
+ //#region src/configs/toml.ts
1426
1343
  async function toml(options = {}) {
1427
- const { files = [GLOB_TOML], overrides = {}, stylistic: stylistic2 = true } = options;
1428
- const { indent = 2 } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1429
- const [pluginToml, parserToml] = await Promise.all([
1430
- interopDefault(import("eslint-plugin-toml")),
1431
- interopDefault(import("toml-eslint-parser"))
1432
- ]);
1433
- return [
1434
- {
1435
- name: "toml/setup",
1436
- plugins: {
1437
- toml: pluginToml
1438
- }
1439
- },
1440
- {
1441
- files,
1442
- languageOptions: {
1443
- parser: parserToml
1444
- },
1445
- name: "toml/rules",
1446
- rules: {
1447
- "style/spaced-comment": "off",
1448
- "toml/comma-style": "error",
1449
- "toml/keys-order": "error",
1450
- "toml/no-space-dots": "error",
1451
- "toml/no-unreadable-number-separator": "error",
1452
- "toml/precision-of-fractional-seconds": "error",
1453
- "toml/precision-of-integer": "error",
1454
- "toml/tables-order": "error",
1455
- "toml/vue-custom-block/no-parsing-error": "error",
1456
- ...stylistic2 ? {
1457
- "toml/array-bracket-newline": "error",
1458
- "toml/array-bracket-spacing": "error",
1459
- "toml/array-element-newline": "error",
1460
- "toml/indent": ["error", indent === "tab" ? 2 : indent],
1461
- "toml/inline-table-curly-spacing": "error",
1462
- "toml/key-spacing": "error",
1463
- "toml/padding-line-between-pairs": "error",
1464
- "toml/padding-line-between-tables": "error",
1465
- "toml/quoted-keys": "error",
1466
- "toml/spaced-comment": "error",
1467
- "toml/table-bracket-spacing": "error"
1468
- } : {},
1469
- ...overrides
1470
- }
1471
- }
1472
- ];
1344
+ const { files = [GLOB_TOML], overrides = {}, stylistic: stylistic$1 = true } = options;
1345
+ const { indent = 2 } = typeof stylistic$1 === "boolean" ? {} : stylistic$1;
1346
+ const [pluginToml, parserToml] = await Promise.all([interopDefault(import("eslint-plugin-toml")), interopDefault(import("toml-eslint-parser"))]);
1347
+ return [{
1348
+ name: "toml/setup",
1349
+ plugins: { toml: pluginToml }
1350
+ }, {
1351
+ files,
1352
+ languageOptions: { parser: parserToml },
1353
+ name: "toml/rules",
1354
+ rules: {
1355
+ "style/spaced-comment": "off",
1356
+ "toml/comma-style": "error",
1357
+ "toml/keys-order": "error",
1358
+ "toml/no-space-dots": "error",
1359
+ "toml/no-unreadable-number-separator": "error",
1360
+ "toml/precision-of-fractional-seconds": "error",
1361
+ "toml/precision-of-integer": "error",
1362
+ "toml/tables-order": "error",
1363
+ "toml/vue-custom-block/no-parsing-error": "error",
1364
+ ...stylistic$1 ? {
1365
+ "toml/array-bracket-newline": "error",
1366
+ "toml/array-bracket-spacing": "error",
1367
+ "toml/array-element-newline": "error",
1368
+ "toml/indent": ["error", indent === "tab" ? 2 : indent],
1369
+ "toml/inline-table-curly-spacing": "error",
1370
+ "toml/key-spacing": "error",
1371
+ "toml/padding-line-between-pairs": "error",
1372
+ "toml/padding-line-between-tables": "error",
1373
+ "toml/quoted-keys": "error",
1374
+ "toml/spaced-comment": "error",
1375
+ "toml/table-bracket-spacing": "error"
1376
+ } : {},
1377
+ ...overrides
1378
+ }
1379
+ }];
1473
1380
  }
1474
1381
 
1475
- // src/configs/typescript.ts
1476
- import process2 from "node:process";
1382
+ //#endregion
1383
+ //#region src/configs/typescript.ts
1477
1384
  async function typescript(options = {}) {
1478
- const {
1479
- componentExts = [],
1480
- overrides = {},
1481
- overridesTypeAware = {},
1482
- parserOptions = {},
1483
- type = "app"
1484
- } = options;
1485
- const files = options.files ?? [
1486
- GLOB_TS,
1487
- GLOB_TSX,
1488
- ...componentExts.map((ext) => `**/*.${ext}`)
1489
- ];
1490
- const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
1491
- const ignoresTypeAware = options.ignoresTypeAware ?? [`${GLOB_MARKDOWN}/**`];
1492
- const tsconfigPath = options?.tsconfigPath ? options.tsconfigPath : void 0;
1493
- const isTypeAware = !!tsconfigPath;
1494
- const typeAwareRules = {
1495
- "dot-notation": "off",
1496
- "no-implied-eval": "off",
1497
- "ts/await-thenable": "error",
1498
- "ts/dot-notation": ["error", { allowKeywords: true }],
1499
- "ts/no-floating-promises": "error",
1500
- "ts/no-for-in-array": "error",
1501
- "ts/no-implied-eval": "error",
1502
- "ts/no-misused-promises": "error",
1503
- "ts/no-unnecessary-type-assertion": "error",
1504
- "ts/no-unsafe-argument": "error",
1505
- "ts/no-unsafe-assignment": "error",
1506
- "ts/no-unsafe-call": "error",
1507
- "ts/no-unsafe-member-access": "error",
1508
- "ts/no-unsafe-return": "error",
1509
- "ts/promise-function-async": "error",
1510
- "ts/restrict-plus-operands": "error",
1511
- "ts/restrict-template-expressions": "error",
1512
- "ts/return-await": ["error", "in-try-catch"],
1513
- "ts/strict-boolean-expressions": [
1514
- "error",
1515
- { allowNullableBoolean: true, allowNullableObject: true }
1516
- ],
1517
- "ts/switch-exhaustiveness-check": "error",
1518
- "ts/unbound-method": "error"
1519
- };
1520
- const [pluginTs, parserTs] = await Promise.all([
1521
- interopDefault(import("@typescript-eslint/eslint-plugin")),
1522
- interopDefault(import("@typescript-eslint/parser"))
1523
- ]);
1524
- function makeParser(typeAware, files2, ignores2) {
1525
- return {
1526
- files: files2,
1527
- ...ignores2 ? { ignores: ignores2 } : {},
1528
- languageOptions: {
1529
- parser: parserTs,
1530
- parserOptions: {
1531
- extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1532
- sourceType: "module",
1533
- ...typeAware ? {
1534
- projectService: {
1535
- allowDefaultProject: ["./*.js"],
1536
- defaultProject: tsconfigPath
1537
- },
1538
- tsconfigRootDir: process2.cwd()
1539
- } : {},
1540
- ...parserOptions
1541
- }
1542
- },
1543
- name: `typescript/${typeAware ? "type-aware-parser" : "parser"}`
1544
- };
1545
- }
1546
- return [
1547
- {
1548
- // Install the plugins without globs, so they can be configured separately.
1549
- name: "typescript/setup",
1550
- plugins: {
1551
- antfu: default3,
1552
- ts: pluginTs
1553
- }
1554
- },
1555
- // assign type-aware parser for type-aware files and type-unaware parser for the rest
1556
- ...isTypeAware ? [
1557
- makeParser(false, files),
1558
- makeParser(true, filesTypeAware, ignoresTypeAware)
1559
- ] : [makeParser(false, files)],
1560
- {
1561
- files,
1562
- name: "typescript/rules",
1563
- rules: {
1564
- ...renameRules(
1565
- pluginTs.configs["eslint-recommended"].overrides[0].rules,
1566
- { "@typescript-eslint": "ts" }
1567
- ),
1568
- ...renameRules(pluginTs.configs.strict.rules, {
1569
- "@typescript-eslint": "ts"
1570
- }),
1571
- "no-dupe-class-members": "off",
1572
- "no-redeclare": "off",
1573
- "no-use-before-define": "off",
1574
- "no-useless-constructor": "off",
1575
- "ts/ban-ts-comment": [
1576
- "error",
1577
- { "ts-expect-error": "allow-with-description" }
1578
- ],
1579
- "ts/consistent-type-definitions": ["error", "interface"],
1580
- "ts/consistent-type-imports": [
1581
- "error",
1582
- {
1583
- disallowTypeAnnotations: false,
1584
- fixStyle: "separate-type-imports",
1585
- prefer: "type-imports"
1586
- }
1587
- ],
1588
- "ts/method-signature-style": ["error", "property"],
1589
- // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
1590
- "ts/no-dupe-class-members": "error",
1591
- "ts/no-dynamic-delete": "off",
1592
- "ts/no-empty-object-type": ["error", { allowInterfaces: "always" }],
1593
- "ts/no-explicit-any": "off",
1594
- "ts/no-extraneous-class": "off",
1595
- "ts/no-import-type-side-effects": "error",
1596
- "ts/no-invalid-void-type": "off",
1597
- "ts/no-non-null-assertion": "off",
1598
- "ts/no-redeclare": ["error", { builtinGlobals: false }],
1599
- "ts/no-require-imports": "error",
1600
- "ts/no-unused-expressions": [
1601
- "error",
1602
- {
1603
- allowShortCircuit: true,
1604
- allowTaggedTemplates: true,
1605
- allowTernary: true
1606
- }
1607
- ],
1608
- "ts/no-unused-vars": "off",
1609
- "ts/no-use-before-define": [
1610
- "error",
1611
- { classes: false, functions: false, variables: true }
1612
- ],
1613
- "ts/no-useless-constructor": "off",
1614
- "ts/no-wrapper-object-types": "error",
1615
- "ts/triple-slash-reference": "off",
1616
- "ts/unified-signatures": "off",
1617
- ...type === "lib" ? {
1618
- "ts/explicit-function-return-type": [
1619
- "error",
1620
- {
1621
- allowExpressions: true,
1622
- allowHigherOrderFunctions: true,
1623
- allowIIFEs: true
1624
- }
1625
- ]
1626
- } : {},
1627
- ...overrides
1628
- }
1629
- },
1630
- ...isTypeAware ? [
1631
- {
1632
- files: filesTypeAware,
1633
- ignores: ignoresTypeAware,
1634
- name: "typescript/rules-type-aware",
1635
- rules: {
1636
- ...typeAwareRules,
1637
- ...overridesTypeAware
1638
- }
1639
- }
1640
- ] : []
1641
- ];
1385
+ const { componentExts = [], overrides = {}, overridesTypeAware = {}, parserOptions = {}, type = "app" } = options;
1386
+ const files = options.files ?? [
1387
+ GLOB_TS,
1388
+ GLOB_TSX,
1389
+ ...componentExts.map((ext) => `**/*.${ext}`)
1390
+ ];
1391
+ const filesTypeAware = options.filesTypeAware ?? [GLOB_TS, GLOB_TSX];
1392
+ const ignoresTypeAware = options.ignoresTypeAware ?? [`${GLOB_MARKDOWN}/**`];
1393
+ const tsconfigPath = options?.tsconfigPath ? options.tsconfigPath : void 0;
1394
+ const isTypeAware = !!tsconfigPath;
1395
+ const typeAwareRules = {
1396
+ "dot-notation": "off",
1397
+ "no-implied-eval": "off",
1398
+ "ts/await-thenable": "error",
1399
+ "ts/dot-notation": ["error", { allowKeywords: true }],
1400
+ "ts/no-floating-promises": "error",
1401
+ "ts/no-for-in-array": "error",
1402
+ "ts/no-implied-eval": "error",
1403
+ "ts/no-misused-promises": "error",
1404
+ "ts/no-unnecessary-type-assertion": "error",
1405
+ "ts/no-unsafe-argument": "error",
1406
+ "ts/no-unsafe-assignment": "error",
1407
+ "ts/no-unsafe-call": "error",
1408
+ "ts/no-unsafe-member-access": "error",
1409
+ "ts/no-unsafe-return": "error",
1410
+ "ts/promise-function-async": "error",
1411
+ "ts/restrict-plus-operands": "error",
1412
+ "ts/restrict-template-expressions": "error",
1413
+ "ts/return-await": ["error", "in-try-catch"],
1414
+ "ts/strict-boolean-expressions": ["error", {
1415
+ allowNullableBoolean: true,
1416
+ allowNullableObject: true
1417
+ }],
1418
+ "ts/switch-exhaustiveness-check": "error",
1419
+ "ts/unbound-method": "error"
1420
+ };
1421
+ const [pluginTs, parserTs] = await Promise.all([interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/parser"))]);
1422
+ function makeParser(typeAware, files$1, ignores$1) {
1423
+ return {
1424
+ files: files$1,
1425
+ ...ignores$1 ? { ignores: ignores$1 } : {},
1426
+ languageOptions: {
1427
+ parser: parserTs,
1428
+ parserOptions: {
1429
+ extraFileExtensions: componentExts.map((ext) => `.${ext}`),
1430
+ sourceType: "module",
1431
+ ...typeAware ? {
1432
+ projectService: {
1433
+ allowDefaultProject: ["./*.js"],
1434
+ defaultProject: tsconfigPath
1435
+ },
1436
+ tsconfigRootDir: process.cwd()
1437
+ } : {},
1438
+ ...parserOptions
1439
+ }
1440
+ },
1441
+ name: `typescript/${typeAware ? "type-aware-parser" : "parser"}`
1442
+ };
1443
+ }
1444
+ return [
1445
+ {
1446
+ name: "typescript/setup",
1447
+ plugins: {
1448
+ antfu: pluginAntfu,
1449
+ ts: pluginTs
1450
+ }
1451
+ },
1452
+ ...isTypeAware ? [makeParser(false, files), makeParser(true, filesTypeAware, ignoresTypeAware)] : [makeParser(false, files)],
1453
+ {
1454
+ files,
1455
+ name: "typescript/rules",
1456
+ rules: {
1457
+ ...renameRules(pluginTs.configs["eslint-recommended"].overrides[0].rules, { "@typescript-eslint": "ts" }),
1458
+ ...renameRules(pluginTs.configs.strict.rules, { "@typescript-eslint": "ts" }),
1459
+ "no-dupe-class-members": "off",
1460
+ "no-redeclare": "off",
1461
+ "no-use-before-define": "off",
1462
+ "no-useless-constructor": "off",
1463
+ "ts/ban-ts-comment": ["error", { "ts-expect-error": "allow-with-description" }],
1464
+ "ts/consistent-type-definitions": ["error", "interface"],
1465
+ "ts/consistent-type-imports": ["error", {
1466
+ disallowTypeAnnotations: false,
1467
+ fixStyle: "separate-type-imports",
1468
+ prefer: "type-imports"
1469
+ }],
1470
+ "ts/method-signature-style": ["error", "property"],
1471
+ "ts/no-dupe-class-members": "error",
1472
+ "ts/no-dynamic-delete": "off",
1473
+ "ts/no-empty-object-type": ["error", { allowInterfaces: "always" }],
1474
+ "ts/no-explicit-any": "off",
1475
+ "ts/no-extraneous-class": "off",
1476
+ "ts/no-import-type-side-effects": "error",
1477
+ "ts/no-invalid-void-type": "off",
1478
+ "ts/no-non-null-assertion": "off",
1479
+ "ts/no-redeclare": ["error", { builtinGlobals: false }],
1480
+ "ts/no-require-imports": "error",
1481
+ "ts/no-unused-expressions": ["error", {
1482
+ allowShortCircuit: true,
1483
+ allowTaggedTemplates: true,
1484
+ allowTernary: true
1485
+ }],
1486
+ "ts/no-unused-vars": "off",
1487
+ "ts/no-use-before-define": ["error", {
1488
+ classes: false,
1489
+ functions: false,
1490
+ variables: true
1491
+ }],
1492
+ "ts/no-useless-constructor": "off",
1493
+ "ts/no-wrapper-object-types": "error",
1494
+ "ts/triple-slash-reference": "off",
1495
+ "ts/unified-signatures": "off",
1496
+ ...type === "lib" ? { "ts/explicit-function-return-type": ["error", {
1497
+ allowExpressions: true,
1498
+ allowHigherOrderFunctions: true,
1499
+ allowIIFEs: true
1500
+ }] } : {},
1501
+ ...overrides
1502
+ }
1503
+ },
1504
+ ...isTypeAware ? [{
1505
+ files: filesTypeAware,
1506
+ ignores: ignoresTypeAware,
1507
+ name: "typescript/rules-type-aware",
1508
+ rules: {
1509
+ ...typeAwareRules,
1510
+ ...overridesTypeAware
1511
+ }
1512
+ }] : []
1513
+ ];
1642
1514
  }
1643
1515
 
1644
- // src/configs/unicorn.ts
1516
+ //#endregion
1517
+ //#region src/configs/unicorn.ts
1645
1518
  async function unicorn(options = {}) {
1646
- const {
1647
- allRecommended = false,
1648
- overrides = {}
1649
- } = options;
1650
- return [
1651
- {
1652
- name: "unicorn/rules",
1653
- plugins: {
1654
- unicorn: default6
1655
- },
1656
- rules: {
1657
- ...allRecommended ? default6.configs.recommended.rules : {
1658
- "unicorn/consistent-empty-array-spread": "error",
1659
- "unicorn/error-message": "error",
1660
- "unicorn/escape-case": "error",
1661
- "unicorn/new-for-builtins": "error",
1662
- "unicorn/no-instanceof-builtins": "error",
1663
- "unicorn/no-new-array": "error",
1664
- "unicorn/no-new-buffer": "error",
1665
- "unicorn/number-literal-case": "error",
1666
- "unicorn/prefer-dom-node-text-content": "error",
1667
- "unicorn/prefer-includes": "error",
1668
- "unicorn/prefer-node-protocol": "error",
1669
- "unicorn/prefer-number-properties": "error",
1670
- "unicorn/prefer-string-starts-ends-with": "error",
1671
- "unicorn/prefer-type-error": "error",
1672
- "unicorn/throw-new-error": "error"
1673
- },
1674
- ...overrides
1675
- }
1676
- }
1677
- ];
1519
+ const { allRecommended = false, overrides = {} } = options;
1520
+ return [{
1521
+ name: "unicorn/rules",
1522
+ plugins: { unicorn: pluginUnicorn },
1523
+ rules: {
1524
+ ...allRecommended ? pluginUnicorn.configs.recommended.rules : {
1525
+ "unicorn/consistent-empty-array-spread": "error",
1526
+ "unicorn/error-message": "error",
1527
+ "unicorn/escape-case": "error",
1528
+ "unicorn/new-for-builtins": "error",
1529
+ "unicorn/no-instanceof-builtins": "error",
1530
+ "unicorn/no-new-array": "error",
1531
+ "unicorn/no-new-buffer": "error",
1532
+ "unicorn/number-literal-case": "error",
1533
+ "unicorn/prefer-dom-node-text-content": "error",
1534
+ "unicorn/prefer-includes": "error",
1535
+ "unicorn/prefer-node-protocol": "error",
1536
+ "unicorn/prefer-number-properties": "error",
1537
+ "unicorn/prefer-string-starts-ends-with": "error",
1538
+ "unicorn/prefer-type-error": "error",
1539
+ "unicorn/throw-new-error": "error"
1540
+ },
1541
+ ...overrides
1542
+ }
1543
+ }];
1678
1544
  }
1679
1545
 
1680
- // src/configs/unocss.ts
1546
+ //#endregion
1547
+ //#region src/configs/unocss.ts
1681
1548
  async function unocss(options = {}) {
1682
- const { attributify = true, strict = false } = options;
1683
- await ensurePackages(["@unocss/eslint-plugin"]);
1684
- const [pluginUnoCSS] = await Promise.all([
1685
- interopDefault(import("@unocss/eslint-plugin"))
1686
- ]);
1687
- return [
1688
- {
1689
- name: "unocss",
1690
- plugins: {
1691
- unocss: pluginUnoCSS
1692
- },
1693
- rules: {
1694
- "unocss/order": "warn",
1695
- ...attributify ? {
1696
- "unocss/order-attributify": "warn"
1697
- } : {},
1698
- ...strict ? {
1699
- "unocss/blocklist": "error"
1700
- } : {}
1701
- }
1702
- }
1703
- ];
1549
+ const { attributify = true, strict = false } = options;
1550
+ await ensurePackages(["@unocss/eslint-plugin"]);
1551
+ const [pluginUnoCSS] = await Promise.all([interopDefault(import("@unocss/eslint-plugin"))]);
1552
+ return [{
1553
+ name: "unocss",
1554
+ plugins: { unocss: pluginUnoCSS },
1555
+ rules: {
1556
+ "unocss/order": "warn",
1557
+ ...attributify ? { "unocss/order-attributify": "warn" } : {},
1558
+ ...strict ? { "unocss/blocklist": "error" } : {}
1559
+ }
1560
+ }];
1704
1561
  }
1705
1562
 
1706
- // src/configs/yaml.ts
1563
+ //#endregion
1564
+ //#region src/configs/yaml.ts
1707
1565
  async function yaml(options = {}) {
1708
- const { files = [GLOB_YAML], overrides = {}, stylistic: stylistic2 = true } = options;
1709
- const { indent = 2, quotes = "single" } = typeof stylistic2 === "boolean" ? {} : stylistic2;
1710
- const [pluginYaml, parserYaml] = await Promise.all([
1711
- interopDefault(import("eslint-plugin-yml")),
1712
- interopDefault(import("yaml-eslint-parser"))
1713
- ]);
1714
- return [
1715
- {
1716
- name: "yaml/setup",
1717
- plugins: {
1718
- yaml: pluginYaml
1719
- }
1720
- },
1721
- {
1722
- files,
1723
- languageOptions: {
1724
- parser: parserYaml
1725
- },
1726
- name: "yaml/rules",
1727
- rules: {
1728
- "style/spaced-comment": "off",
1729
- "yaml/block-mapping": "error",
1730
- "yaml/block-sequence": "error",
1731
- "yaml/no-empty-key": "error",
1732
- "yaml/no-empty-sequence-entry": "error",
1733
- "yaml/no-irregular-whitespace": "error",
1734
- "yaml/plain-scalar": "error",
1735
- "yaml/vue-custom-block/no-parsing-error": "error",
1736
- ...stylistic2 ? {
1737
- "yaml/block-mapping-question-indicator-newline": "error",
1738
- "yaml/block-sequence-hyphen-indicator-newline": "error",
1739
- "yaml/flow-mapping-curly-newline": "error",
1740
- "yaml/flow-mapping-curly-spacing": "error",
1741
- "yaml/flow-sequence-bracket-newline": "error",
1742
- "yaml/flow-sequence-bracket-spacing": "error",
1743
- "yaml/indent": ["error", indent === "tab" ? 2 : indent],
1744
- "yaml/key-spacing": "error",
1745
- "yaml/no-tab-indent": "error",
1746
- "yaml/quotes": [
1747
- "error",
1748
- {
1749
- avoidEscape: true,
1750
- prefer: quotes === "backtick" ? "single" : quotes
1751
- }
1752
- ],
1753
- "yaml/spaced-comment": "error"
1754
- } : {},
1755
- ...overrides
1756
- }
1757
- },
1758
- {
1759
- files: ["pnpm-workspace.yaml"],
1760
- name: "yaml/pnpm-workspace",
1761
- rules: {
1762
- "yaml/sort-keys": [
1763
- "error",
1764
- {
1765
- order: [
1766
- "packages",
1767
- "overrides",
1768
- "patchedDependencies",
1769
- "hoistPattern",
1770
- "catalog",
1771
- "catalogs",
1772
- "allowedDeprecatedVersions",
1773
- "allowNonAppliedPatches",
1774
- "configDependencies",
1775
- "ignoredBuiltDependencies",
1776
- "ignoredOptionalDependencies",
1777
- "neverBuiltDependencies",
1778
- "onlyBuiltDependencies",
1779
- "onlyBuiltDependenciesFile",
1780
- "packageExtensions",
1781
- "peerDependencyRules",
1782
- "supportedArchitectures"
1783
- ],
1784
- pathPattern: "^$"
1785
- },
1786
- {
1787
- order: { type: "asc" },
1788
- pathPattern: ".*"
1789
- }
1790
- ]
1791
- }
1792
- }
1793
- ];
1566
+ const { files = [GLOB_YAML], overrides = {}, stylistic: stylistic$1 = true } = options;
1567
+ const { indent = 2, quotes = "single" } = typeof stylistic$1 === "boolean" ? {} : stylistic$1;
1568
+ const [pluginYaml, parserYaml] = await Promise.all([interopDefault(import("eslint-plugin-yml")), interopDefault(import("yaml-eslint-parser"))]);
1569
+ return [
1570
+ {
1571
+ name: "yaml/setup",
1572
+ plugins: { yaml: pluginYaml }
1573
+ },
1574
+ {
1575
+ files,
1576
+ languageOptions: { parser: parserYaml },
1577
+ name: "yaml/rules",
1578
+ rules: {
1579
+ "style/spaced-comment": "off",
1580
+ "yaml/block-mapping": "error",
1581
+ "yaml/block-sequence": "error",
1582
+ "yaml/no-empty-key": "error",
1583
+ "yaml/no-empty-sequence-entry": "error",
1584
+ "yaml/no-irregular-whitespace": "error",
1585
+ "yaml/plain-scalar": "error",
1586
+ "yaml/vue-custom-block/no-parsing-error": "error",
1587
+ ...stylistic$1 ? {
1588
+ "yaml/block-mapping-question-indicator-newline": "error",
1589
+ "yaml/block-sequence-hyphen-indicator-newline": "error",
1590
+ "yaml/flow-mapping-curly-newline": "error",
1591
+ "yaml/flow-mapping-curly-spacing": "error",
1592
+ "yaml/flow-sequence-bracket-newline": "error",
1593
+ "yaml/flow-sequence-bracket-spacing": "error",
1594
+ "yaml/indent": ["error", indent === "tab" ? 2 : indent],
1595
+ "yaml/key-spacing": "error",
1596
+ "yaml/no-tab-indent": "error",
1597
+ "yaml/quotes": ["error", {
1598
+ avoidEscape: true,
1599
+ prefer: quotes === "backtick" ? "single" : quotes
1600
+ }],
1601
+ "yaml/spaced-comment": "error"
1602
+ } : {},
1603
+ ...overrides
1604
+ }
1605
+ },
1606
+ {
1607
+ files: ["pnpm-workspace.yaml"],
1608
+ name: "yaml/pnpm-workspace",
1609
+ rules: { "yaml/sort-keys": [
1610
+ "error",
1611
+ {
1612
+ order: [
1613
+ "packages",
1614
+ "overrides",
1615
+ "patchedDependencies",
1616
+ "hoistPattern",
1617
+ "catalog",
1618
+ "catalogs",
1619
+ "allowedDeprecatedVersions",
1620
+ "allowNonAppliedPatches",
1621
+ "configDependencies",
1622
+ "ignoredBuiltDependencies",
1623
+ "ignoredOptionalDependencies",
1624
+ "neverBuiltDependencies",
1625
+ "onlyBuiltDependencies",
1626
+ "onlyBuiltDependenciesFile",
1627
+ "packageExtensions",
1628
+ "peerDependencyRules",
1629
+ "supportedArchitectures"
1630
+ ],
1631
+ pathPattern: "^$"
1632
+ },
1633
+ {
1634
+ order: { type: "asc" },
1635
+ pathPattern: ".*"
1636
+ }
1637
+ ] }
1638
+ }
1639
+ ];
1794
1640
  }
1795
1641
 
1796
- // src/factory.ts
1797
- var flatConfigProps = [
1798
- "name",
1799
- "languageOptions",
1800
- "linterOptions",
1801
- "processor",
1802
- "plugins",
1803
- "rules",
1804
- "settings"
1642
+ //#endregion
1643
+ //#region src/factory.ts
1644
+ const flatConfigProps = [
1645
+ "name",
1646
+ "languageOptions",
1647
+ "linterOptions",
1648
+ "processor",
1649
+ "plugins",
1650
+ "rules",
1651
+ "settings"
1805
1652
  ];
1806
- var ReactPackages = ["react", "nest"];
1807
- var defaultPluginRenaming = {
1808
- "@eslint-react": "react",
1809
- "@eslint-react/dom": "react-dom",
1810
- "@eslint-react/hooks-extra": "react-hooks-extra",
1811
- "@eslint-react/naming-convention": "react-naming-convention",
1812
- "@stylistic": "style",
1813
- "@typescript-eslint": "ts",
1814
- "import-x": "import",
1815
- "n": "node",
1816
- "yml": "yaml"
1653
+ const defaultPluginRenaming = {
1654
+ "@eslint-react": "react",
1655
+ "@eslint-react/dom": "react-dom",
1656
+ "@eslint-react/hooks-extra": "react-hooks-extra",
1657
+ "@eslint-react/naming-convention": "react-naming-convention",
1658
+ "@stylistic": "style",
1659
+ "@typescript-eslint": "ts",
1660
+ "import-x": "import",
1661
+ "n": "node",
1662
+ "yml": "yaml"
1817
1663
  };
1664
+ /**
1665
+ * Construct an array of ESLint flat config items.
1666
+ *
1667
+ * @param {OptionsConfig & TypedFlatConfigItem} options
1668
+ * The options for generating the ESLint configurations.
1669
+ * @param {Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]} userConfigs
1670
+ * The user configurations to be merged with the generated configurations.
1671
+ * @returns {Promise<TypedFlatConfigItem[]>}
1672
+ * The merged ESLint configurations.
1673
+ */
1818
1674
  function config(options = {}, ...userConfigs) {
1819
- const {
1820
- autoRenamePlugins = true,
1821
- componentExts = [],
1822
- gitignore: enableGitignore = true,
1823
- jsx: enableJsx = true,
1824
- pnpm: enableCatalogs = false,
1825
- react: enableReact = ReactPackages.some((i) => isPackageExists3(i)),
1826
- regexp: enableRegexp = true,
1827
- typescript: enableTypeScript = isPackageExists3("typescript"),
1828
- unicorn: enableUnicorn = true,
1829
- unocss: enableUnoCSS = false
1830
- } = options;
1831
- let isInEditor = options.isInEditor;
1832
- if (isInEditor == null) {
1833
- isInEditor = isInEditorEnv();
1834
- if (isInEditor) {
1835
- console.log(
1836
- "[@ghettoddos/eslint-config] Detected running in editor, some rules are disabled."
1837
- );
1838
- }
1839
- }
1840
- const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
1841
- if (stylisticOptions && !("jsx" in stylisticOptions)) {
1842
- stylisticOptions.jsx = enableJsx;
1843
- }
1844
- const configs2 = [];
1845
- if (enableGitignore) {
1846
- if (typeof enableGitignore !== "boolean") {
1847
- configs2.push(
1848
- interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1849
- r({
1850
- name: "gitignore",
1851
- ...enableGitignore
1852
- })
1853
- ])
1854
- );
1855
- } else {
1856
- configs2.push(
1857
- interopDefault(import("eslint-config-flat-gitignore")).then((r) => [
1858
- r({
1859
- name: "gitignore",
1860
- strict: false
1861
- })
1862
- ])
1863
- );
1864
- }
1865
- }
1866
- const typescriptOptions = resolveSubOptions(options, "typescript");
1867
- const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
1868
- configs2.push(
1869
- ignores(options.ignores),
1870
- javascript({
1871
- isInEditor,
1872
- overrides: getOverrides(options, "javascript")
1873
- }),
1874
- comments(),
1875
- node(),
1876
- imports({
1877
- stylistic: stylisticOptions
1878
- }),
1879
- // Optional plugins (installed but not enabled by default)
1880
- perfectionist()
1881
- );
1882
- if (enableUnicorn) {
1883
- configs2.push(unicorn(enableUnicorn === true ? {} : enableUnicorn));
1884
- }
1885
- if (enableJsx) {
1886
- configs2.push(jsx());
1887
- }
1888
- if (enableTypeScript) {
1889
- configs2.push(
1890
- typescript({
1891
- ...typescriptOptions,
1892
- componentExts,
1893
- overrides: getOverrides(options, "typescript"),
1894
- type: options.type
1895
- })
1896
- );
1897
- }
1898
- if (stylisticOptions) {
1899
- configs2.push(
1900
- stylistic({
1901
- ...stylisticOptions,
1902
- overrides: getOverrides(options, "stylistic")
1903
- })
1904
- );
1905
- }
1906
- if (enableRegexp) {
1907
- configs2.push(regexp(typeof enableRegexp === "boolean" ? {} : enableRegexp));
1908
- }
1909
- if (enableReact) {
1910
- configs2.push(
1911
- react({
1912
- ...typescriptOptions,
1913
- overrides: getOverrides(options, "react"),
1914
- tsconfigPath
1915
- })
1916
- );
1917
- }
1918
- if (enableUnoCSS) {
1919
- configs2.push(
1920
- unocss({
1921
- ...resolveSubOptions(options, "unocss"),
1922
- overrides: getOverrides(options, "unocss")
1923
- })
1924
- );
1925
- }
1926
- if (options.jsonc ?? true) {
1927
- configs2.push(
1928
- jsonc({
1929
- overrides: getOverrides(options, "jsonc"),
1930
- stylistic: stylisticOptions
1931
- }),
1932
- sortPackageJson(),
1933
- sortTsconfig()
1934
- );
1935
- }
1936
- if (enableCatalogs) {
1937
- configs2.push(
1938
- pnpm()
1939
- );
1940
- }
1941
- if (options.yaml ?? true) {
1942
- configs2.push(
1943
- yaml({
1944
- overrides: getOverrides(options, "yaml"),
1945
- stylistic: stylisticOptions
1946
- })
1947
- );
1948
- }
1949
- if (options.toml ?? true) {
1950
- configs2.push(
1951
- toml({
1952
- overrides: getOverrides(options, "toml"),
1953
- stylistic: stylisticOptions
1954
- })
1955
- );
1956
- }
1957
- if (options.markdown ?? true) {
1958
- configs2.push(
1959
- markdown({
1960
- componentExts,
1961
- overrides: getOverrides(options, "markdown")
1962
- })
1963
- );
1964
- }
1965
- if (options.formatters) {
1966
- configs2.push(
1967
- formatters(
1968
- options.formatters,
1969
- typeof stylisticOptions === "boolean" ? {} : stylisticOptions
1970
- )
1971
- );
1972
- }
1973
- configs2.push(disables());
1974
- if ("files" in options) {
1975
- throw new Error(
1976
- '[@ghettoddos/eslint-config] The first argument should not contain the "files" property as the options are supposed to be global. Place it in the second or later config instead.'
1977
- );
1978
- }
1979
- const fusedConfig = flatConfigProps.reduce((acc, key) => {
1980
- if (key in options) {
1981
- acc[key] = options[key];
1982
- }
1983
- return acc;
1984
- }, {});
1985
- if (Object.keys(fusedConfig).length) {
1986
- configs2.push([fusedConfig]);
1987
- }
1988
- let composer = new FlatConfigComposer();
1989
- composer = composer.append(...configs2, ...userConfigs);
1990
- if (autoRenamePlugins) {
1991
- composer = composer.renamePlugins(defaultPluginRenaming);
1992
- }
1993
- if (isInEditor) {
1994
- composer = composer.disableRulesFix(
1995
- ["unused-imports/no-unused-imports", "prefer-const"],
1996
- {
1997
- builtinRules: () => import(["eslint", "use-at-your-own-risk"].join("/")).then(
1998
- (r) => r.builtinRules
1999
- )
2000
- }
2001
- );
2002
- }
2003
- return composer;
1675
+ const isUsingReact = ReactPackages.some((i) => isPackageExists(i));
1676
+ const { autoRenamePlugins = true, componentExts = [], effector: enableEffector = isPackageExists("effector"), gitignore: enableGitignore = true, jsx: enableJsx = true, jsxA11y: enableJsxA11y = isUsingReact, next: enableNext = NextJsPackages.some((i) => isPackageExists(i)), pnpm: enableCatalogs = false, react: enableReact = isUsingReact, regexp: enableRegexp = true, typescript: enableTypeScript = isPackageExists("typescript"), unicorn: enableUnicorn = true, unocss: enableUnoCSS = false } = options;
1677
+ let isInEditor = options.isInEditor;
1678
+ if (isInEditor == null) {
1679
+ isInEditor = isInEditorEnv();
1680
+ if (isInEditor) console.log("[@ghettoddos/eslint-config] Detected running in editor, some rules are disabled.");
1681
+ }
1682
+ const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
1683
+ if (stylisticOptions && !("jsx" in stylisticOptions)) stylisticOptions.jsx = enableJsx;
1684
+ const configs$1 = [];
1685
+ if (enableGitignore) if (typeof enableGitignore !== "boolean") configs$1.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
1686
+ name: "gitignore",
1687
+ ...enableGitignore
1688
+ })]));
1689
+ else configs$1.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
1690
+ name: "gitignore",
1691
+ strict: false
1692
+ })]));
1693
+ const typescriptOptions = resolveSubOptions(options, "typescript");
1694
+ const tsconfigPath = "tsconfigPath" in typescriptOptions ? typescriptOptions.tsconfigPath : void 0;
1695
+ configs$1.push(ignores(options.ignores), javascript({
1696
+ isInEditor,
1697
+ overrides: getOverrides(options, "javascript")
1698
+ }), comments(), node(), imports({ stylistic: stylisticOptions }), perfectionist());
1699
+ if (enableUnicorn) configs$1.push(unicorn(enableUnicorn === true ? {} : enableUnicorn));
1700
+ if (enableJsx) configs$1.push(jsx());
1701
+ if (enableTypeScript) configs$1.push(typescript({
1702
+ ...typescriptOptions,
1703
+ componentExts,
1704
+ overrides: getOverrides(options, "typescript"),
1705
+ type: options.type
1706
+ }));
1707
+ if (stylisticOptions) configs$1.push(stylistic({
1708
+ ...stylisticOptions,
1709
+ overrides: getOverrides(options, "stylistic")
1710
+ }));
1711
+ if (enableRegexp) configs$1.push(regexp(typeof enableRegexp === "boolean" ? {} : enableRegexp));
1712
+ if (enableReact) configs$1.push(react({
1713
+ ...typescriptOptions,
1714
+ overrides: getOverrides(options, "react"),
1715
+ tsconfigPath
1716
+ }));
1717
+ if (enableJsxA11y) configs$1.push(jsxA11y({ overrides: getOverrides(options, "jsxA11y") }));
1718
+ if (enableNext) configs$1.push(next({ overrides: getOverrides(options, "next") }));
1719
+ if (enableEffector) configs$1.push(effector({
1720
+ ...resolveSubOptions(options, "effector"),
1721
+ overrides: getOverrides(options, "effector")
1722
+ }));
1723
+ if (enableUnoCSS) configs$1.push(unocss({
1724
+ ...resolveSubOptions(options, "unocss"),
1725
+ overrides: getOverrides(options, "unocss")
1726
+ }));
1727
+ if (options.jsonc ?? true) configs$1.push(jsonc({
1728
+ overrides: getOverrides(options, "jsonc"),
1729
+ stylistic: stylisticOptions
1730
+ }), sortPackageJson(), sortTsconfig());
1731
+ if (enableCatalogs) configs$1.push(pnpm());
1732
+ if (options.yaml ?? true) configs$1.push(yaml({
1733
+ overrides: getOverrides(options, "yaml"),
1734
+ stylistic: stylisticOptions
1735
+ }));
1736
+ if (options.toml ?? true) configs$1.push(toml({
1737
+ overrides: getOverrides(options, "toml"),
1738
+ stylistic: stylisticOptions
1739
+ }));
1740
+ if (options.markdown ?? true) configs$1.push(markdown({
1741
+ componentExts,
1742
+ overrides: getOverrides(options, "markdown")
1743
+ }));
1744
+ if (options.formatters) configs$1.push(formatters(options.formatters, typeof stylisticOptions === "boolean" ? {} : stylisticOptions));
1745
+ configs$1.push(disables());
1746
+ if ("files" in options) throw new Error("[@ghettoddos/eslint-config] The first argument should not contain the \"files\" property as the options are supposed to be global. Place it in the second or later config instead.");
1747
+ const fusedConfig = flatConfigProps.reduce((acc, key) => {
1748
+ if (key in options) acc[key] = options[key];
1749
+ return acc;
1750
+ }, {});
1751
+ if (Object.keys(fusedConfig).length) configs$1.push([fusedConfig]);
1752
+ let composer = new FlatConfigComposer();
1753
+ composer = composer.append(...configs$1, ...userConfigs);
1754
+ if (autoRenamePlugins) composer = composer.renamePlugins(defaultPluginRenaming);
1755
+ if (isInEditor) composer = composer.disableRulesFix(["unused-imports/no-unused-imports", "prefer-const"], { builtinRules: () => import(["eslint", "use-at-your-own-risk"].join("/")).then((r) => r.builtinRules) });
1756
+ return composer;
2004
1757
  }
2005
1758
  function resolveSubOptions(options, key) {
2006
- return typeof options[key] === "boolean" ? {} : options[key] || {};
1759
+ return typeof options[key] === "boolean" ? {} : options[key] || {};
2007
1760
  }
2008
1761
  function getOverrides(options, key) {
2009
- const sub = resolveSubOptions(options, key);
2010
- return {
2011
- ...options.overrides?.[key],
2012
- ..."overrides" in sub ? sub.overrides : {}
2013
- };
1762
+ const sub = resolveSubOptions(options, key);
1763
+ return {
1764
+ ...options.overrides?.[key],
1765
+ ..."overrides" in sub ? sub.overrides : {}
1766
+ };
2014
1767
  }
2015
1768
 
2016
- // src/index.ts
2017
- var index_default = config;
2018
- export {
2019
- GLOB_ALL_SRC,
2020
- GLOB_CSS,
2021
- GLOB_EXCLUDE,
2022
- GLOB_HTML,
2023
- GLOB_JS,
2024
- GLOB_JSON,
2025
- GLOB_JSON5,
2026
- GLOB_JSONC,
2027
- GLOB_JSX,
2028
- GLOB_MARKDOWN,
2029
- GLOB_MARKDOWN_CODE,
2030
- GLOB_MARKDOWN_IN_MARKDOWN,
2031
- GLOB_POSTCSS,
2032
- GLOB_SCSS,
2033
- GLOB_SRC,
2034
- GLOB_SRC_EXT,
2035
- GLOB_STYLE,
2036
- GLOB_SVG,
2037
- GLOB_TOML,
2038
- GLOB_TS,
2039
- GLOB_TSX,
2040
- GLOB_XML,
2041
- GLOB_YAML,
2042
- StylisticConfigDefaults,
2043
- combine,
2044
- comments,
2045
- config,
2046
- index_default as default,
2047
- defaultPluginRenaming,
2048
- disables,
2049
- ensurePackages,
2050
- formatters,
2051
- getOverrides,
2052
- ignores,
2053
- imports,
2054
- interopDefault,
2055
- isInEditorEnv,
2056
- isInGitHooksOrLintStaged,
2057
- isPackageInScope,
2058
- javascript,
2059
- jsonc,
2060
- jsx,
2061
- markdown,
2062
- node,
2063
- parserPlain,
2064
- perfectionist,
2065
- pnpm,
2066
- react,
2067
- regexp,
2068
- renameRules,
2069
- resolveSubOptions,
2070
- sortPackageJson,
2071
- sortTsconfig,
2072
- stylistic,
2073
- toml,
2074
- typescript,
2075
- unicorn,
2076
- unocss,
2077
- yaml
2078
- };
1769
+ //#endregion
1770
+ //#region src/index.ts
1771
+ var src_default = config;
1772
+
1773
+ //#endregion
1774
+ export { GLOB_ALL_SRC, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVG, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_XML, GLOB_YAML, StylisticConfigDefaults, combine, comments, config, src_default as default, defaultPluginRenaming, disables, effector, ensurePackages, formatters, getOverrides, ignores, imports, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, javascript, jsonc, jsx, jsxA11y, markdown, next, node, parserPlain, perfectionist, pnpm, react, regexp, renameRules, resolveSubOptions, sortPackageJson, sortTsconfig, stylistic, toml, typescript, unicorn, unocss, yaml };