@debbl/eslint-config 1.0.0-beta.0 → 1.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # @debbl/eslint-config
2
+
3
+ [![npm](https://img.shields.io/npm/v/@debbl/eslint-config?color=444&label=)](https://npmjs.com/package/@debbl/eslint-config)
4
+
5
+ # 参考
6
+
7
+ > https://github.com/antfu/eslint-config
8
+
9
+ # 使用
10
+
11
+ - `@debbl/eslint-config`
12
+ - `@debbl/eslint-config-ts` TypeScript
13
+ - `@debbl/eslint-config-vue` Vue
14
+ - `@debbl/eslint-config-react` React
15
+ - `@debbl/eslint-config-prettier` Prettier
16
+ - `@debbl/eslint-config-solid` Solid
17
+ - `@debbl/eslint-config-tailwindcss` Tailwindcss
18
+
19
+ ## 安装
20
+
21
+ ```bash
22
+ pnpm i eslint @debbl/eslint-config -D
23
+ ```
24
+
25
+ ### 配置 `eslint.config.js`
26
+
27
+ ```js
28
+ import { config } from "@debbl/eslint-config";
29
+
30
+ export default config({
31
+ ts: true,
32
+ react: true,
33
+ });
34
+ ```
35
+
36
+ - 默认使用 ts 和 prettier
37
+
38
+ ```js
39
+ import { config } from "@debbl/eslint-config";
40
+
41
+ export default config();
42
+ ```
43
+
44
+ - react 默认开启 ts
45
+ - vue 默认开启 ts
46
+ - solid 默认开启 ts
47
+ - 开启 tailwindcss
48
+
49
+ ```js
50
+ import { config } from "@debbl/eslint-config";
51
+
52
+ export default config({
53
+ tailwindcss: true,
54
+ });
55
+ ```
56
+
57
+ ### 配置 `Prettier`, 会覆盖默认的规则
58
+
59
+ ```js
60
+ import { config } from "@debbl/eslint-config";
61
+
62
+ export default config(
63
+ {
64
+ ts: true,
65
+ react: true,
66
+ },
67
+ {
68
+ rules: {
69
+ "prettier/prettier": [
70
+ "warn",
71
+ {
72
+ printWidth: 100, // 打印宽度, 一行最长120个字符
73
+ tabWidth: 2, // 缩进的空格数
74
+ useTabs: false, // 缩进使用空格,不适用制表符
75
+ semi: true, // 语句末尾添加分号
76
+ singleQuote: false, // 使用单引号
77
+ trailingComma: "all", // 尾随逗号
78
+ bracketSpacing: true, // { foo: bar } 有空格
79
+ quoteProps: "consistent", // 对象属性 引号
80
+ },
81
+ {
82
+ usePrettierrc: false,
83
+ fileInfoOptions: {
84
+ withNodeModules: true,
85
+ },
86
+ },
87
+ ],
88
+ },
89
+ }
90
+ );
91
+ ```
package/dist/index.d.ts CHANGED
@@ -6,19 +6,55 @@ export { vue } from '@debbl/eslint-config-vue';
6
6
  export { solid } from '@debbl/eslint-config-solid';
7
7
  export { react } from '@debbl/eslint-config-react';
8
8
 
9
+ declare const OFF = 0;
10
+
11
+ declare const GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
12
+ declare const GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
13
+ declare const GLOB_JS = "**/*.?([cm])js";
14
+ declare const GLOB_JSX = "**/*.?([cm])jsx";
15
+ declare const GLOB_TS = "**/*.?([cm])ts";
16
+ declare const GLOB_TSX = "**/*.?([cm])tsx";
17
+ declare const GLOB_STYLE = "**/*.{c,le,sc}ss";
18
+ declare const GLOB_CSS = "**/*.css";
19
+ declare const GLOB_LESS = "**/*.less";
20
+ declare const GLOB_SCSS = "**/*.scss";
21
+ declare const GLOB_JSON = "**/*.json";
22
+ declare const GLOB_JSON5 = "**/*.json5";
23
+ declare const GLOB_JSONC = "**/*.jsonc";
24
+ declare const GLOB_MARKDOWN = "**/*.md";
25
+ declare const GLOB_VUE = "**/*.vue";
26
+ declare const GLOB_YAML = "**/*.y?(a)ml";
27
+ declare const GLOB_HTML = "**/*.htm?(l)";
28
+ declare const GLOB_MARKDOWN_CODE = "**/*.md/**/*.?([cm])[jt]s?(x)";
29
+ declare const GLOB_TESTS: string[];
30
+ declare const GLOB_ALL_SRC: string[];
31
+ declare const GLOB_EXCLUDE: string[];
32
+
9
33
  interface OptionsTypeScriptWithLanguageServer {
10
34
  tsconfigPath: string;
11
35
  tsconfigRootDir?: string;
12
36
  }
37
+ interface OptionsComponentExts {
38
+ /**
39
+ * Additional extensions for components.
40
+ *
41
+ * @example ['vue']
42
+ * @default []
43
+ */
44
+ componentExts?: string[];
45
+ }
46
+ interface OptionsIsInEditor {
47
+ isInEditor?: boolean;
48
+ }
49
+ type OptionsHasTypeScript = Pick<OptionsConfig, "ts">;
13
50
  interface OptionsConfig {
14
51
  /**
15
52
  * Enable TypeScript support.
16
53
  *
17
54
  * Passing an object to enable TypeScript Language Server support.
18
- *
19
- * @default auto-detect based on the dependencies
55
+ * @default true
20
56
  */
21
- typescript?: boolean | OptionsTypeScriptWithLanguageServer;
57
+ ts?: boolean | OptionsTypeScriptWithLanguageServer;
22
58
  /**
23
59
  * Enable test support.
24
60
  *
@@ -28,27 +64,33 @@ interface OptionsConfig {
28
64
  /**
29
65
  * Enable Vue support.
30
66
  *
31
- * @default auto-detect based on the dependencies
67
+ * @default false
32
68
  */
33
69
  vue?: boolean;
34
70
  /**
35
71
  * Enable React support.
36
72
  *
37
- * @default auto-detect based on the dependencies
73
+ * @default false
38
74
  */
39
75
  react?: boolean;
40
76
  /**
41
77
  * Enable Solid support.
42
78
  *
43
- * @default auto-detect based on the dependencies
79
+ * @default false
44
80
  */
45
81
  solid?: boolean;
46
82
  /**
47
83
  * Enable TailwindCSS support.
48
84
  *
49
- * @default auto-detect based on the dependencies
85
+ * @default false
50
86
  */
51
87
  tailwindcss?: boolean;
88
+ /**
89
+ * Enable TailwindCSS support.
90
+ *
91
+ * @default true
92
+ */
93
+ prettier?: boolean;
52
94
  /**
53
95
  * Enable JSONC support.
54
96
  *
@@ -79,10 +121,19 @@ interface OptionsConfig {
79
121
  */
80
122
  isInEditor?: boolean;
81
123
  }
124
+ interface OptionsConfigBasic extends Pick<OptionsConfig, "ts" | "isInEditor" | "test" | "jsonc" | "yaml" | "markdown"> {
125
+ componentExts?: string[];
126
+ }
127
+
128
+ /**
129
+ * Combine array and non-array configs into a single array.
130
+ * @param configs
131
+ */
132
+ declare function combine(...configs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
82
133
 
83
134
  /**
84
135
  * Construct an array of ESLint flat config items.
85
136
  */
86
137
  declare function config(options?: OptionsConfig, ...userConfigs: (FlatESLintConfigItem | FlatESLintConfigItem[])[]): FlatESLintConfigItem[];
87
138
 
88
- export { config, config as default };
139
+ export { GLOB_ALL_SRC, GLOB_CSS, GLOB_EXCLUDE, GLOB_HTML, GLOB_JS, GLOB_JSON, GLOB_JSON5, GLOB_JSONC, GLOB_JSX, GLOB_LESS, GLOB_MARKDOWN, GLOB_MARKDOWN_CODE, GLOB_SCSS, GLOB_SRC, GLOB_SRC_EXT, GLOB_STYLE, GLOB_TESTS, GLOB_TS, GLOB_TSX, GLOB_VUE, GLOB_YAML, OFF, OptionsComponentExts, OptionsConfig, OptionsConfigBasic, OptionsHasTypeScript, OptionsIsInEditor, OptionsTypeScriptWithLanguageServer, combine, config, config as default };
package/dist/index.js CHANGED
@@ -1,58 +1,72 @@
1
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";
2
+ import { basic } from "@debbl/eslint-config-basic";
3
+ import { ts } from "@debbl/eslint-config-ts";
41
4
  import { vue } from "@debbl/eslint-config-vue";
42
5
  import { react } from "@debbl/eslint-config-react";
43
6
  import { solid } from "@debbl/eslint-config-solid";
44
7
  import { tailwindcss } from "@debbl/eslint-config-tailwindcss";
8
+ import { prettier } from "@debbl/eslint-config-prettier";
9
+
10
+ // ../../src/flags.ts
11
+ var OFF = 0;
45
12
 
46
13
  // ../../src/globs.ts
47
14
  var GLOB_SRC_EXT = "?([cm])[jt]s?(x)";
48
15
  var GLOB_SRC = "**/*.?([cm])[jt]s?(x)";
16
+ var GLOB_JS = "**/*.?([cm])js";
17
+ var GLOB_JSX = "**/*.?([cm])jsx";
18
+ var GLOB_TS = "**/*.?([cm])ts";
19
+ var GLOB_TSX = "**/*.?([cm])tsx";
20
+ var GLOB_STYLE = "**/*.{c,le,sc}ss";
21
+ var GLOB_CSS = "**/*.css";
22
+ var GLOB_LESS = "**/*.less";
23
+ var GLOB_SCSS = "**/*.scss";
24
+ var GLOB_JSON = "**/*.json";
25
+ var GLOB_JSON5 = "**/*.json5";
26
+ var GLOB_JSONC = "**/*.jsonc";
49
27
  var GLOB_MARKDOWN = "**/*.md";
28
+ var GLOB_VUE = "**/*.vue";
29
+ var GLOB_YAML = "**/*.y?(a)ml";
30
+ var GLOB_HTML = "**/*.htm?(l)";
50
31
  var GLOB_MARKDOWN_CODE = `${GLOB_MARKDOWN}/${GLOB_SRC}`;
51
32
  var GLOB_TESTS = [
52
33
  `**/__tests__/**/*.${GLOB_SRC_EXT}`,
53
34
  `**/*.spec.${GLOB_SRC_EXT}`,
54
35
  `**/*.test.${GLOB_SRC_EXT}`
55
36
  ];
37
+ var GLOB_ALL_SRC = [
38
+ GLOB_SRC,
39
+ GLOB_STYLE,
40
+ GLOB_JSON,
41
+ GLOB_JSON5,
42
+ GLOB_MARKDOWN,
43
+ GLOB_VUE,
44
+ GLOB_YAML,
45
+ GLOB_HTML
46
+ ];
47
+ var GLOB_EXCLUDE = [
48
+ "**/node_modules",
49
+ "**/dist",
50
+ "**/package-lock.json",
51
+ "**/yarn.lock",
52
+ "**/pnpm-lock.yaml",
53
+ "**/output",
54
+ "**/coverage",
55
+ "**/temp",
56
+ "**/.vitepress/cache",
57
+ "**/.nuxt",
58
+ "**/.vercel",
59
+ "**/.changeset",
60
+ "**/.idea",
61
+ "**/.output",
62
+ "**/.vite-inspect",
63
+ "**/CHANGELOG*.md",
64
+ "**/*.min.*",
65
+ "**/LICENSE*",
66
+ "**/__snapshots__",
67
+ "**/auto-import?(s).d.ts",
68
+ "**/components.d.ts"
69
+ ];
56
70
 
57
71
  // ../../src/utils.ts
58
72
  function combine(...configs) {
@@ -63,105 +77,95 @@ function combine(...configs) {
63
77
 
64
78
  // src/factory.ts
65
79
  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 }));
80
+ const enableVue = options.vue;
81
+ const enableReact = options.react;
82
+ const enableSolid = options.solid;
83
+ const enableTailwindcss = options.tailwindcss;
84
+ const enableTypeScript = options.ts ?? true;
85
+ const enablePrettier = options.prettier ?? true;
86
+ const configs = [];
105
87
  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 }));
