@debbl/eslint-config 0.0.64 → 1.0.0-beta.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,88 @@
1
+ import { FlatESLintConfigItem } from 'eslint-define-config';
2
+ export { basic, comments, ignores, imports, js, jsdoc, jsonc, markdown, node, sortPackageJson, sortTsconfig, test, unicorn, yml } from '@debbl/eslint-config-basic';
3
+ export { ts, tsWithLanguageServer } from '@debbl/eslint-config-ts';
4
+ export { prettier } from '@debbl/eslint-config-prettier';
5
+ export { vue } from '@debbl/eslint-config-vue';
6
+ export { solid } from '@debbl/eslint-config-solid';
7
+ export { react } from '@debbl/eslint-config-react';
8
+
9
+ interface OptionsTypeScriptWithLanguageServer {
10
+ tsconfigPath: string;
11
+ tsconfigRootDir?: string;
12
+ }
13
+ interface OptionsConfig {
14
+ /**
15
+ * Enable TypeScript support.
16
+ *
17
+ * Passing an object to enable TypeScript Language Server support.
18
+ *
19
+ * @default auto-detect based on the dependencies
20
+ */
21
+ typescript?: boolean | OptionsTypeScriptWithLanguageServer;
22
+ /**
23
+ * Enable test support.
24
+ *
25
+ * @default true
26
+ */
27
+ test?: boolean;
28
+ /**
29
+ * Enable Vue support.
30
+ *
31
+ * @default auto-detect based on the dependencies
32
+ */
33
+ vue?: boolean;
34
+ /**
35
+ * Enable React support.
36
+ *
37
+ * @default auto-detect based on the dependencies
38
+ */
39
+ react?: boolean;
40
+ /**
41
+ * Enable Solid support.
42
+ *
43
+ * @default auto-detect based on the dependencies
44
+ */
45
+ solid?: boolean;
46
+ /**
47
+ * Enable TailwindCSS support.
48
+ *
49
+ * @default auto-detect based on the dependencies
50
+ */
51
+ tailwindcss?: boolean;
52
+ /**
53
+ * Enable JSONC support.
54
+ *
55
+ * @default true
56
+ */
57
+ jsonc?: boolean;
58
+ /**
59
+ * Enable YAML support.
60
+ *
61
+ * @default true
62
+ */
63
+ yaml?: boolean;
64
+ /**
65
+ * Enable Markdown support.
66
+ *
67
+ * @default true
68
+ */
69
+ markdown?: boolean;
70
+ /**
71
+ * Enable stylistic rules.
72
+ *
73
+ * @default true
74
+ */
75
+ stylistic?: boolean;
76
+ /**
77
+ * Control to disable some rules in editors.
78
+ * @default auto-detect based on the process.env
79
+ */
80
+ isInEditor?: boolean;
81
+ }
82
+
83
+ /**
84
+ * Construct an array of ESLint flat config items.
85
+ */
86
+ declare function config(options?: OptionsConfig, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
87
+
88
+ export { config, config as default };
package/dist/index.js ADDED
@@ -0,0 +1,167 @@
1
+ // src/factory.ts
2
+ import process from "process";
3
+
4
+ // ../../node_modules/local-pkg/index.mjs
5
+ import { createRequire } from "module";
6
+ var _require = createRequire(import.meta.url);
7
+ function isPackageExists(name, options) {
8
+ return !!resolvePackage(name, options);
9
+ }
10
+ function resolvePackage(name, options = {}) {
11
+ try {
12
+ return _require.resolve(`${name}/package.json`, options);
13
+ } catch {
14
+ }
15
+ try {
16
+ return _require.resolve(name, options);
17
+ } catch (e) {
18
+ if (e.code !== "MODULE_NOT_FOUND")
19
+ console.error(e);
20
+ return false;
21
+ }
22
+ }
23
+
24
+ // src/factory.ts
25
+ import {
26
+ comments,
27
+ ignores,
28
+ imports,
29
+ js,
30
+ jsdoc,
31
+ jsonc,
32
+ markdown,
33
+ node,
34
+ sortPackageJson,
35
+ sortTsconfig,
36
+ test,
37
+ unicorn,
38
+ yml
39
+ } from "@debbl/eslint-config-basic";
40
+ import { ts, tsWithLanguageServer } from "@debbl/eslint-config-ts";
41
+ import { vue } from "@debbl/eslint-config-vue";
42
+ import { react } from "@debbl/eslint-config-react";
43
+ import { solid } from "@debbl/eslint-config-solid";
44
+ import { tailwindcss } from "@debbl/eslint-config-tailwindcss";
45
+
46
+ // ../../src/globs.ts
47
+ var GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
48
+ var GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
49
+ var GLOB_MARKDOWN = "**/*.md";
50
+ var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
51
+ var GLOB_TESTS = [
52
+ `**/__tests__/**/*.${GLOB_SRC_EXT}`,
53
+ `**/*.spec.${GLOB_SRC_EXT}`,
54
+ `**/*.test.${GLOB_SRC_EXT}`
55
+ ];
56
+
57
+ // ../../src/utils.ts
58
+ function combine(...configs) {
59
+ return configs.flatMap(
60
+ (config2) => Array.isArray(config2) ? config2 : [config2]
61
+ );
62
+ }
63
+
64
+ // src/factory.ts
65
+ function config(options = {}, ...userConfigs) {
66
+ const isInEditor = options.isInEditor ?? !!((process.env.VSCODE_PID || process.env.JETBRAINS_IDE) && !process.env.CI);
67
+ const enableVue = options.vue ?? (isPackageExists("vue") || isPackageExists("nuxt") || isPackageExists("vitepress") || isPackageExists("@slidev/cli"));
68
+ const enableReact = options.react ?? isPackageExists("react");
69
+ const enableSolid = options.solid ?? isPackageExists("solid-js");
70
+ const enableTailwindcss = options.tailwindcss ?? isPackageExists("tailwindcss");
71
+ const enableTypeScript = options.typescript ?? isPackageExists("typescript");
72
+ const configs = [
73
+ ignores,
74
+ js({ isInEditor }),
75
+ comments,
76
+ node,
77
+ jsdoc,
78
+ imports,
79
+ unicorn
80
+ ];
81
+ const componentExts = [];
82
+ if (enableVue)
83
+ componentExts.push("vue");
84
+ if (enableReact)
85
+ componentExts.push("react");
86
+ if (enableSolid)
87
+ componentExts.push("solid");
88
+ if (enableTailwindcss)
89
+ componentExts.push("tailwindcss");
90
+ if (enableTypeScript) {
91
+ configs.push(ts({ componentExts }));
92
+ if (typeof enableTypeScript !== "boolean") {
93
+ configs.push(
94
+ tsWithLanguageServer({
95
+ ...enableTypeScript,
96
+ componentExts
97
+ })
98
+ );
99
+ }
100
+ }
101
+ if (options.test ?? true)
102
+ configs.push(test({ isInEditor }));
103
+ if (enableVue)
104
+ configs.push(vue({ ts: !!enableTypeScript }));
105
+ if (enableReact)
106
+ configs.push(react());
107
+ if (enableSolid)
108
+ configs.push(solid());
109
+ if (enableTailwindcss)
110
+ configs.push(tailwindcss());
111
+ if (options.jsonc ?? true) {
112
+ configs.push(jsonc, sortPackageJson, sortTsconfig);
113
+ }
114
+ if (options.yaml ?? true)
115
+ configs.push(yml);
116
+ if (options.markdown ?? true)
117
+ configs.push(markdown({ componentExts }));
118
+ return combine(...configs, ...userConfigs);
119
+ }
120
+
121
+ // src/index.ts
122
+ import {
123
+ basic,
124
+ comments as comments2,
125
+ ignores as ignores2,
126
+ imports as imports2,
127
+ js as js2,
128
+ jsdoc as jsdoc2,
129
+ jsonc as jsonc2,
130
+ markdown as markdown2,
131
+ node as node2,
132
+ sortPackageJson as sortPackageJson2,
133
+ sortTsconfig as sortTsconfig2,
134
+ test as test2,
135
+ unicorn as unicorn2,
136
+ yml as yml2
137
+ } from "@debbl/eslint-config-basic";
138
+ import { ts as ts2, tsWithLanguageServer as tsWithLanguageServer2 } from "@debbl/eslint-config-ts";
139
+ import { prettier } from "@debbl/eslint-config-prettier";
140
+ import { vue as vue2 } from "@debbl/eslint-config-vue";
141
+ import { solid as solid2 } from "@debbl/eslint-config-solid";
142
+ import { react as react2 } from "@debbl/eslint-config-react";
143
+ var src_default = config;
144
+ export {
145
+ basic,
146
+ comments2 as comments,
147
+ config,
148
+ src_default as default,
149
+ ignores2 as ignores,
150
+ imports2 as imports,
151
+ js2 as js,
152
+ jsdoc2 as jsdoc,
153
+ jsonc2 as jsonc,
154
+ markdown2 as markdown,
155
+ node2 as node,
156
+ prettier,
157
+ react2 as react,
158
+ solid2 as solid,
159
+ sortPackageJson2 as sortPackageJson,
160
+ sortTsconfig2 as sortTsconfig,
161
+ test2 as test,
162
+ ts2 as ts,
163
+ tsWithLanguageServer2 as tsWithLanguageServer,
164
+ unicorn2 as unicorn,
165
+ vue2 as vue,
166
+ yml2 as yml
167
+ };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@debbl/eslint-config",
3
- "version": "0.0.64",
3
+ "type": "module",
4
+ "version": "1.0.0-beta.0",
4
5
  "description": "",
5
6
  "author": "Debbl <me@aiwan.run> (https://github.com/Debbl/)",
6
7
  "license": "MIT",
@@ -8,26 +9,26 @@
8
9
  "keywords": [
9
10
  "eslint-config"
10
11
  ],
11
- "main": "index.js",
12
+ "main": "dist/index.js",
12
13
  "files": [
13
- "index.js"
14
+ "dist"
14
15
  ],
15
16
  "peerDependencies": {
16
17
  "eslint": ">=8.24.0"
17
18
  },
18
19
  "dependencies": {
19
- "@debbl/eslint-config-basic": "0.0.64",
20
- "@debbl/eslint-config-react": "0.0.64",
21
- "@debbl/eslint-config-ts": "0.0.64",
22
- "@debbl/eslint-config-solid": "0.0.64",
23
- "@debbl/eslint-config-vue": "0.0.64",
24
- "@debbl/eslint-config-tailwindcss": "0.0.64",
25
- "@debbl/eslint-config-prettier": "0.0.64"
20
+ "@debbl/eslint-config-basic": "1.0.0-beta.0",
21
+ "@debbl/eslint-config-solid": "1.0.0-beta.0",
22
+ "@debbl/eslint-config-prettier": "1.0.0-beta.0",
23
+ "@debbl/eslint-config-react": "1.0.0-beta.0",
24
+ "@debbl/eslint-config-tailwindcss": "1.0.0-beta.0",
25
+ "@debbl/eslint-config-vue": "1.0.0-beta.0",
26
+ "@debbl/eslint-config-ts": "1.0.0-beta.0"
26
27
  },
27
28
  "devDependencies": {
28
- "eslint": "^8.49.0"
29
+ "eslint": "^8.50.0"
29
30
  },
30
31
  "scripts": {
31
- "test": "echo \"Error: no test specified\" && exit 1"
32
+ "build": "tsup src/index.ts --format esm --clean --dts"
32
33
  }
33
34
  }
