@dhzh/eslint-config 2.0.2 → 2.0.4
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/dist/cli/index.mjs +1 -1
- package/dist/index.mjs +18 -9
- package/package.json +3 -2
package/dist/cli/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import fsp from "node:fs/promises";
|
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import fs from "node:fs";
|
|
8
8
|
//#region package.json
|
|
9
|
-
var version = "2.0.
|
|
9
|
+
var version = "2.0.4";
|
|
10
10
|
var devDependencies = {
|
|
11
11
|
"@eslint/config-inspector": "^2.0.0",
|
|
12
12
|
"@prettier/plugin-xml": "^3.4.2",
|
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,10 @@ import pluginReactHooks from "eslint-plugin-react-hooks";
|
|
|
3
3
|
import pluginReactRefresh from "eslint-plugin-react-refresh";
|
|
4
4
|
import pluginReactCompiler from "eslint-plugin-react-compiler";
|
|
5
5
|
import pluginReactGoogleTranslate from "eslint-plugin-react-google-translate";
|
|
6
|
-
import { isPackageExists } from "local-pkg";
|
|
7
6
|
import { defineConfig as defineConfig$1 } from "eslint/config";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { getPackagesSync } from "@manypkg/get-packages";
|
|
9
|
+
import { isPackageExists } from "local-pkg";
|
|
8
10
|
import js from "@eslint/js";
|
|
9
11
|
import tseslint from "typescript-eslint";
|
|
10
12
|
import pluginVue from "eslint-plugin-vue";
|
|
@@ -13,7 +15,6 @@ import { mergeProcessors } from "eslint-merge-processors";
|
|
|
13
15
|
import processorVueBlocks from "eslint-processor-vue-blocks";
|
|
14
16
|
import pluginStylistic from "@stylistic/eslint-plugin";
|
|
15
17
|
import pluginAntfu from "eslint-plugin-antfu";
|
|
16
|
-
import process from "node:process";
|
|
17
18
|
import pluginNode from "eslint-plugin-n";
|
|
18
19
|
import pluginJsonc from "eslint-plugin-jsonc";
|
|
19
20
|
import pluginPackageJson from "eslint-plugin-package-json";
|
|
@@ -147,6 +148,14 @@ const mergeRule = (...rules) => {
|
|
|
147
148
|
if (Object.keys(finalOptions).length === 0) return finalLevel;
|
|
148
149
|
return [finalLevel, finalOptions];
|
|
149
150
|
};
|
|
151
|
+
function isPackageAvailable(name, cwd = process.cwd()) {
|
|
152
|
+
if (isPackageExists(name, { paths: [cwd] })) return true;
|
|
153
|
+
try {
|
|
154
|
+
return getPackagesSync(cwd).packages.some((pkg) => name in (pkg.packageJson.dependencies || {}) || name in (pkg.packageJson.devDependencies || {}) || name in (pkg.packageJson.peerDependencies || {}) || name in (pkg.packageJson.optionalDependencies || {}));
|
|
155
|
+
} catch {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
150
159
|
//#endregion
|
|
151
160
|
//#region src/configs/react.ts
|
|
152
161
|
const ReactRefreshAllowConstantExportPackages = ["vite"];
|
|
@@ -173,11 +182,11 @@ function react(options = {}) {
|
|
|
173
182
|
googleTranslate: {}
|
|
174
183
|
} } = options;
|
|
175
184
|
const config = language === "typescript" ? pluginReact.configs["recommended-type-checked"] : pluginReact.configs.recommended;
|
|
176
|
-
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) =>
|
|
177
|
-
const isUsingRemix = RemixPackages.some((i) =>
|
|
178
|
-
const isUsingReactRouter = ReactRouterPackages.some((i) =>
|
|
179
|
-
const isUsingNext = NextJsPackages.some((i) =>
|
|
180
|
-
const isUsingExpo = ExpoPackages.some((i) =>
|
|
185
|
+
const isAllowConstantExport = ReactRefreshAllowConstantExportPackages.some((i) => isPackageAvailable(i));
|
|
186
|
+
const isUsingRemix = RemixPackages.some((i) => isPackageAvailable(i));
|
|
187
|
+
const isUsingReactRouter = ReactRouterPackages.some((i) => isPackageAvailable(i));
|
|
188
|
+
const isUsingNext = NextJsPackages.some((i) => isPackageAvailable(i));
|
|
189
|
+
const isUsingExpo = ExpoPackages.some((i) => isPackageAvailable(i));
|
|
181
190
|
return [
|
|
182
191
|
{
|
|
183
192
|
...config,
|
|
@@ -1137,7 +1146,7 @@ function format(options = {}) {
|
|
|
1137
1146
|
//#region src/configs/tailwindcss.ts
|
|
1138
1147
|
function tailwindcss(options = {}) {
|
|
1139
1148
|
const { overrides = {} } = options;
|
|
1140
|
-
return
|
|
1149
|
+
return isPackageAvailable("tailwindcss") ? [...pluginTailwindcss.configs["flat/recommended"].map((item) => ({
|
|
1141
1150
|
...item,
|
|
1142
1151
|
name: `${RULE_PREFIX}/tailwindcss/shared/${item.name?.replace("tailwindcss:", "")}`,
|
|
1143
1152
|
files: GLOB_SRC
|
|
@@ -1154,7 +1163,7 @@ function tailwindcss(options = {}) {
|
|
|
1154
1163
|
//#region src/configs/unocss.ts
|
|
1155
1164
|
function unocss(options = {}) {
|
|
1156
1165
|
const { overrides = {} } = options;
|
|
1157
|
-
if (!
|
|
1166
|
+
if (!isPackageAvailable("unocss")) return [];
|
|
1158
1167
|
return [{
|
|
1159
1168
|
...configUnocss,
|
|
1160
1169
|
name: `${RULE_PREFIX}/unocss/shared`,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhzh/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.4",
|
|
5
5
|
"description": "tinywaves's ESLint config",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Lyle Zheng",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.7.1",
|
|
53
53
|
"@eslint-react/eslint-plugin": "^4.2.3",
|
|
54
54
|
"@eslint/js": "^10.0.1",
|
|
55
|
+
"@manypkg/get-packages": "^3.1.0",
|
|
55
56
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
56
57
|
"@unocss/eslint-config": "66.6.8",
|
|
57
58
|
"ansis": "^4.2.0",
|
|
@@ -100,7 +101,7 @@
|
|
|
100
101
|
"typescript": "^6.0.3"
|
|
101
102
|
},
|
|
102
103
|
"simple-git-hooks": {
|
|
103
|
-
"pre-commit": "
|
|
104
|
+
"pre-commit": "eval \"$(fnm env)\" && pnpm exec lint-staged"
|
|
104
105
|
},
|
|
105
106
|
"lint-staged": {
|
|
106
107
|
"*": "eslint --fix"
|