@octohash/eslint-config 0.2.2 → 0.2.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/index.mjs +7 -104
- package/package.json +7 -8
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import antfu, { GLOB_HTML, GLOB_SRC, GLOB_VUE, ensurePackages, interopDefault } from "@antfu/eslint-config";
|
|
2
2
|
import catalogsSort, { configs } from "eslint-plugin-catalogs-sort";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
3
|
import { getPackageInfo } from "local-pkg";
|
|
5
|
-
import { basename, dirname, resolve } from "pathe";
|
|
6
|
-
import { glob } from "tinyglobby";
|
|
7
|
-
import process from "node:process";
|
|
8
|
-
import { findUp } from "find-up-simple";
|
|
9
4
|
|
|
10
5
|
//#region src/configs/octohash.ts
|
|
11
6
|
async function octohash() {
|
|
12
7
|
return [{
|
|
13
8
|
name: "octohash/octohash/rules",
|
|
14
|
-
rules: {
|
|
9
|
+
rules: {
|
|
10
|
+
"pnpm/yaml-enforce-settings": "off",
|
|
11
|
+
"markdown/no-unused-definitions": "off"
|
|
12
|
+
}
|
|
15
13
|
}];
|
|
16
14
|
}
|
|
17
15
|
|
|
@@ -116,70 +114,17 @@ async function sortPackageJson() {
|
|
|
116
114
|
];
|
|
117
115
|
}
|
|
118
116
|
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/constants.ts
|
|
121
|
-
const DEFAULT_IGNORE_PATHS = [
|
|
122
|
-
"**/.git/**",
|
|
123
|
-
"**/.next/**",
|
|
124
|
-
"**/.nuxt/**",
|
|
125
|
-
"**/.output/**",
|
|
126
|
-
"**/.vercel/**",
|
|
127
|
-
"**/.vscode/**",
|
|
128
|
-
"**/.idea/**",
|
|
129
|
-
"**/coverage/**",
|
|
130
|
-
"**/dist/**",
|
|
131
|
-
"**/build/**",
|
|
132
|
-
"**/node_modules/**",
|
|
133
|
-
"**/dist/**",
|
|
134
|
-
"**/public/**",
|
|
135
|
-
"**/fixture/**",
|
|
136
|
-
"**/fixtures/**"
|
|
137
|
-
];
|
|
138
|
-
const REPOSITORY_ROOT_FILES = [
|
|
139
|
-
".git",
|
|
140
|
-
"package-lock.json",
|
|
141
|
-
"npm-shrinkwrap.json",
|
|
142
|
-
"pnpm-lock.yaml",
|
|
143
|
-
"pnpm-workspace.yaml",
|
|
144
|
-
"yarn.lock",
|
|
145
|
-
"bun.lock",
|
|
146
|
-
"bun.lockb",
|
|
147
|
-
"deno.lock"
|
|
148
|
-
];
|
|
149
|
-
const TAILWIND_V3_CONFIG_PATTERNS = [
|
|
150
|
-
"**/tailwind.config.ts",
|
|
151
|
-
"**/tailwind.config.mjs",
|
|
152
|
-
"**/tailwind.config.cjs",
|
|
153
|
-
"**/tailwind.config.js"
|
|
154
|
-
];
|
|
155
|
-
const TAILWIND_V4_IMPORT_RE = /@import\s+['"]tailwindcss(?:\/[^'"]*)?['"]/;
|
|
156
|
-
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region src/utils.ts
|
|
159
|
-
async function findRepositoryRoot() {
|
|
160
|
-
for (const file of REPOSITORY_ROOT_FILES) {
|
|
161
|
-
const filepath = await findUp(file, file === ".git" ? { type: "directory" } : void 0);
|
|
162
|
-
if (filepath) return dirname(filepath);
|
|
163
|
-
}
|
|
164
|
-
return process.cwd();
|
|
165
|
-
}
|
|
166
|
-
function pathDepth(filepath) {
|
|
167
|
-
return filepath.split("/").length;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
117
|
//#endregion
|
|
171
118
|
//#region src/configs/tailwindcss.ts
|
|
172
119
|
async function tailwindcss(options = {}) {
|
|
173
120
|
const pkg = await getPackageInfo("tailwindcss");
|
|
174
121
|
if (!pkg || !pkg.version) return [];
|
|
175
122
|
await ensurePackages(["eslint-plugin-better-tailwindcss"]);
|
|
176
|
-
const version = pkg.version;
|
|
177
123
|
const { files = [
|
|
178
124
|
GLOB_HTML,
|
|
179
125
|
GLOB_SRC,
|
|
180
126
|
GLOB_VUE
|
|
181
127
|
], overrides = {}, settings = {} } = options;
|
|
182
|
-
const resolvedSettings = await resolveTailwindSettings(settings, version);
|
|
183
128
|
return [{
|
|
184
129
|
name: "octohash/tailwindcss/setup",
|
|
185
130
|
plugins: { tailwindcss: await interopDefault(import("eslint-plugin-better-tailwindcss")) }
|
|
@@ -199,52 +144,9 @@ async function tailwindcss(options = {}) {
|
|
|
199
144
|
"tailwindcss/no-conflicting-classes": "error",
|
|
200
145
|
...overrides
|
|
201
146
|
},
|
|
202
|
-
settings: { "better-tailwindcss":
|
|
147
|
+
settings: { "better-tailwindcss": settings }
|
|
203
148
|
}];
|
|
204
149
|
}
|
|
205
|
-
async function resolveTailwindSettings(settings, version) {
|
|
206
|
-
const resolvedSettings = { ...settings ?? {} };
|
|
207
|
-
const major = Number.parseInt(version, 10);
|
|
208
|
-
const cwd = await findRepositoryRoot();
|
|
209
|
-
if (major === 4 && !resolvedSettings.entryPoint) resolvedSettings.entryPoint = await findTailwindV4ImportCSS(cwd) ?? void 0;
|
|
210
|
-
if (major === 3 && !resolvedSettings.tailwindConfig) resolvedSettings.tailwindConfig = await findTailwindV3Config(cwd) ?? void 0;
|
|
211
|
-
return resolvedSettings;
|
|
212
|
-
}
|
|
213
|
-
async function findTailwindV3Config(cwd) {
|
|
214
|
-
const files = await glob(TAILWIND_V3_CONFIG_PATTERNS, {
|
|
215
|
-
cwd,
|
|
216
|
-
ignore: DEFAULT_IGNORE_PATHS,
|
|
217
|
-
onlyFiles: true
|
|
218
|
-
});
|
|
219
|
-
if (files.length === 0) return void 0;
|
|
220
|
-
const extensionPriority = new Map(TAILWIND_V3_CONFIG_PATTERNS.map((pattern, index) => [basename(pattern), index]));
|
|
221
|
-
files.sort((a, b) => {
|
|
222
|
-
const depthDiff = pathDepth(a) - pathDepth(b);
|
|
223
|
-
if (depthDiff !== 0) return depthDiff;
|
|
224
|
-
return (extensionPriority.get(basename(a)) ?? Number.POSITIVE_INFINITY) - (extensionPriority.get(basename(b)) ?? Number.POSITIVE_INFINITY);
|
|
225
|
-
});
|
|
226
|
-
return resolve(cwd, files[0]);
|
|
227
|
-
}
|
|
228
|
-
async function findTailwindV4ImportCSS(cwd) {
|
|
229
|
-
const files = await glob("**/*.css", {
|
|
230
|
-
cwd,
|
|
231
|
-
ignore: DEFAULT_IGNORE_PATHS,
|
|
232
|
-
onlyFiles: true
|
|
233
|
-
});
|
|
234
|
-
files.sort((a, b) => pathDepth(a) - pathDepth(b));
|
|
235
|
-
for (const file of files) {
|
|
236
|
-
const fullPath = resolve(cwd, file);
|
|
237
|
-
if (await hasTailwindV4Import(fullPath)) return fullPath;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
async function hasTailwindV4Import(filePath) {
|
|
241
|
-
try {
|
|
242
|
-
const content = await readFile(filePath, "utf-8");
|
|
243
|
-
return TAILWIND_V4_IMPORT_RE.test(content);
|
|
244
|
-
} catch {
|
|
245
|
-
return false;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
150
|
|
|
249
151
|
//#endregion
|
|
250
152
|
//#region src/index.ts
|
|
@@ -257,9 +159,10 @@ function defineConfig(options, ...userConfigs) {
|
|
|
257
159
|
return config;
|
|
258
160
|
}
|
|
259
161
|
function mergeOptions(options) {
|
|
162
|
+
const formatters = typeof options?.formatters === "object" ? options.formatters : typeof options?.formatters === "boolean" ? options.formatters : void 0;
|
|
260
163
|
return {
|
|
261
164
|
...options,
|
|
262
|
-
formatters
|
|
165
|
+
formatters
|
|
263
166
|
};
|
|
264
167
|
}
|
|
265
168
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octohash/eslint-config",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.4",
|
|
5
5
|
"description": "Personal ESLint config based on @antfu/eslint-config with opinionated extensions.",
|
|
6
6
|
"author": "jinghaihan",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,12 +38,11 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@antfu/eslint-config": "^7.
|
|
41
|
+
"@antfu/eslint-config": "^7.6.0",
|
|
42
42
|
"eslint-plugin-catalogs-sort": "^0.0.0-alpha.0",
|
|
43
43
|
"find-up-simple": "^1.0.1",
|
|
44
44
|
"local-pkg": "^1.1.2",
|
|
45
|
-
"pathe": "^2.0.3"
|
|
46
|
-
"tinyglobby": "^0.2.15"
|
|
45
|
+
"pathe": "^2.0.3"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"tsdown": "^0.20.3",
|
|
@@ -53,13 +52,13 @@
|
|
|
53
52
|
"simple-git-hooks": "^2.13.1",
|
|
54
53
|
"taze": "^19.9.2",
|
|
55
54
|
"typescript": "^5.9.3",
|
|
56
|
-
"eslint": "^10.0.
|
|
55
|
+
"eslint": "^10.0.2",
|
|
57
56
|
"eslint-flat-config-utils": "^3.0.1",
|
|
58
|
-
"eslint-plugin-better-tailwindcss": "^4.
|
|
57
|
+
"eslint-plugin-better-tailwindcss": "^4.3.0",
|
|
59
58
|
"lint-staged": "^16.2.7",
|
|
60
59
|
"vitest": "^4.0.18",
|
|
61
|
-
"@types/node": "^
|
|
62
|
-
"@octohash/eslint-config": "0.2.
|
|
60
|
+
"@types/node": "^25.3.0",
|
|
61
|
+
"@octohash/eslint-config": "0.2.4"
|
|
63
62
|
},
|
|
64
63
|
"simple-git-hooks": {
|
|
65
64
|
"pre-commit": "pnpm lint-staged"
|