88
+ configs.push(react(options));
89
+ else if (enableVue)
90
+ configs.push(vue(options));
91
+ else if (enableSolid)
92
+ configs.push(solid(options));
93
+ else if (enableTypeScript)
94
+ configs.push(ts({ ...options }));
95
+ else
96
+ configs.push(basic(options));
97
+ enableTailwindcss && configs.push(tailwindcss());
98
+ enablePrettier && configs.push(prettier());
118
99
  return combine(...configs, ...userConfigs);
119
100
  }
120
101
 
121
102
  // src/index.ts
122
103
  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
104
+ basic as basic2,
105
+ comments,
106
+ ignores,
107
+ imports,
108
+ js,
109
+ jsdoc,
110
+ jsonc,
111
+ markdown,
112
+ node,
113
+ sortPackageJson,
114
+ sortTsconfig,
115
+ test,
116
+ unicorn,
117
+ yml
137
118
  } 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";
119
+ import { ts as ts2, tsWithLanguageServer } from "@debbl/eslint-config-ts";
120
+ import { prettier as prettier2 } from "@debbl/eslint-config-prettier";
140
121
  import { vue as vue2 } from "@debbl/eslint-config-vue";
141
122
  import { solid as solid2 } from "@debbl/eslint-config-solid";
142
123
  import { react as react2 } from "@debbl/eslint-config-react";
