Skip to content

Commit f7fcc5d

Browse files
chore: apply prettier formatting to command files
• Apply consistent code formatting across all command files • Improve line breaks and spacing for better readability • Format long parameter lists and function calls • Ensure consistent code style in commit, preview, revert, and test commands
1 parent 2f8b120 commit f7fcc5d

File tree

12 files changed

+307
-142
lines changed

12 files changed

+307
-142
lines changed

src/cli/commands/commit/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,8 @@ export async function commitAction(options: {
449449
type = typeResult.type;
450450
emoji = typeResult.emoji;
451451
// Re-validate scope if type changed (scope requirements might have changed)
452-
const isScopeRequired = config.validation.require_scope_for.includes(
453-
type,
454-
);
452+
const isScopeRequired =
453+
config.validation.require_scope_for.includes(type);
455454
if (isScopeRequired && !scope) {
456455
// Scope is now required, prompt for it
457456
scope = await promptScope(config, type, undefined, scope);

src/cli/commands/commit/prompts.ts

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ export async function promptType(
124124
{
125125
message: `${label("type", "magenta")} ${textColors.pureWhite("Select commit type:")}`,
126126
options,
127-
initialValue: initialIndex !== undefined && initialIndex >= 0 ? config.types[initialIndex].id : undefined,
127+
initialValue:
128+
initialIndex !== undefined && initialIndex >= 0
129+
? config.types[initialIndex].id
130+
: undefined,
128131
},
129132
shortcutMapping,
130133
);
@@ -157,8 +160,12 @@ export async function promptScope(
157160
console.error(
158161
`\n✗ Error: Scope is required for commit type '${selectedType}'`,
159162
);
160-
console.error("\n Your configuration requires a scope for this commit type.");
161-
console.error(`\n Fix: Add scope with -s <scope> or run 'lab commit' interactively\n`);
163+
console.error(
164+
"\n Your configuration requires a scope for this commit type.",
165+
);
166+
console.error(
167+
`\n Fix: Add scope with -s <scope> or run 'lab commit' interactively\n`,
168+
);
162169
process.exit(1);
163170
}
164171
if (allowedScopes.length > 0 && !allowedScopes.includes(providedScope)) {
@@ -194,7 +201,10 @@ export async function promptScope(
194201
`Enter scope ${isRequired ? "(required for '" + selectedType + "')" : "(optional)"}:`,
195202
)}`,
196203
options,
197-
initialValue: initialIndex !== undefined && initialIndex >= 0 ? allowedScopes[initialIndex] : initialScope || undefined,
204+
initialValue:
205+
initialIndex !== undefined && initialIndex >= 0
206+
? allowedScopes[initialIndex]
207+
: initialScope || undefined,
198208
});
199209

200210
handleCancel(selected);
@@ -300,7 +310,9 @@ export async function promptSubject(
300310
console.error(` ${error.context}`);
301311
}
302312
}
303-
console.error(`\n Fix: Correct the subject and try again, or run 'lab commit' interactively\n`);
313+
console.error(
314+
`\n Fix: Correct the subject and try again, or run 'lab commit' interactively\n`,
315+
);
304316
process.exit(1);
305317
}
306318
return providedMessage;
@@ -483,7 +495,11 @@ export async function promptBody(
483495
const shortcut = shortcutMapping
484496
? getShortcutForValue(option.value, shortcutMapping)
485497
: undefined;
486-
const label = formatLabelWithShortcut(option.label, shortcut, displayHints);
498+
const label = formatLabelWithShortcut(
499+
option.label,
500+
shortcut,
501+
displayHints,
502+
);
487503

488504
return {
489505
value: option.value,
@@ -562,7 +578,11 @@ export async function promptBody(
562578
const shortcut = shortcutMapping
563579
? getShortcutForValue(option.value, shortcutMapping)
564580
: undefined;
565-
const label = formatLabelWithShortcut(option.label, shortcut, displayHints);
581+
const label = formatLabelWithShortcut(
582+
option.label,
583+
shortcut,
584+
displayHints,
585+
);
566586

567587
return {
568588
value: option.value,
@@ -583,7 +603,10 @@ export async function promptBody(
583603
handleCancel(inputMethod);
584604

585605
if (inputMethod === "editor") {
586-
const editorBody = await promptBodyWithEditor(config, typeof body === "string" ? body : initialBody || "");
606+
const editorBody = await promptBodyWithEditor(
607+
config,
608+
typeof body === "string" ? body : initialBody || "",
609+
);
587610
if (editorBody !== null && editorBody !== undefined) {
588611
body = editorBody;
589612
} else {
@@ -681,7 +704,11 @@ async function promptBodyRequiredWithEditor(
681704
const shortcut = shortcutMapping
682705
? getShortcutForValue(option.value, shortcutMapping)
683706
: undefined;
684-
const label = formatLabelWithShortcut(option.label, shortcut, displayHints);
707+
const label = formatLabelWithShortcut(
708+
option.label,
709+
shortcut,
710+
displayHints,
711+
);
685712

686713
return {
687714
value: option.value,
@@ -789,7 +816,11 @@ async function promptBodyWithEditor(
789816
const shortcut = shortcutMapping
790817
? getShortcutForValue(option.value, shortcutMapping)
791818
: undefined;
792-
const label = formatLabelWithShortcut(option.label, shortcut, displayHints);
819+
const label = formatLabelWithShortcut(
820+
option.label,
821+
shortcut,
822+
displayHints,
823+
);
793824

794825
return {
795826
value: option.value,
@@ -1045,7 +1076,14 @@ export async function displayPreview(
10451076
formattedMessage: string,
10461077
body: string | undefined,
10471078
config?: LabcommitrConfig,
1048-
): Promise<"commit" | "edit-type" | "edit-scope" | "edit-subject" | "edit-body" | "cancel"> {
1079+
): Promise<
1080+
| "commit"
1081+
| "edit-type"
1082+
| "edit-scope"
1083+
| "edit-subject"
1084+
| "edit-body"
1085+
| "cancel"
1086+
> {
10491087
// Start connector line using @clack/prompts
10501088
log.info(
10511089
`${label("preview", "green")} ${textColors.pureWhite("Commit message preview:")}`,
@@ -1081,11 +1119,7 @@ export async function displayPreview(
10811119
];
10821120

10831121
const shortcutMapping = config
1084-
? processShortcuts(
1085-
config.advanced.shortcuts,
1086-
"preview",
1087-
previewOptions,
1088-
)
1122+
? processShortcuts(config.advanced.shortcuts, "preview", previewOptions)
10891123
: null;
10901124

10911125
const displayHints = config?.advanced.shortcuts?.display_hints ?? true;
@@ -1112,5 +1146,11 @@ export async function displayPreview(
11121146
);
11131147

11141148
handleCancel(action);
1115-
return action as "commit" | "edit-type" | "edit-scope" | "edit-subject" | "edit-body" | "cancel";
1149+
return action as
1150+
| "commit"
1151+
| "edit-type"
1152+
| "edit-scope"
1153+
| "edit-subject"
1154+
| "edit-body"
1155+
| "cancel";
11161156
}

src/cli/commands/preview/index.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,13 @@ async function previewAction(options: {
7272

7373
const remaining = maxCommits - totalFetched;
7474
const toFetch = Math.min(remaining, 50);
75-
75+
7676
// Get the last commit hash we've already fetched to exclude it from next fetch
77-
const lastHash = allCommits.length > 0 ? allCommits[allCommits.length - 1].hash : undefined;
78-
77+
const lastHash =
78+
allCommits.length > 0
79+
? allCommits[allCommits.length - 1].hash
80+
: undefined;
81+
7982
const newCommits = fetchCommits(toFetch, branch, lastHash);
8083
allCommits = [...allCommits, ...newCommits];
8184
totalFetched = allCommits.length;
@@ -131,9 +134,7 @@ async function previewAction(options: {
131134
);
132135
const diff = getCommitDiff(currentDetailCommit.hash);
133136
console.log(diff);
134-
console.log(
135-
`\n${textColors.white("Press any key to go back...")}`,
136-
);
137+
console.log(`\n${textColors.white("Press any key to go back...")}`);
137138
await new Promise((resolve) => {
138139
process.stdin.setRawMode(true);
139140
process.stdin.resume();
@@ -176,12 +177,24 @@ async function previewAction(options: {
176177
const maxIndex = pageCommits.length - 1;
177178

178179
// Check if there are more pages to show (either already loaded or can be fetched)
179-
const hasMorePages = (currentPage + 1) * pageSize < allCommits.length || hasMore;
180+
const hasMorePages =
181+
(currentPage + 1) * pageSize < allCommits.length || hasMore;
180182
const hasPreviousPage = currentPage > 0;
181183

182-
displayCommitList(pageCommits, startIndex, totalFetched, hasMore, hasPreviousPage, hasMorePages);
184+
displayCommitList(
185+
pageCommits,
186+
startIndex,
187+
totalFetched,
188+
hasMore,
189+
hasPreviousPage,
190+
hasMorePages,
191+
);
183192

184-
const action = await waitForListAction(maxIndex, hasMorePages, hasPreviousPage);
193+
const action = await waitForListAction(
194+
maxIndex,
195+
hasMorePages,
196+
hasPreviousPage,
197+
);
185198

186199
if (typeof action === "number") {
187200
// View commit details
@@ -214,7 +227,7 @@ async function previewAction(options: {
214227
} else if (action === "next") {
215228
// Move to next page
216229
const nextPageStart = (currentPage + 1) * pageSize;
217-
230+
218231
// If we need more commits and they're available, load them
219232
if (nextPageStart >= allCommits.length && hasMore) {
220233
console.log("\n Loading next batch...");
@@ -226,7 +239,7 @@ async function previewAction(options: {
226239
continue;
227240
}
228241
}
229-
242+
230243
// Increment page if we have commits to show
231244
if (nextPageStart < allCommits.length) {
232245
currentPage++;
@@ -263,7 +276,13 @@ async function previewAction(options: {
263276
*/
264277
export const previewCommand = new Command("preview")
265278
.description("Browse and inspect commit history")
266-
.option("-l, --limit <number>", "Maximum commits to fetch (default: 50, max: 100)", "50")
267-
.option("-b, --branch <branch>", "Branch to preview (default: current branch)")
279+
.option(
280+
"-l, --limit <number>",
281+
"Maximum commits to fetch (default: 50, max: 100)",
282+
"50",
283+
)
284+
.option(
285+
"-b, --branch <branch>",
286+
"Branch to preview (default: current branch)",
287+
)
268288
.action(previewAction);
269-

src/cli/commands/preview/prompts.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function displayCommitList(
8080
// Pagination info
8181
const endIndex = startIndex + displayCount;
8282
console.log();
83-
83+
8484
if (hasMore) {
8585
console.log(
8686
` Showing commits ${startIndex + 1}-${endIndex} of ${totalFetched}+`,
@@ -91,22 +91,30 @@ export function displayCommitList(
9191
);
9292
}
9393
console.log();
94-
94+
9595
// Build navigation hints
9696
const navHints: string[] = [];
97-
navHints.push(`${textColors.brightCyan("0-9")} ${textColors.white("to view details")}`);
97+
navHints.push(
98+
`${textColors.brightCyan("0-9")} ${textColors.white("to view details")}`,
99+
);
98100
if (hasPreviousPage) {
99-
navHints.push(`${textColors.brightYellow("p")} ${textColors.white("for previous batch")}`);
101+
navHints.push(
102+
`${textColors.brightYellow("p")} ${textColors.white("for previous batch")}`,
103+
);
100104
}
101105
if (hasMorePages) {
102-
navHints.push(`${textColors.brightYellow("n")} ${textColors.white("for next batch")}`);
106+
navHints.push(
107+
`${textColors.brightYellow("n")} ${textColors.white("for next batch")}`,
108+
);
103109
}
104-
navHints.push(`${textColors.brightYellow("?")} ${textColors.white("for help")}`);
105-
navHints.push(`${textColors.brightYellow("Esc")} ${textColors.white("to exit")}`);
106-
107-
console.log(
108-
` ${textColors.white("Press")} ${navHints.join(`, `)}`,
110+
navHints.push(
111+
`${textColors.brightYellow("?")} ${textColors.white("for help")}`,
112+
);
113+
navHints.push(
114+
`${textColors.brightYellow("Esc")} ${textColors.white("to exit")}`,
109115
);
116+
117+
console.log(` ${textColors.white("Press")} ${navHints.join(`, `)}`);
110118
}
111119

112120
/**
@@ -125,9 +133,13 @@ export function displayCommitDetails(
125133
console.log(` ${textColors.brightWhite("Hash:")} ${commit.hash}`);
126134
console.log(` ${textColors.brightWhite("Subject:")} ${commit.subject}`);
127135
console.log();
128-
console.log(` ${textColors.brightWhite("Author:")} ${commit.author.name} <${commit.author.email}>`);
136+
console.log(
137+
` ${textColors.brightWhite("Author:")} ${commit.author.name} <${commit.author.email}>`,
138+
);
129139
console.log(` ${textColors.brightWhite("Date:")} ${commit.date.absolute}`);
130-
console.log(` ${textColors.brightWhite("Relative:")} ${commit.date.relative}`);
140+
console.log(
141+
` ${textColors.brightWhite("Relative:")} ${commit.date.relative}`,
142+
);
131143
console.log();
132144

133145
if (commit.parents.length > 0) {
@@ -147,10 +159,14 @@ export function displayCommitDetails(
147159
console.log(` ${textColors.brightWhite("File Statistics:")}`);
148160
console.log(` Files changed: ${commit.fileStats.filesChanged}`);
149161
if (commit.fileStats.additions !== undefined) {
150-
console.log(` Additions: ${textColors.gitAdded(`+${commit.fileStats.additions}`)}`);
162+
console.log(
163+
` Additions: ${textColors.gitAdded(`+${commit.fileStats.additions}`)}`,
164+
);
151165
}
152166
if (commit.fileStats.deletions !== undefined) {
153-
console.log(` Deletions: ${textColors.gitDeleted(`-${commit.fileStats.deletions}`)}`);
167+
console.log(
168+
` Deletions: ${textColors.gitDeleted(`-${commit.fileStats.deletions}`)}`,
169+
);
154170
}
155171
console.log();
156172
}
@@ -362,4 +378,3 @@ export async function waitForListAction(
362378
stdin.on("keypress", onKeypress);
363379
});
364380
}
365-

0 commit comments

Comments
 (0)