@octohash/eslint-config 0.2.3 → 0.2.5
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.d.mts +20 -13
- package/dist/index.mjs +7 -109
- package/package.json +20 -15
package/dist/index.d.mts
CHANGED
|
@@ -201,7 +201,7 @@ interface JSONSchema4 {
|
|
|
201
201
|
format?: string | undefined;
|
|
202
202
|
}
|
|
203
203
|
//#endregion
|
|
204
|
-
//#region node_modules/.pnpm/@eslint+core@1.1.
|
|
204
|
+
//#region node_modules/.pnpm/@eslint+core@1.1.1/node_modules/@eslint/core/dist/esm/types.d.ts
|
|
205
205
|
/**
|
|
206
206
|
* Represents an error inside of a file.
|
|
207
207
|
*/
|
|
@@ -528,7 +528,7 @@ type RuleFixer = (fixer: RuleTextEditor) => RuleTextEdit | Iterable<RuleTextEdit
|
|
|
528
528
|
* Data that can be used to fill placeholders in error messages.
|
|
529
529
|
*/
|
|
530
530
|
type MessagePlaceholderData = Record<string, string | number | boolean | bigint | null | undefined>;
|
|
531
|
-
interface ViolationReportBase {
|
|
531
|
+
interface ViolationReportBase<MessageIds extends string = string> {
|
|
532
532
|
/**
|
|
533
533
|
* The data to insert into the message.
|
|
534
534
|
*/
|
|
@@ -541,9 +541,9 @@ interface ViolationReportBase {
|
|
|
541
541
|
* An array of suggested fixes for the problem. These fixes may change the
|
|
542
542
|
* behavior of the code, so they are not applied automatically.
|
|
543
543
|
*/
|
|
544
|
-
suggest?: SuggestedEdit[] | null | undefined;
|
|
544
|
+
suggest?: SuggestedEdit<MessageIds>[] | null | undefined;
|
|
545
545
|
}
|
|
546
|
-
type ViolationMessage<MessageIds = string> = {
|
|
546
|
+
type ViolationMessage<MessageIds extends string = string> = {
|
|
547
547
|
message: string;
|
|
548
548
|
} | {
|
|
549
549
|
messageId: MessageIds;
|
|
@@ -553,7 +553,7 @@ type ViolationLocation<Node> = {
|
|
|
553
553
|
} | {
|
|
554
554
|
node: Node;
|
|
555
555
|
};
|
|
556
|
-
type ViolationReport<Node = unknown, MessageIds = string> = ViolationReportBase & ViolationMessage<MessageIds> & ViolationLocation<Node>;
|
|
556
|
+
type ViolationReport<Node = unknown, MessageIds extends string = string> = ViolationReportBase<MessageIds> & ViolationMessage<MessageIds> & ViolationLocation<Node>;
|
|
557
557
|
interface SuggestedEditBase {
|
|
558
558
|
/**
|
|
559
559
|
* The data to insert into the message.
|
|
@@ -564,15 +564,15 @@ interface SuggestedEditBase {
|
|
|
564
564
|
*/
|
|
565
565
|
fix: RuleFixer;
|
|
566
566
|
}
|
|
567
|
-
type SuggestionMessage = {
|
|
567
|
+
type SuggestionMessage<MessageIds extends string = string> = {
|
|
568
568
|
desc: string;
|
|
569
569
|
} | {
|
|
570
|
-
messageId:
|
|
570
|
+
messageId: MessageIds;
|
|
571
571
|
};
|
|
572
572
|
/**
|
|
573
573
|
* A suggested edit for a rule violation.
|
|
574
574
|
*/
|
|
575
|
-
type SuggestedEdit = SuggestedEditBase & SuggestionMessage
|
|
575
|
+
type SuggestedEdit<MessageIds extends string = string> = SuggestedEditBase & SuggestionMessage<MessageIds>;
|
|
576
576
|
/**
|
|
577
577
|
* The normalized version of a lint suggestion.
|
|
578
578
|
*/
|
|
@@ -1300,19 +1300,26 @@ interface Directive {
|
|
|
1300
1300
|
justification?: string;
|
|
1301
1301
|
}
|
|
1302
1302
|
//#endregion
|
|
1303
|
-
//#region node_modules/.pnpm/@eslint+config-helpers@0.5.
|
|
1303
|
+
//#region node_modules/.pnpm/@eslint+config-helpers@0.5.3/node_modules/@eslint/config-helpers/dist/esm/types.d.ts
|
|
1304
1304
|
/**
|
|
1305
1305
|
* Infinite array type.
|
|
1306
1306
|
*/
|
|
1307
1307
|
type InfiniteArray<T> = T | InfiniteArray<T>[];
|
|
1308
|
+
/**
|
|
1309
|
+
* A config object that may appear inside of `extends`.
|
|
1310
|
+
* `basePath` and nested `extends` are not allowed on extension config objects.
|
|
1311
|
+
*/
|
|
1312
|
+
type ExtensionConfigObject = Omit<ConfigObject, "basePath"> & {
|
|
1313
|
+
extends?: never;
|
|
1314
|
+
};
|
|
1308
1315
|
/**
|
|
1309
1316
|
* The type of array element in the `extends` property after flattening.
|
|
1310
1317
|
*/
|
|
1311
|
-
type SimpleExtendsElement = string |
|
|
1318
|
+
type SimpleExtendsElement = string | ExtensionConfigObject;
|
|
1312
1319
|
/**
|
|
1313
1320
|
* The type of array element in the `extends` property before flattening.
|
|
1314
1321
|
*/
|
|
1315
|
-
type ExtendsElement = SimpleExtendsElement | InfiniteArray<
|
|
1322
|
+
type ExtendsElement = SimpleExtendsElement | InfiniteArray<ExtensionConfigObject>;
|
|
1316
1323
|
/**
|
|
1317
1324
|
* Config with extends. Valid only inside of `defineConfig()`.
|
|
1318
1325
|
*/
|
|
@@ -1320,10 +1327,10 @@ interface ConfigWithExtends$1 extends ConfigObject {
|
|
|
1320
1327
|
extends?: ExtendsElement[];
|
|
1321
1328
|
}
|
|
1322
1329
|
//#endregion
|
|
1323
|
-
//#region node_modules/.pnpm/@eslint+config-helpers@0.5.
|
|
1330
|
+
//#region node_modules/.pnpm/@eslint+config-helpers@0.5.3/node_modules/@eslint/config-helpers/dist/esm/index.d.ts
|
|
1324
1331
|
type ConfigWithExtends = ConfigWithExtends$1;
|
|
1325
1332
|
//#endregion
|
|
1326
|
-
//#region node_modules/.pnpm/eslint-flat-config-utils@3.0.
|
|
1333
|
+
//#region node_modules/.pnpm/eslint-flat-config-utils@3.0.2/node_modules/eslint-flat-config-utils/dist/index.d.mts
|
|
1327
1334
|
/**
|
|
1328
1335
|
* A type that can be awaited. Promise<T> or T.
|
|
1329
1336
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
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
|
-
|
|
10
4
|
//#region src/configs/octohash.ts
|
|
11
5
|
async function octohash() {
|
|
12
6
|
return [{
|
|
13
7
|
name: "octohash/octohash/rules",
|
|
14
|
-
rules: {
|
|
8
|
+
rules: {
|
|
9
|
+
"pnpm/yaml-enforce-settings": "off",
|
|
10
|
+
"markdown/no-unused-definitions": "off"
|
|
11
|
+
}
|
|
15
12
|
}];
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
//#endregion
|
|
19
15
|
//#region src/configs/sort.ts
|
|
20
16
|
async function sortPackageJson() {
|
|
@@ -74,6 +70,7 @@ async function sortPackageJson() {
|
|
|
74
70
|
"husky",
|
|
75
71
|
"simple-git-hooks",
|
|
76
72
|
"lint-staged",
|
|
73
|
+
"nano-staged",
|
|
77
74
|
"eslintConfig"
|
|
78
75
|
],
|
|
79
76
|
pathPattern: "^$"
|
|
@@ -115,71 +112,17 @@ async function sortPackageJson() {
|
|
|
115
112
|
...configs.recommended
|
|
116
113
|
];
|
|
117
114
|
}
|
|
118
|
-
|
|
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
115
|
//#endregion
|
|
171
116
|
//#region src/configs/tailwindcss.ts
|
|
172
117
|
async function tailwindcss(options = {}) {
|
|
173
118
|
const pkg = await getPackageInfo("tailwindcss");
|
|
174
119
|
if (!pkg || !pkg.version) return [];
|
|
175
120
|
await ensurePackages(["eslint-plugin-better-tailwindcss"]);
|
|
176
|
-
const version = pkg.version;
|
|
177
121
|
const { files = [
|
|
178
122
|
GLOB_HTML,
|
|
179
123
|
GLOB_SRC,
|
|
180
124
|
GLOB_VUE
|
|
181
125
|
], overrides = {}, settings = {} } = options;
|
|
182
|
-
const resolvedSettings = await resolveTailwindSettings(settings, version);
|
|
183
126
|
return [{
|
|
184
127
|
name: "octohash/tailwindcss/setup",
|
|
185
128
|
plugins: { tailwindcss: await interopDefault(import("eslint-plugin-better-tailwindcss")) }
|
|
@@ -199,53 +142,9 @@ async function tailwindcss(options = {}) {
|
|
|
199
142
|
"tailwindcss/no-conflicting-classes": "error",
|
|
200
143
|
...overrides
|
|
201
144
|
},
|
|
202
|
-
settings: { "better-tailwindcss":
|
|
145
|
+
settings: { "better-tailwindcss": settings }
|
|
203
146
|
}];
|
|
204
147
|
}
|
|
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
|
-
|
|
249
148
|
//#endregion
|
|
250
149
|
//#region src/index.ts
|
|
251
150
|
function defineConfig(options, ...userConfigs) {
|
|
@@ -263,6 +162,5 @@ function mergeOptions(options) {
|
|
|
263
162
|
formatters
|
|
264
163
|
};
|
|
265
164
|
}
|
|
266
|
-
|
|
267
165
|
//#endregion
|
|
268
|
-
export { defineConfig };
|
|
166
|
+
export { defineConfig };
|
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.5",
|
|
5
5
|
"description": "Personal ESLint config based on @antfu/eslint-config with opinionated extensions.",
|
|
6
6
|
"author": "jinghaihan",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,35 +38,40 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@antfu/eslint-config": "^7.
|
|
41
|
+
"@antfu/eslint-config": "^7.7.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
|
-
"tsdown": "^0.
|
|
48
|
+
"tsdown": "^0.21.2",
|
|
50
49
|
"@octohash/tsconfig": "^0.2.0",
|
|
51
50
|
"bumpp": "^10.4.1",
|
|
52
|
-
"
|
|
51
|
+
"nano-staged": "^0.9.0",
|
|
52
|
+
"pncat": "^0.10.4",
|
|
53
53
|
"simple-git-hooks": "^2.13.1",
|
|
54
|
-
"taze": "^19.
|
|
54
|
+
"taze": "^19.10.0",
|
|
55
55
|
"typescript": "^5.9.3",
|
|
56
|
-
"eslint": "^10.0.
|
|
57
|
-
"eslint-flat-config-utils": "^3.0.
|
|
58
|
-
"eslint-plugin-better-tailwindcss": "^4.2
|
|
59
|
-
"lint-staged": "^16.2.7",
|
|
56
|
+
"eslint": "^10.0.3",
|
|
57
|
+
"eslint-flat-config-utils": "^3.0.2",
|
|
58
|
+
"eslint-plugin-better-tailwindcss": "^4.3.2",
|
|
60
59
|
"vitest": "^4.0.18",
|
|
61
|
-
"@types/node": "^
|
|
62
|
-
"@octohash/eslint-config": "0.2.
|
|
60
|
+
"@types/node": "^25.4.0",
|
|
61
|
+
"@octohash/eslint-config": "0.2.5"
|
|
63
62
|
},
|
|
64
63
|
"simple-git-hooks": {
|
|
65
|
-
"pre-commit": "pnpm
|
|
64
|
+
"pre-commit": "pnpm nano-staged"
|
|
66
65
|
},
|
|
67
|
-
"
|
|
66
|
+
"nano-staged": {
|
|
68
67
|
"*": "eslint --fix"
|
|
69
68
|
},
|
|
69
|
+
"inlinedDependencies": {
|
|
70
|
+
"@types/json-schema": "7.0.15",
|
|
71
|
+
"@eslint/core": "1.1.1",
|
|
72
|
+
"@eslint/config-helpers": "0.5.3",
|
|
73
|
+
"eslint-flat-config-utils": "3.0.2"
|
|
74
|
+
},
|
|
70
75
|
"scripts": {
|
|
71
76
|
"build": "tsdown",
|
|
72
77
|
"typecheck": "tsc",
|