@eienjs/eslint-config 0.1.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.
@@ -0,0 +1,85 @@
1
+ import { Awaitable, ConfigNames, OptionsComponentExts, OptionsConfig, OptionsFiles, OptionsFormatters, OptionsHasTypeScript, OptionsIsInEditor, OptionsOverrides, OptionsRegExp, OptionsStylistic, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes, OptionsTypescript, OptionsVue, RuleOptions, Rules, StylisticConfig, TypedFlatConfigItem } from "./types-BDuTVdZ8.js";
2
+ import { FlatConfigComposer } from "eslint-flat-config-utils";
3
+ import { Linter } from "eslint";
4
+
5
+ //#region src/factory.d.ts
6
+ declare const defaultPluginRenaming: {
7
+ 'import-lite': string;
8
+ vitest: string;
9
+ yml: string;
10
+ };
11
+ declare function eienjs(options?: OptionsConfig & Omit<TypedFlatConfigItem, 'files'>): FlatConfigComposer<TypedFlatConfigItem, ConfigNames>;
12
+ type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
13
+ declare function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolvedOptions<OptionsConfig[K]>;
14
+ declare function getOverrides<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): Partial<Linter.RulesRecord & RuleOptions>;
15
+ //#endregion
16
+ //#region src/globs.d.ts
17
+ declare const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
18
+ declare const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
19
+ declare const GLOB_JS = "**/*.?([cm])js";
20
+ declare const GLOB_JSX = "**/*.?([cm])jsx";
21
+ declare const GLOB_TS = "**/*.?([cm])ts";
22
+ declare const GLOB_TSX = "**/*.?([cm])tsx";
23
+ declare const GLOB_STYLE = "**/*.{c,le,sc}ss";
24
+ declare const GLOB_CSS = "**/*.css";
25
+ declare const GLOB_POSTCSS = "**/*.{p,post}css";
26
+ declare const GLOB_LESS = "**/*.less";
27
+ declare const GLOB_SCSS = "**/*.scss";
28
+ declare const GLOB_JSON = "**/*.json";
29
+ declare const GLOB_JSON5 = "**/*.json5";
30
+ declare const GLOB_JSONC = "**/*.jsonc";
31
+ declare const GLOB_MARKDOWN = "**/*.md";
32
+ declare const GLOB_MARKDOWN_IN_MARKDOWN = "**/*.md/*.md";
33
+ declare const GLOB_VUE = "**/*.vue";
34
+ declare const GLOB_YAML = "**/*.y?(a)ml";
35
+ declare const GLOB_TOML = "**/*.toml";
36
+ declare const GLOB_XML = "**/*.xml";
37
+ declare const GLOB_SVG = "**/*.svg";
38
+ declare const GLOB_HTML = "**/*.htm?(l)";
39
+ declare const GLOB_ASTRO = "**/*.astro";
40
+ declare const GLOB_ASTRO_TS = "**/*.astro/*.ts";
41
+ declare const GLOB_MARKDOWN_CODE = "**/*.md/**/*.?([cm])[jt]s?(x)";
42
+ declare const GLOB_TESTS: string[];
43
+ declare const GLOB_ALL_SRC: string[];
44
+ declare const GLOB_EXCLUDE: string[];
45
+ //#endregion
46
+ //#region src/utils.d.ts
47
+ declare const parserPlain: {
48
+ meta: {
49
+ name: string;
50
+ };
51
+ parseForESLint: (code: string) => {
52
+ ast: {
53
+ body: never[];
54
+ comments: never[];
55
+ loc: {
56
+ end: number;
57
+ start: number;
58
+ };
59
+ range: number[];
60
+ tokens: never[];
61
+ type: string;
62
+ };
63
+ scopeManager: null;
64
+ services: {
65
+ isPlain: boolean;
66
+ };
67
+ visitorKeys: {
68
+ Program: never[];
69
+ };
70
+ };
71
+ };
72
+ /**
73
+ * Combine array and non-array configs into a single array.
74
+ */
75
+ declare function combine(...configs: Awaitable<TypedFlatConfigItem | TypedFlatConfigItem[]>[]): Promise<TypedFlatConfigItem[]>;
76
+ declare function toArray<T>(value: T | T[]): T[];
77
+ declare function interopDefault<T>(m: Awaitable<T>): Promise<T extends {
78
+ default: infer U;
79
+ } ? U : T>;
80
+ declare function isPackageInScope(name: string): boolean;
81
+ declare function ensurePackages(packages: (string | undefined)[]): Promise<void>;
82
+ declare function isInEditorEnv(): boolean;
83
+ declare function isInGitHooksOrLintStaged(): boolean;
84
+ //#endregion
85
+ export { Awaitable, ConfigNames, GLOB_ALL_SRC, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVG, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, OptionsComponentExts, OptionsConfig, OptionsFiles, OptionsFormatters, OptionsHasTypeScript, OptionsIsInEditor, OptionsOverrides, OptionsRegExp, OptionsStylistic, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes, OptionsTypescript, OptionsVue, ResolvedOptions, Rules, StylisticConfig, TypedFlatConfigItem, combine, eienjs as default, defaultPluginRenaming, eienjs, ensurePackages, getOverrides, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, parserPlain, resolveSubOptions, toArray };
package/dist/index.js ADDED
@@ -0,0 +1,125 @@
1
+ import { GLOB_ALL_SRC, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVG, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, astro, combine, command, comments, disables, ensurePackages, formatters, ignores, imports, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, javascript, jsdoc, jsonc, markdown, node, parserPlain, perfectionist, pnpm, regexp, sortPackageJson, sortTsconfig, stylistic, test, toArray, toml, typescript, unicorn, vue, yaml } from "./configs-B_fhQhgr.js";
2
+ import { FlatConfigComposer } from "eslint-flat-config-utils";
3
+ import { isPackageExists } from "local-pkg";
4
+
5
+ //#region src/factory.ts
6
+ const flatConfigProps = [
7
+ "name",
8
+ "languageOptions",
9
+ "linterOptions",
10
+ "processor",
11
+ "plugins",
12
+ "rules",
13
+ "settings"
14
+ ];
15
+ const VuePackages = [
16
+ "vue",
17
+ "nuxt",
18
+ "vitepress",
19
+ "@slidev/cli"
20
+ ];
21
+ const defaultPluginRenaming = {
22
+ "import-lite": "import",
23
+ "vitest": "test",
24
+ "yml": "yaml"
25
+ };
26
+ function eienjs(options = {}) {
27
+ const { astro: enableAstro = false, componentExts = [], gitignore: enableGitignore = true, imports: enableImports = true, pnpm: enableCatalogs = false, regexp: enableRegexp = true, typescript: enableTypeScript = isPackageExists("typescript"), unicorn: enableUnicorn = true, vue: enableVue = VuePackages.some((i) => isPackageExists(i)) } = options;
28
+ let { isInEditor } = options;
29
+ if (isInEditor == null) {
30
+ isInEditor = isInEditorEnv();
31
+ if (isInEditor) console.info("[@eienjs/eslint-config] Detected running in editor, some rules are disabled.");
32
+ }
33
+ const stylisticOptions = options.stylistic === false ? false : typeof options.stylistic === "object" ? options.stylistic : {};
34
+ const configs = [];
35
+ if (enableGitignore) if (typeof enableGitignore === "boolean") configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
36
+ name: "eienjs/gitignore",
37
+ strict: false
38
+ })]));
39
+ else configs.push(interopDefault(import("eslint-config-flat-gitignore")).then((r) => [r({
40
+ name: "eienjs/gitignore",
41
+ ...enableGitignore
42
+ })]));
43
+ const typescriptOptions = resolveSubOptions(options, "typescript");
44
+ configs.push(ignores(options.ignores), javascript({
45
+ isInEditor,
46
+ overrides: getOverrides(options, "javascript")
47
+ }), comments(), node(), jsdoc({ stylistic: stylisticOptions }), imports({ stylistic: stylisticOptions }), command(), perfectionist());
48
+ if (enableImports) configs.push(imports(enableImports === true ? { stylistic: stylisticOptions } : {
49
+ stylistic: stylisticOptions,
50
+ ...enableImports
51
+ }));
52
+ if (enableUnicorn) configs.push(unicorn(enableUnicorn === true ? {} : enableUnicorn));
53
+ if (enableVue) componentExts.push("vue");
54
+ if (enableTypeScript) configs.push(typescript({
55
+ ...typescriptOptions,
56
+ componentExts,
57
+ overrides: getOverrides(options, "typescript")
58
+ }));
59
+ if (stylisticOptions) configs.push(stylistic({
60
+ ...stylisticOptions,
61
+ overrides: getOverrides(options, "stylistic")
62
+ }));
63
+ if (enableRegexp) configs.push(regexp(typeof enableRegexp === "boolean" ? {} : enableRegexp));
64
+ if (options.test ?? true) configs.push(test({
65
+ isInEditor,
66
+ overrides: getOverrides(options, "test")
67
+ }));
68
+ if (enableVue) configs.push(vue({
69
+ ...resolveSubOptions(options, "vue"),
70
+ overrides: getOverrides(options, "vue"),
71
+ stylistic: stylisticOptions,
72
+ typescript: Boolean(enableTypeScript)
73
+ }));
74
+ if (enableAstro) configs.push(astro({
75
+ overrides: getOverrides(options, "astro"),
76
+ stylistic: stylisticOptions
77
+ }));
78
+ if (options.jsonc ?? true) configs.push(jsonc({
79
+ overrides: getOverrides(options, "jsonc"),
80
+ stylistic: stylisticOptions
81
+ }), sortPackageJson(), sortTsconfig());
82
+ if (enableCatalogs) configs.push(pnpm());
83
+ if (options.yaml ?? true) configs.push(yaml({
84
+ overrides: getOverrides(options, "yaml"),
85
+ stylistic: stylisticOptions
86
+ }));
87
+ if (options.toml ?? true) configs.push(toml({
88
+ overrides: getOverrides(options, "toml"),
89
+ stylistic: stylisticOptions
90
+ }));
91
+ if (options.markdown ?? true) configs.push(markdown({
92
+ componentExts,
93
+ overrides: getOverrides(options, "markdown")
94
+ }));
95
+ if (options.formatters) configs.push(formatters(options.formatters, typeof stylisticOptions === "boolean" ? {} : stylisticOptions));
96
+ configs.push(disables());
97
+ if ("files" in options) throw new Error("[@eienjs/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.");
98
+ const fusedConfig = flatConfigProps.reduce((acc, key) => {
99
+ if (key in options) acc[key] = options[key];
100
+ return acc;
101
+ }, {});
102
+ if (Object.keys(fusedConfig).length > 0) configs.push([fusedConfig]);
103
+ let composer = new FlatConfigComposer();
104
+ composer = composer.append(...configs).renamePlugins(defaultPluginRenaming);
105
+ if (isInEditor) composer = composer.disableRulesFix([
106
+ "unused-imports/no-unused-imports",
107
+ "test/no-only-tests",
108
+ "prefer-const"
109
+ ], { builtinRules: () => import(["eslint", "use-at-your-own-risk"].join("/")).then((r) => r.builtinRules) });
110
+ return composer;
111
+ }
112
+ function resolveSubOptions(options, key) {
113
+ return typeof options[key] === "boolean" ? {} : options[key] || {};
114
+ }
115
+ function getOverrides(options, key) {
116
+ const sub = resolveSubOptions(options, key);
117
+ return { ..."overrides" in sub ? sub.overrides : {} };
118
+ }
119
+
120
+ //#endregion
121
+ //#region src/index.ts
122
+ var src_default = eienjs;
123
+
124
+ //#endregion
125
+ export { GLOB_ALL_SRC, GLOB_ASTRO, GLOB_ASTRO_TS, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_MARKDOWN_IN_MARKDOWN, GLOB_POSTCSS, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_SVG, GLOB_TESTS, GLOB_TOML, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_XML, GLOB_YAML, combine, src_default as default, defaultPluginRenaming, eienjs, ensurePackages, getOverrides, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, parserPlain, resolveSubOptions, toArray };