143
124
  var src_default = config;
144
125
  export {
145
- basic,
146
- comments2 as comments,
126
+ GLOB_ALL_SRC,
127
+ GLOB_CSS,
128
+ GLOB_EXCLUDE,
129
+ GLOB_HTML,
130
+ GLOB_JS,
131
+ GLOB_JSON,
132
+ GLOB_JSON5,
133
+ GLOB_JSONC,
134
+ GLOB_JSX,
135
+ GLOB_LESS,
136
+ GLOB_MARKDOWN,
137
+ GLOB_MARKDOWN_CODE,
138
+ GLOB_SCSS,
139
+ GLOB_SRC,
140
+ GLOB_SRC_EXT,
141
+ GLOB_STYLE,
142
+ GLOB_TESTS,
143
+ GLOB_TS,
144
+ GLOB_TSX,
145
+ GLOB_VUE,
146
+ GLOB_YAML,
147
+ OFF,
148
+ basic2 as basic,
149
+ combine,
150
+ comments,
147
151
  config,
148
152
  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,
153
+ ignores,
154
+ imports,
155
+ js,
156
+ jsdoc,
157
+ jsonc,
158
+ markdown,
159
+ node,
160
+ prettier2 as prettier,
157
161
  react2 as react,
158
162
  solid2 as solid,
159
- sortPackageJson2 as sortPackageJson,
160
- sortTsconfig2 as sortTsconfig,
161
- test2 as test,
163
+ sortPackageJson,
164
+ sortTsconfig,
165
+ test,
162
166
  ts2 as ts,
163
- tsWithLanguageServer2 as tsWithLanguageServer,
164
- unicorn2 as unicorn,
167
+ tsWithLanguageServer,
168
+ unicorn,
165
169
  vue2 as vue,
166
- yml2 as yml
170
+ yml
167
171
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@debbl/eslint-config",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.0",
4
+ "version": "1.0.0-beta.10",
5
5
  "description": "",
6
6
  "author": "Debbl <me@aiwan.run> (https://github.com/Debbl/)",
7
7
  "license": "MIT",
@@ -11,19 +11,20 @@
11
11
  ],
12
12
  "main": "dist/index.js",
13
13
  "files": [
14
+ "README.md",
14
15
  "dist"
15
16
  ],
16
17
  "peerDependencies": {
17
18
  "eslint": ">=8.24.0"
18
19
  },
19
20
  "dependencies": {
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"
21
+ "@debbl/eslint-config-basic": "1.0.0-beta.10",
22
+ "@debbl/eslint-config-solid": "1.0.0-beta.10",
23
+ "@debbl/eslint-config-ts": "1.0.0-beta.10",
24
+ "@debbl/eslint-config-react": "1.0.0-beta.10",
25
+ "@debbl/eslint-config-vue": "1.0.0-beta.10",
26
+ "@debbl/eslint-config-prettier": "1.0.0-beta.10",
27
+ "@debbl/eslint-config-tailwindcss": "1.0.0-beta.10"
27
28
  },
28
29
  "devDependencies": {
29
30
  "eslint": "^8.50.0"