style: 完成所有文件的lint

This commit is contained in:
claude-code-best
2026-05-01 21:39:30 +08:00
parent d136872cc9
commit 6182015005
1333 changed files with 68255 additions and 77882 deletions

View File

@@ -1,86 +1,74 @@
import { mkdir, writeFile } from 'fs/promises'
import * as React from 'react'
import type { CommandResultDisplay } from '../../commands.js'
import { Dialog } from '@anthropic/ink'
import { MemoryFileSelector } from '../../components/memory/MemoryFileSelector.js'
import { getRelativeMemoryPath } from '../../components/memory/MemoryUpdateNotification.js'
import { Box, Link, Text } from '@anthropic/ink'
import type { LocalJSXCommandCall } from '../../types/command.js'
import { clearMemoryFileCaches, getMemoryFiles } from '../../utils/claudemd.js'
import { getClaudeConfigHomeDir } from '../../utils/envUtils.js'
import { getErrnoCode } from '../../utils/errors.js'
import { logError } from '../../utils/log.js'
import { editFileInEditor } from '../../utils/promptEditor.js'
import { mkdir, writeFile } from 'fs/promises';
import * as React from 'react';
import type { CommandResultDisplay } from '../../commands.js';
import { Dialog } from '@anthropic/ink';
import { MemoryFileSelector } from '../../components/memory/MemoryFileSelector.js';
import { getRelativeMemoryPath } from '../../components/memory/MemoryUpdateNotification.js';
import { Box, Link, Text } from '@anthropic/ink';
import type { LocalJSXCommandCall } from '../../types/command.js';
import { clearMemoryFileCaches, getMemoryFiles } from '../../utils/claudemd.js';
import { getClaudeConfigHomeDir } from '../../utils/envUtils.js';
import { getErrnoCode } from '../../utils/errors.js';
import { logError } from '../../utils/log.js';
import { editFileInEditor } from '../../utils/promptEditor.js';
function MemoryCommand({
onDone,
}: {
onDone: (
result?: string,
options?: { display?: CommandResultDisplay },
) => void
onDone: (result?: string, options?: { display?: CommandResultDisplay }) => void;
}): React.ReactNode {
const handleSelectMemoryFile = async (memoryPath: string) => {
try {
// Create claude directory if it doesn't exist (idempotent with recursive)
if (memoryPath.includes(getClaudeConfigHomeDir())) {
await mkdir(getClaudeConfigHomeDir(), { recursive: true })
await mkdir(getClaudeConfigHomeDir(), { recursive: true });
}
// Create file if it doesn't exist (wx flag fails if file exists,
// which we catch to preserve existing content)
try {
await writeFile(memoryPath, '', { encoding: 'utf8', flag: 'wx' })
await writeFile(memoryPath, '', { encoding: 'utf8', flag: 'wx' });
} catch (e: unknown) {
if (getErrnoCode(e) !== 'EEXIST') {
throw e
throw e;
}
}
await editFileInEditor(memoryPath)
await editFileInEditor(memoryPath);
// Determine which environment variable controls the editor
let editorSource = 'default'
let editorValue = ''
let editorSource = 'default';
let editorValue = '';
if (process.env.VISUAL) {
editorSource = '$VISUAL'
editorValue = process.env.VISUAL
editorSource = '$VISUAL';
editorValue = process.env.VISUAL;
} else if (process.env.EDITOR) {
editorSource = '$EDITOR'
editorValue = process.env.EDITOR
editorSource = '$EDITOR';
editorValue = process.env.EDITOR;
}
const editorInfo =
editorSource !== 'default'
? `Using ${editorSource}="${editorValue}".`
: ''
const editorInfo = editorSource !== 'default' ? `Using ${editorSource}="${editorValue}".` : '';
const editorHint = editorInfo
? `> ${editorInfo} To change editor, set $EDITOR or $VISUAL environment variable.`
: `> To use a different editor, set the $EDITOR or $VISUAL environment variable.`
: `> To use a different editor, set the $EDITOR or $VISUAL environment variable.`;
onDone(
`Opened memory file at ${getRelativeMemoryPath(memoryPath)}\n\n${editorHint}`,
{ display: 'system' },
)
onDone(`Opened memory file at ${getRelativeMemoryPath(memoryPath)}\n\n${editorHint}`, { display: 'system' });
} catch (error) {
logError(error)
onDone(`Error opening memory file: ${error}`)
logError(error);
onDone(`Error opening memory file: ${error}`);
}
}
};
const handleCancel = () => {
onDone('Cancelled memory editing', { display: 'system' })
}
onDone('Cancelled memory editing', { display: 'system' });
};
return (
<Dialog title="Memory" onCancel={handleCancel} color="remember">
<Box flexDirection="column">
<React.Suspense fallback={null}>
<MemoryFileSelector
onSelect={handleSelectMemoryFile}
onCancel={handleCancel}
/>
<MemoryFileSelector onSelect={handleSelectMemoryFile} onCancel={handleCancel} />
</React.Suspense>
<Box marginTop={1}>
@@ -90,13 +78,13 @@ function MemoryCommand({
</Box>
</Box>
</Dialog>
)
);
}
export const call: LocalJSXCommandCall = async onDone => {
// Clear + prime before rendering — Suspense handles the unprimed case,
// but awaiting here avoids a fallback flash on initial open.
clearMemoryFileCaches()
await getMemoryFiles()
return <MemoryCommand onDone={onDone} />
}
clearMemoryFileCaches();
await getMemoryFiles();
return <MemoryCommand onDone={onDone} />;
};