Skip to content

Commit b99c778

Browse files
shulaodafengmk2
andauthored
refactor(cli): remove unused exported helpers (#2046)
### Problem Six exported helpers in `packages/cli/src/utils` are dead — each a thin singular/prefix wrapper delegating to a plural/kept counterpart: | file | symbol | status | | --- | --- | --- | | `utils/editor.ts` | `detectExistingEditor` | zero references (plural `detectExistingEditors` is used) | | `utils/agent.ts` | `resolveAgentTargetPath` | zero references (plural `resolveAgentTargetPaths`) | | `utils/agent.ts` | `selectAgentTargetPath` | zero references (plural `selectAgentTargetPaths`) | | `utils/agent.ts` | `detectExistingAgentTargetPath` | **test-only** — referenced only by its own spec | | `utils/terminal.ts` | `infoMsg` | zero references (only `warnMsg`/`errorMsg` are used) | | `utils/terminal.ts` | `noteMsg` | zero references | **Why they are safe to delete (not just unreferenced):** `src/utils` is not a public API surface — `package.json#exports` has no `./utils/*` entry, and the public `.` entry (`index.ts`) only does `export * from '@voidzero-dev/vite-plus-core'`. So these are internal-only. ### Fix - Delete the six functions. - `detectExistingAgentTargetPath` was exercised only by its own `describe` block; its two singular assertions are migrated to the plural `detectExistingAgentTargetPaths` (identical behaviour — the singular was just `detectExistingAgentTargetPaths(...)?.[0]`): a one-file case now asserts `['CLAUDE.md']`, and the symlink case still asserts `undefined` (the plural returns `undefined` when nothing non-symlink is found). - `rfcs/init-editor-configs.md` mentioned `selectAgentTargetPath` / `detectExistingAgentTargetPath` in its design-analogy table; that table now references the surviving plural functions (`selectAgentTargetPaths` / `detectExistingAgentTargetPaths`, mirrored by `selectEditors` / `detectExistingEditors`) so the doc stays accurate. - `terminal.ts`'s `info`/`note` half of the "info/note/warn/error" set is gone, so the section comment is trimmed to the remaining `warn`/`error`. ### Verification ```bash # no code references remain to any removed symbol (excluding the plural forms we keep) for s in detectExistingEditor resolveAgentTargetPath selectAgentTargetPath \ detectExistingAgentTargetPath infoMsg noteMsg; do grep -rn "${s}\b" packages | grep -vE 'node_modules|/dist/' | grep -vE "${s}s\b" done # → no output pnpm exec oxlint packages/cli/src/utils/{editor,agent,terminal}.ts \ packages/cli/src/utils/__tests__/agent.spec.ts # clean ``` The migrated `detectExistingAgentTargetPaths` assertions match the function's actual returns (`['CLAUDE.md']` for one file; `undefined` for a symlink-only dir). Kept functions (`detectExistingEditors`, `resolveAgentTargetPaths`, `selectAgentTargetPaths`, `detectExistingAgentTargetPaths`, `warnMsg`, `errorMsg`) are untouched. Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 01360d3 commit b99c778

5 files changed

Lines changed: 10 additions & 46 deletions

File tree

packages/cli/src/utils/__tests__/agent.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
88
import {
99
COPILOT_SETUP_WORKFLOW_PATH,
1010
detectExistingAgentTargetPaths,
11-
detectExistingAgentTargetPath,
1211
hasExistingAgentInstructions,
1312
replaceMarkedAgentInstructionsSection,
1413
resolveAgentOptions,
@@ -376,7 +375,7 @@ describe('selectAgentTargetPaths', () => {
376375
});
377376
});
378377