package/index.js DELETED
@@ -1,48 +0,0 @@
1
- const path = require("node:path");
2
- const { cwd } = require("node:process");
3
-
4
- const isTS = isPackageExists("typescript");
5
- const isReact = isPackageExists("react");
6
- const isVue = isPackageExists("vue");
7
- const isSolid = isPackageExists("solid-js");
8
- const isTailwindCSS = isPackageExists("tailwindcss");
9
-
10
- const allowExtends = [
11
- isReact ? "@debbl/eslint-config-react" : null,
12
- isVue ? "@debbl/eslint-config-vue" : null,
13
- isSolid ? "@debbl/eslint-config-solid" : null,
14
- isTailwindCSS ? "@debbl/eslint-config-tailwindcss" : null,
15
- ].filter(Boolean);
16
-
17
- if (allowExtends.length === 0) {
18
- if (isTS) {
19
- allowExtends.push("@debbl/eslint-config-ts");
20
- } else {
21
- allowExtends.push("@debbl/eslint-config-basic");
22
- }
23
- }
24
-
25
- // use prettier
26
- allowExtends.push("@debbl/eslint-config-prettier");
27
-
28
- // eslint-disable-next-line no-console
29
- console.info("[@debbl/eslint-config] Current running extends:", allowExtends);
30
-
31
- // determine if the package is exists
32
- function isPackageExists(name) {
33
- const {
34
- dependencies = [],
35
- devDependencies = [],
36
- peerDependencies = [],
37
- } = require(path.resolve(cwd(), "./package.json"));
38
-
39
- return (
40
- Object.keys(dependencies || {}).includes(name) ||
41
- Object.keys(devDependencies || {}).includes(name) ||
42
- Object.keys(peerDependencies || {}).includes(name)
43
- );
44
- }
45
-
46
- module.exports = {
47
- extends: allowExtends,
48
- };