Skip to content

Commit 5de8478

Browse files
committed
chore(scan create): trim redundant comments and restore export order
Match the sibling `cmd-scan-*` convention of placing `export const cmd*` immediately before `async function run`, and drop comments that restated the code rather than explaining non-obvious *why*. The one remaining comment on the misuse check keeps the meow/yargs-parser coercion detail, which isn't derivable from reading the code.
1 parent 54f92cc commit 5de8478

2 files changed

Lines changed: 10 additions & 28 deletions

File tree

packages/cli/src/commands/scan/cmd-scan-create.mts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ const generalFlags: MeowFlags = {
202202
},
203203
}
204204

205-
// Scan argv for `--default-branch=<non-bool-string>` (both kebab-case
206-
// and yargs-parser's camelCase expansion). The flag is declared boolean,
207-
// so meow coerces `--default-branch=main` to `true` and discards "main"
208-
// — silently leaving the scan without a branch tag.
209205
const DEFAULT_BRANCH_PREFIXES = ['--default-branch=', '--defaultBranch=']
210206

211207
function findDefaultBranchValueMisuse(
@@ -226,6 +222,12 @@ function findDefaultBranchValueMisuse(
226222
return undefined
227223
}
228224

225+
export const cmdScanCreate = {
226+
description,
227+
hidden,
228+
run,
229+
}
230+
229231
async function run(
230232
argv: string[] | readonly string[],
231233
importMeta: ImportMeta,
@@ -290,18 +292,13 @@ async function run(
290292
`,
291293
}
292294

293-
// Detect the common `--default-branch=main` misuse before meow parses.
294-
// `--default-branch` is a boolean — meow/yargs-parser treats
295-
// `--default-branch=main` as `defaultBranch=true` and silently drops
296-
// the "main" portion, so the user's scan gets tagged without the
297-
// intended branch name and doesn't appear in the Main/PR dashboard
298-
// tabs. Fail fast with a suggestion toward the correct form.
295+
// `--default-branch` is declared boolean, so meow/yargs-parser
296+
// coerces `--default-branch=main` to `defaultBranch=true` and drops
297+
// "main" silently — the resulting scan is untagged and invisible in
298+
// the Main/PR dashboard tabs. Catch that shape before meow parses.
299299
const defaultBranchMisuse = findDefaultBranchValueMisuse(argv)
300300
if (defaultBranchMisuse) {
301301
const { prefix, value } = defaultBranchMisuse
302-
// Strip the trailing `=` from the matched prefix when naming the
303-
// canonical flag in the suggestion — users should always be told
304-
// to use the kebab-case form.
305302
logger.fail(
306303
`"${prefix}${value}" looks like you meant the branch name "${value}".\n--default-branch is a boolean flag; pass the branch name with --branch instead:\n socket scan create --branch ${value} --default-branch`,
307304
)
@@ -717,9 +714,3 @@ async function run(
717714
workspace: (workspace && String(workspace)) || '',
718715
})
719716
}
720-
721-
export const cmdScanCreate = {
722-
description,
723-
hidden,
724-
run,
725-
}

packages/cli/test/unit/commands/scan/cmd-scan-create.test.mts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,10 +1368,6 @@ describe('cmd-scan-create', () => {
13681368
})
13691369

13701370
describe('--default-branch misuse detection', () => {
1371-
// --default-branch is a boolean flag; meow silently discards the
1372-
// `=<value>` portion on `--default-branch=<name>`. Catch that
1373-
// pattern before meow parses so users get a clear error pointing
1374-
// at the right shape (`--branch <name> --default-branch`).
13751371
it('fails when --default-branch=<name> is passed with a branch name', async () => {
13761372
await cmdScanCreate.run(
13771373
['--org', 'test-org', '--default-branch=main', '.'],
@@ -1392,8 +1388,6 @@ describe('cmd-scan-create', () => {
13921388
})
13931389

13941390
it('also catches the camelCase --defaultBranch=<name> variant', async () => {
1395-
// yargs-parser expands camelCase, so users can type either
1396-
// form from the shell. See Cursor bugbot feedback on PR #1230.
13971391
await cmdScanCreate.run(
13981392
['--org', 'test-org', '--defaultBranch=main', '.'],
13991393
importMeta,
@@ -1405,8 +1399,6 @@ describe('cmd-scan-create', () => {
14051399
expect(mockLogger.fail).toHaveBeenCalledWith(
14061400
expect.stringContaining('looks like you meant the branch name "main"'),
14071401
)
1408-
// Error quotes the exact form the user typed so there's no
1409-
// confusion about whether the error applies to their input.
14101402
expect(mockLogger.fail).toHaveBeenCalledWith(
14111403
expect.stringContaining('"--defaultBranch=main"'),
14121404
)
@@ -1433,7 +1425,6 @@ describe('cmd-scan-create', () => {
14331425
context,
14341426
)
14351427

1436-
// meow parses the flag normally and flows through to handleCreateNewScan.
14371428
expect(mockLogger.fail).not.toHaveBeenCalledWith(
14381429
expect.stringContaining('looks like you meant the branch name'),
14391430
)

0 commit comments

Comments
 (0)