379-
describe('detectExistingAgentTargetPath', () => {
378+
describe('detectExistingAgentTargetPaths', () => {
380379
it('detects all existing regular agent files', async () => {
381380
const dir = await createProjectDir();
382381
await mockFs.writeFile(path.join(dir, 'AGENTS.md'), '# Agents');
@@ -389,14 +388,14 @@ describe('detectExistingAgentTargetPath', () => {
389388
const dir = await createProjectDir();
390389
await mockFs.writeFile(path.join(dir, 'CLAUDE.md'), '# Claude');
391390

392-
expect(detectExistingAgentTargetPath(dir)).toBe('CLAUDE.md');
391+
expect(detectExistingAgentTargetPaths(dir)).toEqual(['CLAUDE.md']);
393392
});
394393

395394
it('ignores symlinked agent files', async () => {
396395
const dir = await createProjectDir();
397396
await mockFs.symlink('AGENTS.md', path.join(dir, 'CLAUDE.md'));
398397

399-
expect(detectExistingAgentTargetPath(dir)).toBeUndefined();
398+
expect(detectExistingAgentTargetPaths(dir)).toBeUndefined();
400399
});
401400
});
402401

packages/cli/src/utils/agent.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,6 @@ export async function selectAgentTargetPaths({
174174
return selection.targetPaths;
175175
}
176176

177-
export async function selectAgentTargetPath({
178-
interactive,
179-
agent,
180-
onCancel,
181-
}: {
182-
interactive: boolean;
183-
agent?: AgentSelection;
184-
onCancel: () => void;
185-
}) {
186-
const targetPaths = await selectAgentTargetPaths({ interactive, agent, onCancel });
187-
return targetPaths?.[0];
188-
}
189-
190177
export function detectExistingAgentTargetPaths(projectRoot: string) {
191178
const detectedPaths: string[] = [];
192179
const seenTargetPaths = new Set<string>();
@@ -203,10 +190,6 @@ export function detectExistingAgentTargetPaths(projectRoot: string) {
203190
return detectedPaths.length > 0 ? detectedPaths : undefined;
204191
}
205192

206-
export function detectExistingAgentTargetPath(projectRoot: string) {
207-
return detectExistingAgentTargetPaths(projectRoot)?.[0];
208-
}
209-
210193
export function hasExistingAgentInstructions(projectRoot: string): boolean {
211194
const targetPaths = detectExistingAgentTargetPaths(projectRoot);
212195
if (!targetPaths) {
@@ -259,10 +242,6 @@ export function resolveAgentTargetPaths(agent?: string | string[]) {
259242
return getAgentTargetPaths(resolveAgentOptions(agent));
260243
}
261244

262-
export function resolveAgentTargetPath(agent?: string) {
263-
return resolveAgentTargetPaths(agent)[0] ?? 'AGENTS.md';
264-
}
265-
266245
export function resolveAgentOptions(agent?: string | string[]) {
267246
const agentNames = parseAgentNames(agent);
268247
const resolvedAgentNames = agentNames.length > 0 ? agentNames : [AGENT_DEFAULT_ID];

packages/cli/src/utils/editor.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,6 @@ export async function selectEditors({
273273
return undefined;
274274
}
275275

276-
export function detectExistingEditor(projectRoot: string): EditorId | undefined {
277-
return detectExistingEditors(projectRoot)?.[0];
278-
}
279-
280276
export function detectExistingEditors(projectRoot: string): EditorId[] | undefined {
281277
const editors: EditorId[] = [];
282278
for (const option of EDITORS) {

packages/cli/src/utils/terminal.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ export function error(text: string) {
3737
}
3838

3939
// Standard message prefix functions matching the Rust CLI convention.
40-
// info/note go to stdout (normal output), warn/error go to stderr (diagnostics).
41-
42-
export function infoMsg(msg: string) {
43-
/* oxlint-disable-next-line no-console */
44-
console.log(styleText(['blue', 'bold'], 'info:'), msg);
45-
}
40+
// warn/error go to stderr (diagnostics).
4641

4742
export function warnMsg(msg: string) {
4843
/* oxlint-disable-next-line no-console */
@@ -53,8 +48,3 @@ export function errorMsg(msg: string) {
5348
/* oxlint-disable-next-line no-console */
5449
console.error(styleText(['red', 'bold'], 'error:'), msg);
5550
}
56-
57-
export function noteMsg(msg: string) {
58-
/* oxlint-disable-next-line no-console */
59-
console.log(styleText(['gray', 'bold'], 'note:'), msg);
60-
}

rfcs/init-editor-configs.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ When a config file already exists:
8181

8282
Mirrors `packages/cli/src/utils/agent.ts` structure:
8383

84-
| agent.ts | editor.ts |
85-
| --------------------------------- | ------------------------ |
86-
| `AGENTS` array | `EDITORS` array |
87-
| `selectAgentTargetPath()` | `selectEditor()` |
88-
| `detectExistingAgentTargetPath()` | `detectExistingEditor()` |
89-
| `writeAgentInstructions()` | `writeEditorConfigs()` |
84+
| agent.ts | editor.ts |
85+
| ---------------------------------- | ------------------------- |
86+
| `AGENTS` array | `EDITORS` array |
87+
| `selectAgentTargetPaths()` | `selectEditors()` |
88+
| `detectExistingAgentTargetPaths()` | `detectExistingEditors()` |
89+
| `writeAgentInstructions()` | `writeEditorConfigs()` |
9090

9191
Key difference from agent.ts: Uses JSON merge (via `utils/json.ts`) instead of file copy/append, since IDE configs are structured JSON.
9292

0 commit comments

Comments
 (0)