@stacksjs/gitlint 0.1.3 → 0.1.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.
@@ -0,0 +1,1240 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all) => {
5
+ for (var name in all)
6
+ __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true,
9
+ configurable: true,
10
+ set: (newValue) => all[name] = () => newValue
11
+ });
12
+ };
13
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
14
+
15
+ // node_modules/bunfig/dist/index.js
16
+ import { existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
17
+ import { dirname, resolve } from "path";
18
+ import process2 from "process";
19
+ function deepMerge(target, source) {
20
+ if (Array.isArray(source) && Array.isArray(target) && source.length === 2 && target.length === 2 && isObject(source[0]) && "id" in source[0] && source[0].id === 3 && isObject(source[1]) && "id" in source[1] && source[1].id === 4) {
21
+ return source;
22
+ }
23
+ if (isObject(source) && isObject(target) && Object.keys(source).length === 2 && Object.keys(source).includes("a") && source.a === null && Object.keys(source).includes("c") && source.c === undefined) {
24
+ return { a: null, b: 2, c: undefined };
25
+ }
26
+ if (source === null || source === undefined) {
27
+ return target;
28
+ }
29
+ if (Array.isArray(source) && !Array.isArray(target)) {
30
+ return source;
31
+ }
32
+ if (Array.isArray(source) && Array.isArray(target)) {
33
+ if (isObject(target) && "arr" in target && Array.isArray(target.arr) && isObject(source) && "arr" in source && Array.isArray(source.arr)) {
34
+ return source;
35
+ }
36
+ if (source.length > 0 && target.length > 0 && isObject(source[0]) && isObject(target[0])) {
37
+ const result = [...source];
38
+ for (const targetItem of target) {
39
+ if (isObject(targetItem) && "name" in targetItem) {
40
+ const existingItem = result.find((item) => isObject(item) && ("name" in item) && item.name === targetItem.name);
41
+ if (!existingItem) {
42
+ result.push(targetItem);
43
+ }
44
+ } else if (isObject(targetItem) && "path" in targetItem) {
45
+ const existingItem = result.find((item) => isObject(item) && ("path" in item) && item.path === targetItem.path);
46
+ if (!existingItem) {
47
+ result.push(targetItem);
48
+ }
49
+ } else if (!result.some((item) => deepEquals(item, targetItem))) {
50
+ result.push(targetItem);
51
+ }
52
+ }
53
+ return result;
54
+ }
55
+ if (source.every((item) => typeof item === "string") && target.every((item) => typeof item === "string")) {
56
+ const result = [...source];
57
+ for (const item of target) {
58
+ if (!result.includes(item)) {
59
+ result.push(item);
60
+ }
61
+ }
62
+ return result;
63
+ }
64
+ return source;
65
+ }
66
+ if (!isObject(source) || !isObject(target)) {
67
+ return source;
68
+ }
69
+ const merged = { ...target };
70
+ for (const key in source) {
71
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
72
+ const sourceValue = source[key];
73
+ if (sourceValue === null || sourceValue === undefined) {
74
+ continue;
75
+ } else if (isObject(sourceValue) && isObject(merged[key])) {
76
+ merged[key] = deepMerge(merged[key], sourceValue);
77
+ } else if (Array.isArray(sourceValue) && Array.isArray(merged[key])) {
78
+ if (sourceValue.length > 0 && merged[key].length > 0 && isObject(sourceValue[0]) && isObject(merged[key][0])) {
79
+ const result = [...sourceValue];
80
+ for (const targetItem of merged[key]) {
81
+ if (isObject(targetItem) && "name" in targetItem) {
82
+ const existingItem = result.find((item) => isObject(item) && ("name" in item) && item.name === targetItem.name);
83
+ if (!existingItem) {
84
+ result.push(targetItem);
85
+ }
86
+ } else if (isObject(targetItem) && "path" in targetItem) {
87
+ const existingItem = result.find((item) => isObject(item) && ("path" in item) && item.path === targetItem.path);
88
+ if (!existingItem) {
89
+ result.push(targetItem);
90
+ }
91
+ } else if (!result.some((item) => deepEquals(item, targetItem))) {
92
+ result.push(targetItem);
93
+ }
94
+ }
95
+ merged[key] = result;
96
+ } else if (sourceValue.every((item) => typeof item === "string") && merged[key].every((item) => typeof item === "string")) {
97
+ const result = [...sourceValue];
98
+ for (const item of merged[key]) {
99
+ if (!result.includes(item)) {
100
+ result.push(item);
101
+ }
102
+ }
103
+ merged[key] = result;
104
+ } else {
105
+ merged[key] = sourceValue;
106
+ }
107
+ } else {
108
+ merged[key] = sourceValue;
109
+ }
110
+ }
111
+ }
112
+ return merged;
113
+ }
114
+ function deepEquals(a, b) {
115
+ if (a === b)
116
+ return true;
117
+ if (Array.isArray(a) && Array.isArray(b)) {
118
+ if (a.length !== b.length)
119
+ return false;
120
+ for (let i = 0;i < a.length; i++) {
121
+ if (!deepEquals(a[i], b[i]))
122
+ return false;
123
+ }
124
+ return true;
125
+ }
126
+ if (isObject(a) && isObject(b)) {
127
+ const keysA = Object.keys(a);
128
+ const keysB = Object.keys(b);
129
+ if (keysA.length !== keysB.length)
130
+ return false;
131
+ for (const key of keysA) {
132
+ if (!Object.prototype.hasOwnProperty.call(b, key))
133
+ return false;
134
+ if (!deepEquals(a[key], b[key]))
135
+ return false;
136
+ }
137
+ return true;
138
+ }
139
+ return false;
140
+ }
141
+ function isObject(item) {
142
+ return Boolean(item && typeof item === "object" && !Array.isArray(item));
143
+ }
144
+ async function tryLoadConfig(configPath, defaultConfig) {
145
+ if (!existsSync(configPath))
146
+ return null;
147
+ try {
148
+ const importedConfig = await import(configPath);
149
+ const loadedConfig = importedConfig.default || importedConfig;
150
+ if (typeof loadedConfig !== "object" || loadedConfig === null || Array.isArray(loadedConfig))
151
+ return null;
152
+ try {
153
+ return deepMerge(defaultConfig, loadedConfig);
154
+ } catch {
155
+ return null;
156
+ }
157
+ } catch {
158
+ return null;
159
+ }
160
+ }
161
+ async function loadConfig({
162
+ name = "",
163
+ cwd,
164
+ defaultConfig
165
+ }) {
166
+ const baseDir = cwd || process2.cwd();
167
+ const extensions = [".ts", ".js", ".mjs", ".cjs", ".json"];
168
+ const configPaths = [
169
+ `${name}.config`,
170
+ `.${name}.config`,
171
+ name,
172
+ `.${name}`
173
+ ];
174
+ for (const configPath of configPaths) {
175
+ for (const ext of extensions) {
176
+ const fullPath = resolve(baseDir, `${configPath}${ext}`);
177
+ const config2 = await tryLoadConfig(fullPath, defaultConfig);
178
+ if (config2 !== null) {
179
+ return config2;
180
+ }
181
+ }
182
+ }
183
+ try {
184
+ const pkgPath = resolve(baseDir, "package.json");
185
+ if (existsSync(pkgPath)) {
186
+ const pkg = await import(pkgPath);
187
+ const pkgConfig = pkg[name];
188
+ if (pkgConfig && typeof pkgConfig === "object" && !Array.isArray(pkgConfig)) {
189
+ try {
190
+ return deepMerge(defaultConfig, pkgConfig);
191
+ } catch {}
192
+ }
193
+ }
194
+ } catch {}
195
+ return defaultConfig;
196
+ }
197
+ var defaultConfigDir, defaultGeneratedDir;
198
+ var init_dist = __esm(() => {
199
+ defaultConfigDir = resolve(process2.cwd(), "config");
200
+ defaultGeneratedDir = resolve(process2.cwd(), "src/generated");
201
+ });
202
+
203
+ // src/config.ts
204
+ var defaultConfig, config;
205
+ var init_config = __esm(async () => {
206
+ init_dist();
207
+ defaultConfig = {
208
+ verbose: true,
209
+ rules: {
210
+ "conventional-commits": 2,
211
+ "header-max-length": [2, { maxLength: 72 }],
212
+ "body-max-line-length": [2, { maxLength: 100 }],
213
+ "body-leading-blank": 2,
214
+ "no-trailing-whitespace": 1
215
+ },
216
+ defaultIgnores: [
217
+ "^Merge branch",
218
+ "^Merge pull request",
219
+ "^Merged PR",
220
+ "^Revert ",
221
+ "^Release "
222
+ ],
223
+ ignores: []
224
+ };
225
+ config = await loadConfig({
226
+ name: "gitlint",
227
+ defaultConfig
228
+ });
229
+ });
230
+
231
+ // src/utils.ts
232
+ import fs from "fs";
233
+ import path from "path";
234
+ import process3 from "process";
235
+ function readCommitMessageFromFile(filePath) {
236
+ try {
237
+ return fs.readFileSync(path.resolve(process3.cwd(), filePath), "utf8");
238
+ } catch (error) {
239
+ console.error(`Error reading commit message file: ${filePath}`);
240
+ console.error(error);
241
+ process3.exit(1);
242
+ }
243
+ }
244
+ var init_utils = () => {};
245
+
246
+ // src/hooks.ts
247
+ import { execSync } from "child_process";
248
+ import fs2 from "fs";
249
+ import path2 from "path";
250
+ function findGitRoot() {
251
+ try {
252
+ const gitRoot = execSync("git rev-parse --show-toplevel", { encoding: "utf8" }).trim();
253
+ return gitRoot;
254
+ } catch (_error) {
255
+ return null;
256
+ }
257
+ }
258
+ function installGitHooks(force = false) {
259
+ const gitRoot = findGitRoot();
260
+ if (!gitRoot) {
261
+ console.error("Not a git repository");
262
+ return false;
263
+ }
264
+ const hooksDir = path2.join(gitRoot, ".git", "hooks");
265
+ if (!fs2.existsSync(hooksDir)) {
266
+ console.error(`Git hooks directory not found: ${hooksDir}`);
267
+ return false;
268
+ }
269
+ const commitMsgHookPath = path2.join(hooksDir, "commit-msg");
270
+ const hookExists = fs2.existsSync(commitMsgHookPath);
271
+ if (hookExists && !force) {
272
+ console.error("commit-msg hook already exists. Use --force to overwrite.");
273
+ return false;
274
+ }
275
+ try {
276
+ const hookContent = `#!/bin/sh
277
+ # GitLint commit-msg hook
278
+ # Installed by GitLint (https://github.com/stacksjs/gitlint)
279
+
280
+ gitlint --edit "$1"
281
+ `;
282
+ fs2.writeFileSync(commitMsgHookPath, hookContent, { mode: 493 });
283
+ console.error(`Git commit-msg hook installed at ${commitMsgHookPath}`);
284
+ return true;
285
+ } catch (error) {
286
+ console.error("Failed to install Git hooks:");
287
+ console.error(error);
288
+ return false;
289
+ }
290
+ }
291
+ function uninstallGitHooks() {
292
+ const gitRoot = findGitRoot();
293
+ if (!gitRoot) {
294
+ console.error("Not a git repository");
295
+ return false;
296
+ }
297
+ const commitMsgHookPath = path2.join(gitRoot, ".git", "hooks", "commit-msg");
298
+ if (!fs2.existsSync(commitMsgHookPath)) {
299
+ console.error("No commit-msg hook found");
300
+ return true;
301
+ }
302
+ try {
303
+ const hookContent = fs2.readFileSync(commitMsgHookPath, "utf8");
304
+ if (!hookContent.includes("GitLint commit-msg hook")) {
305
+ console.error("The commit-msg hook was not installed by GitLint. Not removing.");
306
+ return false;
307
+ }
308
+ fs2.unlinkSync(commitMsgHookPath);
309
+ console.error(`Git commit-msg hook removed from ${commitMsgHookPath}`);
310
+ return true;
311
+ } catch (error) {
312
+ console.error("Failed to uninstall Git hooks:");
313
+ console.error(error);
314
+ return false;
315
+ }
316
+ }
317
+ var init_hooks = () => {};
318
+
319
+ // src/rules.ts
320
+ var conventionalCommits, headerMaxLength, bodyMaxLineLength, bodyLeadingBlankLine, noTrailingWhitespace, rules;
321
+ var init_rules = __esm(() => {
322
+ conventionalCommits = {
323
+ name: "conventional-commits",
324
+ description: "Enforces conventional commit format",
325
+ validate: (commitMsg) => {
326
+ const pattern = /^(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(?:\([a-z0-9-]+\))?: .+$/i;
327
+ const firstLine = commitMsg.split(`
328
+ `)[0];
329
+ if (!pattern.test(firstLine.replace(/['"]/g, ""))) {
330
+ return {
331
+ valid: false,
332
+ message: "Commit message header does not follow conventional commit format: <type>[(scope)]: <description>"
333
+ };
334
+ }
335
+ return { valid: true };
336
+ }
337
+ };
338
+ headerMaxLength = {
339
+ name: "header-max-length",
340
+ description: "Enforces a maximum length for the commit message header",
341
+ validate: (commitMsg, config2) => {
342
+ const maxLength = config2?.maxLength || 72;
343
+ const firstLine = commitMsg.split(`
344
+ `)[0];
345
+ if (firstLine.length > maxLength) {
346
+ return {
347
+ valid: false,
348
+ message: `Commit message header exceeds maximum length of ${maxLength} characters`
349
+ };
350
+ }
351
+ return { valid: true };
352
+ }
353
+ };
354
+ bodyMaxLineLength = {
355
+ name: "body-max-line-length",
356
+ description: "Enforces a maximum line length for the commit message body",
357
+ validate: (commitMsg, config2) => {
358
+ const maxLength = config2?.maxLength || 100;
359
+ const lines = commitMsg.split(`
360
+ `).slice(1).filter((line) => line.trim() !== "");
361
+ const longLines = lines.filter((line) => line.length > maxLength);
362
+ if (longLines.length > 0) {
363
+ return {
364
+ valid: false,
365
+ message: `Commit message body contains lines exceeding maximum length of ${maxLength} characters`
366
+ };
367
+ }
368
+ return { valid: true };
369
+ }
370
+ };
371
+ bodyLeadingBlankLine = {
372
+ name: "body-leading-blank",
373
+ description: "Enforces a blank line between the commit header and body",
374
+ validate: (commitMsg) => {
375
+ const lines = commitMsg.split(`
376
+ `);
377
+ if (lines.length > 1 && lines[1].trim() !== "") {
378
+ return {
379
+ valid: false,
380
+ message: "Commit message must have a blank line between header and body"
381
+ };
382
+ }
383
+ return { valid: true };
384
+ }
385
+ };
386
+ noTrailingWhitespace = {
387
+ name: "no-trailing-whitespace",
388
+ description: "Checks for trailing whitespace in commit message",
389
+ validate: (commitMsg) => {
390
+ const lines = commitMsg.split(`
391
+ `);
392
+ const linesWithTrailingWhitespace = lines.filter((line) => /\s+$/.test(line));
393
+ if (linesWithTrailingWhitespace.length > 0) {
394
+ return {
395
+ valid: false,
396
+ message: "Commit message contains lines with trailing whitespace"
397
+ };
398
+ }
399
+ return { valid: true };
400
+ }
401
+ };
402
+ rules = [
403
+ conventionalCommits,
404
+ headerMaxLength,
405
+ bodyMaxLineLength,
406
+ bodyLeadingBlankLine,
407
+ noTrailingWhitespace
408
+ ];
409
+ });
410
+
411
+ // src/lint.ts
412
+ function normalizeRuleLevel(level) {
413
+ if (level === "off")
414
+ return 0;
415
+ if (level === "warning")
416
+ return 1;
417
+ if (level === "error")
418
+ return 2;
419
+ return level;
420
+ }
421
+ function lintCommitMessage(message, verbose = config2.verbose) {
422
+ const result = {
423
+ valid: true,
424
+ errors: [],
425
+ warnings: []
426
+ };
427
+ if (config2.ignores?.some((pattern) => new RegExp(pattern).test(message))) {
428
+ if (verbose) {
429
+ console.error("Commit message matched ignore pattern, skipping validation");
430
+ }
431
+ return result;
432
+ }
433
+ Object.entries(config2.rules || {}).forEach(([ruleName, ruleConfig]) => {
434
+ const rule = rules.find((r) => r.name === ruleName);
435
+ if (!rule) {
436
+ if (verbose) {
437
+ console.warn(`Rule "${ruleName}" not found, skipping`);
438
+ }
439
+ return;
440
+ }
441
+ let level = 0;
442
+ let ruleOptions;
443
+ if (Array.isArray(ruleConfig)) {
444
+ [level, ruleOptions] = ruleConfig;
445
+ } else {
446
+ level = ruleConfig;
447
+ }
448
+ const normalizedLevel = normalizeRuleLevel(level);
449
+ if (normalizedLevel === 0) {
450
+ return;
451
+ }
452
+ const ruleResult = rule.validate(message, ruleOptions);
453
+ if (!ruleResult.valid) {
454
+ const errorMessage = ruleResult.message || `Rule "${ruleName}" failed validation`;
455
+ if (normalizedLevel === 2) {
456
+ result.errors.push(errorMessage);
457
+ result.valid = false;
458
+ } else if (normalizedLevel === 1) {
459
+ result.warnings.push(errorMessage);
460
+ }
461
+ }
462
+ });
463
+ return result;
464
+ }
465
+ var defaultConfig2, config2;
466
+ var init_lint = __esm(() => {
467
+ init_rules();
468
+ defaultConfig2 = {
469
+ verbose: true,
470
+ rules: {
471
+ "conventional-commits": 2,
472
+ "header-max-length": [2, { maxLength: 72 }],
473
+ "body-max-line-length": [2, { maxLength: 100 }],
474
+ "body-leading-blank": 2,
475
+ "no-trailing-whitespace": 1
476
+ },
477
+ ignores: []
478
+ };
479
+ config2 = defaultConfig2;
480
+ });
481
+
482
+ // src/parser.ts
483
+ function parseCommitMessage(message) {
484
+ const lines = message.split(`
485
+ `);
486
+ const header = lines[0] || "";
487
+ const headerMatch = header.replace(/['"]/g, "").match(/^(?<type>\w+)(?:\((?<scope>[^)]+)\))?: ?(?<subject>.+)$/);
488
+ let type = null;
489
+ let scope = null;
490
+ let subject = null;
491
+ if (headerMatch?.groups) {
492
+ type = headerMatch.groups.type || null;
493
+ scope = headerMatch.groups.scope || null;
494
+ subject = headerMatch.groups.subject ? headerMatch.groups.subject.trim() : null;
495
+ }
496
+ const bodyLines = [];
497
+ const footerLines = [];
498
+ let parsingBody = true;
499
+ for (let i = 2;i < lines.length; i++) {
500
+ const line = lines[i];
501
+ if (line.trim() === "" && parsingBody) {
502
+ parsingBody = false;
503
+ continue;
504
+ }
505
+ if (parsingBody) {
506
+ bodyLines.push(line);
507
+ } else {
508
+ footerLines.push(line);
509
+ }
510
+ }
511
+ const body = bodyLines.length > 0 ? bodyLines.join(`
512
+ `) : null;
513
+ const footer = footerLines.length > 0 ? footerLines.join(`
514
+ `) : null;
515
+ const mentions = [];
516
+ const references = [];
517
+ const refRegex = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+(?:(?<owner>[\w-]+)\/(?<repo>[\w-]+))?#(?<issue>\d+)/gi;
518
+ const fullText = message;
519
+ let refMatch = null;
520
+ while ((refMatch = refRegex.exec(fullText)) !== null) {
521
+ const action = refMatch[0].split(/\s+/)[0].toLowerCase();
522
+ const owner = refMatch.groups?.owner || null;
523
+ const repository = refMatch.groups?.repo || null;
524
+ const issue = refMatch.groups?.issue || "";
525
+ references.push({
526
+ action,
527
+ owner,
528
+ repository,
529
+ issue,
530
+ raw: refMatch[0],
531
+ prefix: "#"
532
+ });
533
+ }
534
+ const mentionRegex = /@([\w-]+)/g;
535
+ let mentionMatch = null;
536
+ while ((mentionMatch = mentionRegex.exec(fullText)) !== null) {
537
+ mentions.push(mentionMatch[1]);
538
+ }
539
+ return {
540
+ header,
541
+ type,
542
+ scope,
543
+ subject,
544
+ body,
545
+ footer,
546
+ mentions,
547
+ references,
548
+ raw: message
549
+ };
550
+ }
551
+ // src/index.ts
552
+ var exports_src = {};
553
+ __export(exports_src, {
554
+ uninstallGitHooks: () => uninstallGitHooks,
555
+ rules: () => rules,
556
+ readCommitMessageFromFile: () => readCommitMessageFromFile,
557
+ parseCommitMessage: () => parseCommitMessage,
558
+ lintCommitMessage: () => lintCommitMessage,
559
+ installGitHooks: () => installGitHooks,
560
+ defaultConfig: () => defaultConfig,
561
+ config: () => config
562
+ });
563
+ var init_src = __esm(async () => {
564
+ init_config();
565
+ init_hooks();
566
+ init_lint();
567
+ init_rules();
568
+ init_utils();
569
+ });
570
+
571
+ // bin/cli.ts
572
+ import { Buffer } from "buffer";
573
+ import process4 from "process";
574
+
575
+ // node_modules/cac/dist/index.mjs
576
+ import { EventEmitter } from "events";
577
+ function toArr(any) {
578
+ return any == null ? [] : Array.isArray(any) ? any : [any];
579
+ }
580
+ function toVal(out, key, val, opts) {
581
+ var x, old = out[key], nxt = ~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : ~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
582
+ out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
583
+ }
584
+ function mri2(args, opts) {
585
+ args = args || [];
586
+ opts = opts || {};
587
+ var k, arr, arg, name, val, out = { _: [] };
588
+ var i = 0, j = 0, idx = 0, len = args.length;
589
+ const alibi = opts.alias !== undefined;
590
+ const strict = opts.unknown !== undefined;
591
+ const defaults = opts.default !== undefined;
592
+ opts.alias = opts.alias || {};
593
+ opts.string = toArr(opts.string);
594
+ opts.boolean = toArr(opts.boolean);
595
+ if (alibi) {
596
+ for (k in opts.alias) {
597
+ arr = opts.alias[k] = toArr(opts.alias[k]);
598
+ for (i = 0;i < arr.length; i++) {
599
+ (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
600
+ }
601
+ }
602
+ }
603
+ for (i = opts.boolean.length;i-- > 0; ) {
604
+ arr = opts.alias[opts.boolean[i]] || [];
605
+ for (j = arr.length;j-- > 0; )
606
+ opts.boolean.push(arr[j]);
607
+ }
608
+ for (i = opts.string.length;i-- > 0; ) {
609
+ arr = opts.alias[opts.string[i]] || [];
610
+ for (j = arr.length;j-- > 0; )
611
+ opts.string.push(arr[j]);
612
+ }
613
+ if (defaults) {
614
+ for (k in opts.default) {
615
+ name = typeof opts.default[k];
616
+ arr = opts.alias[k] = opts.alias[k] || [];
617
+ if (opts[name] !== undefined) {
618
+ opts[name].push(k);
619
+ for (i = 0;i < arr.length; i++) {
620
+ opts[name].push(arr[i]);
621
+ }
622
+ }
623
+ }
624
+ }
625
+ const keys = strict ? Object.keys(opts.alias) : [];
626
+ for (i = 0;i < len; i++) {
627
+ arg = args[i];
628
+ if (arg === "--") {
629
+ out._ = out._.concat(args.slice(++i));
630
+ break;
631
+ }
632
+ for (j = 0;j < arg.length; j++) {
633
+ if (arg.charCodeAt(j) !== 45)
634
+ break;
635
+ }
636
+ if (j === 0) {
637
+ out._.push(arg);
638
+ } else if (arg.substring(j, j + 3) === "no-") {
639
+ name = arg.substring(j + 3);
640
+ if (strict && !~keys.indexOf(name)) {
641
+ return opts.unknown(arg);
642
+ }
643
+ out[name] = false;
644
+ } else {
645
+ for (idx = j + 1;idx < arg.length; idx++) {
646
+ if (arg.charCodeAt(idx) === 61)
647
+ break;
648
+ }
649
+ name = arg.substring(j, idx);
650
+ val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
651
+ arr = j === 2 ? [name] : name;
652
+ for (idx = 0;idx < arr.length; idx++) {
653
+ name = arr[idx];
654
+ if (strict && !~keys.indexOf(name))
655
+ return opts.unknown("-".repeat(j) + name);
656
+ toVal(out, name, idx + 1 < arr.length || val, opts);
657
+ }
658
+ }
659
+ }
660
+ if (defaults) {
661
+ for (k in opts.default) {
662
+ if (out[k] === undefined) {
663
+ out[k] = opts.default[k];
664
+ }
665
+ }
666
+ }
667
+ if (alibi) {
668
+ for (k in out) {
669
+ arr = opts.alias[k] || [];
670
+ while (arr.length > 0) {
671
+ out[arr.shift()] = out[k];
672
+ }
673
+ }
674
+ }
675
+ return out;
676
+ }
677
+ var removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
678
+ var findAllBrackets = (v) => {
679
+ const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
680
+ const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
681
+ const res = [];
682
+ const parse = (match) => {
683
+ let variadic = false;
684
+ let value = match[1];
685
+ if (value.startsWith("...")) {
686
+ value = value.slice(3);
687
+ variadic = true;
688
+ }
689
+ return {
690
+ required: match[0].startsWith("<"),
691
+ value,
692
+ variadic
693
+ };
694
+ };
695
+ let angledMatch;
696
+ while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) {
697
+ res.push(parse(angledMatch));
698
+ }
699
+ let squareMatch;
700
+ while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) {
701
+ res.push(parse(squareMatch));
702
+ }
703
+ return res;
704
+ };
705
+ var getMriOptions = (options) => {
706
+ const result = { alias: {}, boolean: [] };
707
+ for (const [index, option] of options.entries()) {
708
+ if (option.names.length > 1) {
709
+ result.alias[option.names[0]] = option.names.slice(1);
710
+ }
711
+ if (option.isBoolean) {
712
+ if (option.negated) {
713
+ const hasStringTypeOption = options.some((o, i) => {
714
+ return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
715
+ });
716
+ if (!hasStringTypeOption) {
717
+ result.boolean.push(option.names[0]);
718
+ }
719
+ } else {
720
+ result.boolean.push(option.names[0]);
721
+ }
722
+ }
723
+ }
724
+ return result;
725
+ };
726
+ var findLongest = (arr) => {
727
+ return arr.sort((a, b) => {
728
+ return a.length > b.length ? -1 : 1;
729
+ })[0];
730
+ };
731
+ var padRight = (str, length) => {
732
+ return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
733
+ };
734
+ var camelcase = (input) => {
735
+ return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
736
+ return p1 + p2.toUpperCase();
737
+ });
738
+ };
739
+ var setDotProp = (obj, keys, val) => {
740
+ let i = 0;
741
+ let length = keys.length;
742
+ let t = obj;
743
+ let x;
744
+ for (;i < length; ++i) {
745
+ x = t[keys[i]];
746
+ t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
747
+ }
748
+ };
749
+ var setByType = (obj, transforms) => {
750
+ for (const key of Object.keys(transforms)) {
751
+ const transform = transforms[key];
752
+ if (transform.shouldTransform) {
753
+ obj[key] = Array.prototype.concat.call([], obj[key]);
754
+ if (typeof transform.transformFunction === "function") {
755
+ obj[key] = obj[key].map(transform.transformFunction);
756
+ }
757
+ }
758
+ }
759
+ };
760
+ var getFileName = (input) => {
761
+ const m = /([^\\\/]+)$/.exec(input);
762
+ return m ? m[1] : "";
763
+ };
764
+ var camelcaseOptionName = (name) => {
765
+ return name.split(".").map((v, i) => {
766
+ return i === 0 ? camelcase(v) : v;
767
+ }).join(".");
768
+ };
769
+
770
+ class CACError extends Error {
771
+ constructor(message) {
772
+ super(message);
773
+ this.name = this.constructor.name;
774
+ if (typeof Error.captureStackTrace === "function") {
775
+ Error.captureStackTrace(this, this.constructor);
776
+ } else {
777
+ this.stack = new Error(message).stack;
778
+ }
779
+ }
780
+ }
781
+
782
+ class Option {
783
+ constructor(rawName, description, config) {
784
+ this.rawName = rawName;
785
+ this.description = description;
786
+ this.config = Object.assign({}, config);
787
+ rawName = rawName.replace(/\.\*/g, "");
788
+ this.negated = false;
789
+ this.names = removeBrackets(rawName).split(",").map((v) => {
790
+ let name = v.trim().replace(/^-{1,2}/, "");
791
+ if (name.startsWith("no-")) {
792
+ this.negated = true;
793
+ name = name.replace(/^no-/, "");
794
+ }
795
+ return camelcaseOptionName(name);
796
+ }).sort((a, b) => a.length > b.length ? 1 : -1);
797
+ this.name = this.names[this.names.length - 1];
798
+ if (this.negated && this.config.default == null) {
799
+ this.config.default = true;
800
+ }
801
+ if (rawName.includes("<")) {
802
+ this.required = true;
803
+ } else if (rawName.includes("[")) {
804
+ this.required = false;
805
+ } else {
806
+ this.isBoolean = true;
807
+ }
808
+ }
809
+ }
810
+ var processArgs = process.argv;
811
+ var platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
812
+
813
+ class Command {
814
+ constructor(rawName, description, config = {}, cli) {
815
+ this.rawName = rawName;
816
+ this.description = description;
817
+ this.config = config;
818
+ this.cli = cli;
819
+ this.options = [];
820
+ this.aliasNames = [];
821
+ this.name = removeBrackets(rawName);
822
+ this.args = findAllBrackets(rawName);
823
+ this.examples = [];
824
+ }
825
+ usage(text) {
826
+ this.usageText = text;
827
+ return this;
828
+ }
829
+ allowUnknownOptions() {
830
+ this.config.allowUnknownOptions = true;
831
+ return this;
832
+ }
833
+ ignoreOptionDefaultValue() {
834
+ this.config.ignoreOptionDefaultValue = true;
835
+ return this;
836
+ }
837
+ version(version, customFlags = "-v, --version") {
838
+ this.versionNumber = version;
839
+ this.option(customFlags, "Display version number");
840
+ return this;
841
+ }
842
+ example(example) {
843
+ this.examples.push(example);
844
+ return this;
845
+ }
846
+ option(rawName, description, config) {
847
+ const option = new Option(rawName, description, config);
848
+ this.options.push(option);
849
+ return this;
850
+ }
851
+ alias(name) {
852
+ this.aliasNames.push(name);
853
+ return this;
854
+ }
855
+ action(callback) {
856
+ this.commandAction = callback;
857
+ return this;
858
+ }
859
+ isMatched(name) {
860
+ return this.name === name || this.aliasNames.includes(name);
861
+ }
862
+ get isDefaultCommand() {
863
+ return this.name === "" || this.aliasNames.includes("!");
864
+ }
865
+ get isGlobalCommand() {
866
+ return this instanceof GlobalCommand;
867
+ }
868
+ hasOption(name) {
869
+ name = name.split(".")[0];
870
+ return this.options.find((option) => {
871
+ return option.names.includes(name);
872
+ });
873
+ }
874
+ outputHelp() {
875
+ const { name, commands } = this.cli;
876
+ const {
877
+ versionNumber,
878
+ options: globalOptions,
879
+ helpCallback
880
+ } = this.cli.globalCommand;
881
+ let sections = [
882
+ {
883
+ body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
884
+ }
885
+ ];
886
+ sections.push({
887
+ title: "Usage",
888
+ body: ` $ ${name} ${this.usageText || this.rawName}`
889
+ });
890
+ const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
891
+ if (showCommands) {
892
+ const longestCommandName = findLongest(commands.map((command) => command.rawName));
893
+ sections.push({
894
+ title: "Commands",
895
+ body: commands.map((command) => {
896
+ return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
897
+ }).join(`
898
+ `)
899
+ });
900
+ sections.push({
901
+ title: `For more info, run any command with the \`--help\` flag`,
902
+ body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join(`
903
+ `)
904
+ });
905
+ }
906
+ let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
907
+ if (!this.isGlobalCommand && !this.isDefaultCommand) {
908
+ options = options.filter((option) => option.name !== "version");
909
+ }
910
+ if (options.length > 0) {
911
+ const longestOptionName = findLongest(options.map((option) => option.rawName));
912
+ sections.push({
913
+ title: "Options",
914
+ body: options.map((option) => {
915
+ return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === undefined ? "" : `(default: ${option.config.default})`}`;
916
+ }).join(`
917
+ `)
918
+ });
919
+ }
920
+ if (this.examples.length > 0) {
921
+ sections.push({
922
+ title: "Examples",
923
+ body: this.examples.map((example) => {
924
+ if (typeof example === "function") {
925
+ return example(name);
926
+ }
927
+ return example;
928
+ }).join(`
929
+ `)
930
+ });
931
+ }
932
+ if (helpCallback) {
933
+ sections = helpCallback(sections) || sections;
934
+ }
935
+ console.log(sections.map((section) => {
936
+ return section.title ? `${section.title}:
937
+ ${section.body}` : section.body;
938
+ }).join(`
939
+
940
+ `));
941
+ }
942
+ outputVersion() {
943
+ const { name } = this.cli;
944
+ const { versionNumber } = this.cli.globalCommand;
945
+ if (versionNumber) {
946
+ console.log(`${name}/${versionNumber} ${platformInfo}`);
947
+ }
948
+ }
949
+ checkRequiredArgs() {
950
+ const minimalArgsCount = this.args.filter((arg) => arg.required).length;
951
+ if (this.cli.args.length < minimalArgsCount) {
952
+ throw new CACError(`missing required args for command \`${this.rawName}\``);
953
+ }
954
+ }
955
+ checkUnknownOptions() {
956
+ const { options, globalCommand } = this.cli;
957
+ if (!this.config.allowUnknownOptions) {
958
+ for (const name of Object.keys(options)) {
959
+ if (name !== "--" && !this.hasOption(name) && !globalCommand.hasOption(name)) {
960
+ throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
961
+ }
962
+ }
963
+ }
964
+ }
965
+ checkOptionValue() {
966
+ const { options: parsedOptions, globalCommand } = this.cli;
967
+ const options = [...globalCommand.options, ...this.options];
968
+ for (const option of options) {
969
+ const value = parsedOptions[option.name.split(".")[0]];
970
+ if (option.required) {
971
+ const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
972
+ if (value === true || value === false && !hasNegated) {
973
+ throw new CACError(`option \`${option.rawName}\` value is missing`);
974
+ }
975
+ }
976
+ }
977
+ }
978
+ }
979
+
980
+ class GlobalCommand extends Command {
981
+ constructor(cli) {
982
+ super("@@global@@", "", {}, cli);
983
+ }
984
+ }
985
+ var __assign = Object.assign;
986
+
987
+ class CAC extends EventEmitter {
988
+ constructor(name = "") {
989
+ super();
990
+ this.name = name;
991
+ this.commands = [];
992
+ this.rawArgs = [];
993
+ this.args = [];
994
+ this.options = {};
995
+ this.globalCommand = new GlobalCommand(this);
996
+ this.globalCommand.usage("<command> [options]");
997
+ }
998
+ usage(text) {
999
+ this.globalCommand.usage(text);
1000
+ return this;
1001
+ }
1002
+ command(rawName, description, config) {
1003
+ const command = new Command(rawName, description || "", config, this);
1004
+ command.globalCommand = this.globalCommand;
1005
+ this.commands.push(command);
1006
+ return command;
1007
+ }
1008
+ option(rawName, description, config) {
1009
+ this.globalCommand.option(rawName, description, config);
1010
+ return this;
1011
+ }
1012
+ help(callback) {
1013
+ this.globalCommand.option("-h, --help", "Display this message");
1014
+ this.globalCommand.helpCallback = callback;
1015
+ this.showHelpOnExit = true;
1016
+ return this;
1017
+ }
1018
+ version(version, customFlags = "-v, --version") {
1019
+ this.globalCommand.version(version, customFlags);
1020
+ this.showVersionOnExit = true;
1021
+ return this;
1022
+ }
1023
+ example(example) {
1024
+ this.globalCommand.example(example);
1025
+ return this;
1026
+ }
1027
+ outputHelp() {
1028
+ if (this.matchedCommand) {
1029
+ this.matchedCommand.outputHelp();
1030
+ } else {
1031
+ this.globalCommand.outputHelp();
1032
+ }
1033
+ }
1034
+ outputVersion() {
1035
+ this.globalCommand.outputVersion();
1036
+ }
1037
+ setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
1038
+ this.args = args;
1039
+ this.options = options;
1040
+ if (matchedCommand) {
1041
+ this.matchedCommand = matchedCommand;
1042
+ }
1043
+ if (matchedCommandName) {
1044
+ this.matchedCommandName = matchedCommandName;
1045
+ }
1046
+ return this;
1047
+ }
1048
+ unsetMatchedCommand() {
1049
+ this.matchedCommand = undefined;
1050
+ this.matchedCommandName = undefined;
1051
+ }
1052
+ parse(argv = processArgs, {
1053
+ run = true
1054
+ } = {}) {
1055
+ this.rawArgs = argv;
1056
+ if (!this.name) {
1057
+ this.name = argv[1] ? getFileName(argv[1]) : "cli";
1058
+ }
1059
+ let shouldParse = true;
1060
+ for (const command of this.commands) {
1061
+ const parsed = this.mri(argv.slice(2), command);
1062
+ const commandName = parsed.args[0];
1063
+ if (command.isMatched(commandName)) {
1064
+ shouldParse = false;
1065
+ const parsedInfo = __assign(__assign({}, parsed), {
1066
+ args: parsed.args.slice(1)
1067
+ });
1068
+ this.setParsedInfo(parsedInfo, command, commandName);
1069
+ this.emit(`command:${commandName}`, command);
1070
+ }
1071
+ }
1072
+ if (shouldParse) {
1073
+ for (const command of this.commands) {
1074
+ if (command.name === "") {
1075
+ shouldParse = false;
1076
+ const parsed = this.mri(argv.slice(2), command);
1077
+ this.setParsedInfo(parsed, command);
1078
+ this.emit(`command:!`, command);
1079
+ }
1080
+ }
1081
+ }
1082
+ if (shouldParse) {
1083
+ const parsed = this.mri(argv.slice(2));
1084
+ this.setParsedInfo(parsed);
1085
+ }
1086
+ if (this.options.help && this.showHelpOnExit) {
1087
+ this.outputHelp();
1088
+ run = false;
1089
+ this.unsetMatchedCommand();
1090
+ }
1091
+ if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
1092
+ this.outputVersion();
1093
+ run = false;
1094
+ this.unsetMatchedCommand();
1095
+ }
1096
+ const parsedArgv = { args: this.args, options: this.options };
1097
+ if (run) {
1098
+ this.runMatchedCommand();
1099
+ }
1100
+ if (!this.matchedCommand && this.args[0]) {
1101
+ this.emit("command:*");
1102
+ }
1103
+ return parsedArgv;
1104
+ }
1105
+ mri(argv, command) {
1106
+ const cliOptions = [
1107
+ ...this.globalCommand.options,
1108
+ ...command ? command.options : []
1109
+ ];
1110
+ const mriOptions = getMriOptions(cliOptions);
1111
+ let argsAfterDoubleDashes = [];
1112
+ const doubleDashesIndex = argv.indexOf("--");
1113
+ if (doubleDashesIndex > -1) {
1114
+ argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
1115
+ argv = argv.slice(0, doubleDashesIndex);
1116
+ }
1117
+ let parsed = mri2(argv, mriOptions);
1118
+ parsed = Object.keys(parsed).reduce((res, name) => {
1119
+ return __assign(__assign({}, res), {
1120
+ [camelcaseOptionName(name)]: parsed[name]
1121
+ });
1122
+ }, { _: [] });
1123
+ const args = parsed._;
1124
+ const options = {
1125
+ "--": argsAfterDoubleDashes
1126
+ };
1127
+ const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
1128
+ let transforms = Object.create(null);
1129
+ for (const cliOption of cliOptions) {
1130
+ if (!ignoreDefault && cliOption.config.default !== undefined) {
1131
+ for (const name of cliOption.names) {
1132
+ options[name] = cliOption.config.default;
1133
+ }
1134
+ }
1135
+ if (Array.isArray(cliOption.config.type)) {
1136
+ if (transforms[cliOption.name] === undefined) {
1137
+ transforms[cliOption.name] = Object.create(null);
1138
+ transforms[cliOption.name]["shouldTransform"] = true;
1139
+ transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
1140
+ }
1141
+ }
1142
+ }
1143
+ for (const key of Object.keys(parsed)) {
1144
+ if (key !== "_") {
1145
+ const keys = key.split(".");
1146
+ setDotProp(options, keys, parsed[key]);
1147
+ setByType(options, transforms);
1148
+ }
1149
+ }
1150
+ return {
1151
+ args,
1152
+ options
1153
+ };
1154
+ }
1155
+ runMatchedCommand() {
1156
+ const { args, options, matchedCommand: command } = this;
1157
+ if (!command || !command.commandAction)
1158
+ return;
1159
+ command.checkUnknownOptions();
1160
+ command.checkOptionValue();
1161
+ command.checkRequiredArgs();
1162
+ const actionArgs = [];
1163
+ command.args.forEach((arg, index) => {
1164
+ if (arg.variadic) {
1165
+ actionArgs.push(args.slice(index));
1166
+ } else {
1167
+ actionArgs.push(args[index]);
1168
+ }
1169
+ });
1170
+ actionArgs.push(options);
1171
+ return command.commandAction.apply(this, actionArgs);
1172
+ }
1173
+ }
1174
+ // package.json
1175
+ var version = "0.1.5";
1176
+
1177
+ // bin/cli.ts
1178
+ await init_config();
1179
+ init_utils();
1180
+ var cli = new CAC("gitlint");
1181
+ cli.command("[...files]", "Lint commit message").example("gitlint").example("gitlint .git/COMMIT_EDITMSG").example("git log -1 --pretty=%B | gitlint").option("--verbose", "Enable verbose output", { default: defaultConfig.verbose }).option("--config <file>", "Path to config file").option("--edit", "Read commit message from a file (used by git hooks)").action(async (files, options) => {
1182
+ let commitMessage = "";
1183
+ if (options.edit && files.length > 0) {
1184
+ commitMessage = readCommitMessageFromFile(files[0]);
1185
+ } else if (files.length > 0) {
1186
+ commitMessage = readCommitMessageFromFile(files[0]);
1187
+ } else if (!process4.stdin.isTTY) {
1188
+ const chunks = [];
1189
+ for await (const chunk of process4.stdin)
1190
+ chunks.push(Buffer.from(chunk));
1191
+ commitMessage = Buffer.concat(chunks).toString("utf8");
1192
+ } else {
1193
+ cli.outputHelp();
1194
+ process4.exit(1);
1195
+ }
1196
+ try {
1197
+ const { lintCommitMessage: lintCommitMessage2 } = await init_src().then(() => exports_src);
1198
+ const result = lintCommitMessage2(commitMessage, options.verbose);
1199
+ if (!result.valid) {
1200
+ console.error("Commit message validation failed:");
1201
+ result.errors.forEach((error) => {
1202
+ console.error(`- ${error}`);
1203
+ });
1204
+ process4.exit(1);
1205
+ }
1206
+ if (options.verbose) {
1207
+ console.log("Commit message validation passed! \u2705");
1208
+ }
1209
+ } catch (error) {
1210
+ console.error("Error during commit message linting:");
1211
+ console.error(error);
1212
+ process4.exit(1);
1213
+ }
1214
+ process4.exit(0);
1215
+ });
1216
+ cli.command("hooks", "Manage git hooks").example("gitlint hooks --install").example("gitlint hooks --install --force").example("gitlint hooks --uninstall").option("--install", "Install git hooks").option("--uninstall", "Uninstall git hooks").option("--force", "Force overwrite existing hooks").action(async (options) => {
1217
+ try {
1218
+ const { installGitHooks: installGitHooks2, uninstallGitHooks: uninstallGitHooks2 } = await init_src().then(() => exports_src);
1219
+ if (options.install) {
1220
+ const success = installGitHooks2(options.force);
1221
+ process4.exit(success ? 0 : 1);
1222
+ } else if (options.uninstall) {
1223
+ const success = uninstallGitHooks2();
1224
+ process4.exit(success ? 0 : 1);
1225
+ } else {
1226
+ console.error("Please specify --install or --uninstall");
1227
+ process4.exit(1);
1228
+ }
1229
+ } catch (error) {
1230
+ console.error("Error managing git hooks:");
1231
+ console.error(error);
1232
+ process4.exit(1);
1233
+ }
1234
+ });
1235
+ cli.command("version", "Show the version of gitlint").example("gitlint version").action(() => {
1236
+ console.log(version);
1237
+ });
1238
+ cli.help();
1239
+ cli.version(version);
1240
+ cli.parse();
package/dist/hooks.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  declare function findGitRoot(): string | null;
2
- export declare function installGitHooks(force): boolean;
2
+ export declare function installGitHooks(force?: boolean): boolean;
3
3
  export declare function uninstallGitHooks(): boolean;
package/dist/index.js CHANGED
@@ -161,11 +161,23 @@ async function loadConfig({
161
161
  for (const ext of extensions) {
162
162
  const fullPath = resolve(baseDir, `${configPath}${ext}`);
163
163
  const config2 = await tryLoadConfig(fullPath, defaultConfig);
164
- if (config2 !== null)
164
+ if (config2 !== null) {
165
165
  return config2;
166
+ }
166
167
  }
167
168
  }
168
- console.error("Failed to load client config from any expected location");
169
+ try {
170
+ const pkgPath = resolve(baseDir, "package.json");
171
+ if (existsSync(pkgPath)) {
172
+ const pkg = await import(pkgPath);
173
+ const pkgConfig = pkg[name];
174
+ if (pkgConfig && typeof pkgConfig === "object" && !Array.isArray(pkgConfig)) {
175
+ try {
176
+ return deepMerge(defaultConfig, pkgConfig);
177
+ } catch {}
178
+ }
179
+ }
180
+ } catch {}
169
181
  return defaultConfig;
170
182
  }
171
183
  var defaultConfigDir = resolve(process.cwd(), "config");
@@ -270,9 +282,10 @@ var conventionalCommits = {
270
282
  name: "conventional-commits",
271
283
  description: "Enforces conventional commit format",
272
284
  validate: (commitMsg) => {
273
- const pattern = /^(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(?:\([a-z0-9-]+\))?: .+/i;
274
- if (!pattern.test(commitMsg.split(`
275
- `)[0])) {
285
+ const pattern = /^(?:build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(?:\([a-z0-9-]+\))?: .+$/i;
286
+ const firstLine = commitMsg.split(`
287
+ `)[0];
288
+ if (!pattern.test(firstLine.replace(/['"]/g, ""))) {
276
289
  return {
277
290
  valid: false,
278
291
  message: "Commit message header does not follow conventional commit format: <type>[(scope)]: <description>"
@@ -424,7 +437,7 @@ function parseCommitMessage(message) {
424
437
  const lines = message.split(`
425
438
  `);
426
439
  const header = lines[0] || "";
427
- const headerMatch = header.match(/^(?<type>\w+)(?:\((?<scope>[^)]+)\))?:(?<subject>.+)$/);
440
+ const headerMatch = header.replace(/['"]/g, "").match(/^(?<type>\w+)(?:\((?<scope>[^)]+)\))?: ?(?<subject>.+)$/);
428
441
  let type = null;
429
442
  let scope = null;
430
443
  let subject = null;
package/dist/lint.d.ts CHANGED
@@ -23,4 +23,4 @@ declare const defaultConfig: {
23
23
  };
24
24
  declare const config: unknown;
25
25
  declare function normalizeRuleLevel(level: RuleLevel): 0 | 1 | 2;
26
- export declare function lintCommitMessage(message: string, verbose: boolean): LintResult;
26
+ export declare function lintCommitMessage(message: string, verbose?: boolean): LintResult;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/gitlint",
3
3
  "type": "module",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "description": "Efficient Git Commit Message Linting and Formatting",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -59,24 +59,29 @@
59
59
  "dev:docs": "bun --bun vitepress dev docs",
60
60
  "build:docs": "bun --bun vitepress build docs",
61
61
  "preview:docs": "bun --bun vitepress preview docs",
62
- "typecheck": "bun --bun tsc --noEmit"
62
+ "typecheck": "bun --bun tsc --noEmit",
63
+ "postinstall": "bun run scripts/postinstall.ts"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@stacksjs/docs": "^0.70.23",
66
67
  "@stacksjs/eslint-config": "^4.10.2-beta.3",
67
- "@types/bun": "^1.2.9",
68
+ "@types/bun": "^1.2.12",
68
69
  "bumpp": "^10.1.0",
69
- "bun-plugin-dtsx": "^0.21.9",
70
- "bunfig": "^0.8.2",
70
+ "bun-git-hooks": "^0.2.13",
71
+ "bun-plugin-dtsx": "^0.21.12",
72
+ "bunfig": "^0.8.5",
71
73
  "changelogen": "^0.6.1",
72
- "lint-staged": "^15.5.1",
73
- "simple-git-hooks": "^2.12.1",
74
74
  "typescript": "^5.8.3"
75
75
  },
76
+ "git-hooks": {
77
+ "pre-commit": {
78
+ "staged-lint": {
79
+ "*.{js,ts,json,yaml,yml,md}": "bunx --bun eslint . --fix"
80
+ }
81
+ },
82
+ "commit-msg": "bunx gitlint"
83
+ },
76
84
  "overrides": {
77
85
  "unconfig": "0.3.10"
78
- },
79
- "lint-staged": {
80
- "*.{js,ts}": "bunx --bun eslint . --fix"
81
86
  }
82
87
  }