Simplify Plugin Code
Review a Tinker plugin's source code for redundant, dead, or duplicated code, then fix all issues found.
Arguments
plugin-name-or-file-path: plugin folder name (e.g. tinker-hash) or one or more specific file paths
Checklist
Read all target files and check for the following categories of redundancy:
1. Unused Exports
- Constants, functions, types, or interfaces that are exported but never imported anywhere in the plugin
- Variables declared but never read
2. Dead Code
- Unreachable code after
return, throw, or break
- Branches or
switch cases that can never execute given the existing logic (e.g. a handler registered before a special-case check that already covers the same path)
- Code guarded by a condition that is always
true or always false
3. Duplicate Logic
- Functions with identical or near-identical bodies that could be merged into one
- The same expression or block repeated in two or more places that could be extracted into a shared helper or hook
4. Duplicate Type Definitions
- Interfaces or types with identical shapes defined more than once
- Type aliases that simply re-export another type without adding meaning
5. Repeated Inline Patterns
- Identical JSX subtrees copy-pasted across components
- Identical event handler logic inline in multiple components
6. Unreferenced Files
- Source files (
.ts, .tsx) under src/ that are never imported by any other file in the plugin
- A file is unreferenced if no other
.ts/.tsx file in the plugin contains an import statement pointing to it
- Entry points (
main.tsx, index.ts) and type-only files (types.ts) are exempt from this check
7. Unused i18n Keys
- Keys defined in
src/i18n/*.json that are never referenced via t('key') anywhere in the plugin's .ts/.tsx files
- Check both locale files (
en-US.json and zh-CN.json) — a key is unused only if it is absent from all t() calls across the entire plugin source
Output Format
For each issue found, output:
[Category] file/path:line — description
Example:
[Unused] src/lib/constants.ts:40 — SUPPORTED_EXTENSIONS is exported but never imported
[Dead Code] src/lib/ffmpegArgs.ts:22 — case 'gif' in getVideoCodecArgs is unreachable; caller handles gif before invoking this function
[Duplicate Logic] src/components/MediaList.tsx:50,158 — handleContextMenu is identical in ImageCard and MediaRow; extract to a shared hook
[Duplicate Type] src/components/MediaList.tsx:43,151 — MediaItemProps and MediaRowProps are identical; remove one
[Unreferenced] src/components/EditProviderDialog.tsx — file is never imported by any other file in the plugin; delete it
[i18n] src/i18n/en-US.json:12 — key "outputDir" is defined but never used via t()
If no issues are found, report: No redundancies found.
Steps
- Identify the target:
- If a plugin name is given, glob all
.ts, .tsx, and .json files under <plugin-name>/src/
- If file paths are given, read those files; also read the i18n locale files for i18n key checks
- Read all target files thoroughly.
- Cross-reference exports against imports across all files in the plugin to detect unused exports.
- Cross-reference every
.ts/.tsx file under src/ against all import statements in the plugin — any file not imported by any other file (excluding entry points and types.ts) is unreferenced and should be deleted.
- For i18n keys: collect every key from both locale JSON files, then grep all
.ts/.tsx files for t('key') calls. Any key not found in any call is unused.
- Apply each checklist item and collect all findings.
- Report all findings grouped by category with file path and line number.
- Fix every issue found by editing or deleting the relevant files. Do not skip any issue.
- After fixing, verify there are no TypeScript errors by checking IDE diagnostics or re-reading the changed files.
1---2name: simplify3description: Review changed code for reuse, quality, and efficiency, then fix any issues found.4---56# Simplify Plugin Code78Review a Tinker plugin's source code for redundant, dead, or duplicated code, then fix all issues found.910## Arguments1112- `plugin-name-or-file-path`: plugin folder name (e.g. `tinker-hash`) or one or more specific file paths1314## Checklist1516Read all target files and check for the following categories of redundancy:1718### 1. Unused Exports1920- Constants, functions, types, or interfaces that are exported but never imported anywhere in the plugin21- Variables declared but never read2223### 2. Dead Code2425- Unreachable code after `return`, `throw`, or `break`26- Branches or `switch` cases that can never execute given the existing logic (e.g. a handler registered before a special-case check that already covers the same path)27- Code guarded by a condition that is always `true` or always `false`2829### 3. Duplicate Logic3031- Functions with identical or near-identical bodies that could be merged into one32- The same expression or block repeated in two or more places that could be extracted into a shared helper or hook3334### 4. Duplicate Type Definitions3536- Interfaces or types with identical shapes defined more than once37- Type aliases that simply re-export another type without adding meaning3839### 5. Repeated Inline Patterns4041- Identical JSX subtrees copy-pasted across components42- Identical event handler logic inline in multiple components4344### 6. Unreferenced Files4546- Source files (`.ts`, `.tsx`) under `src/` that are never imported by any other file in the plugin47- A file is unreferenced if no other `.ts`/`.tsx` file in the plugin contains an `import` statement pointing to it48- Entry points (`main.tsx`, `index.ts`) and type-only files (`types.ts`) are exempt from this check4950### 7. Unused i18n Keys5152- Keys defined in `src/i18n/*.json` that are never referenced via `t('key')` anywhere in the plugin's `.ts`/`.tsx` files53- Check both locale files (`en-US.json` and `zh-CN.json`) — a key is unused only if it is absent from **all** `t()` calls across the entire plugin source5455## Output Format5657For each issue found, output:5859```60[Category] file/path:line — description61```6263Example:64```65[Unused] src/lib/constants.ts:40 — SUPPORTED_EXTENSIONS is exported but never imported66[Dead Code] src/lib/ffmpegArgs.ts:22 — case 'gif' in getVideoCodecArgs is unreachable; caller handles gif before invoking this function67[Duplicate Logic] src/components/MediaList.tsx:50,158 — handleContextMenu is identical in ImageCard and MediaRow; extract to a shared hook68[Duplicate Type] src/components/MediaList.tsx:43,151 — MediaItemProps and MediaRowProps are identical; remove one69[Unreferenced] src/components/EditProviderDialog.tsx — file is never imported by any other file in the plugin; delete it70[i18n] src/i18n/en-US.json:12 — key "outputDir" is defined but never used via t()71```7273If no issues are found, report: **No redundancies found.**7475## Steps76771. Identify the target:78 - If a plugin name is given, glob all `.ts`, `.tsx`, and `.json` files under `<plugin-name>/src/`79 - If file paths are given, read those files; also read the i18n locale files for i18n key checks802. Read all target files thoroughly.813. Cross-reference exports against imports across all files in the plugin to detect unused exports.824. Cross-reference every `.ts`/`.tsx` file under `src/` against all `import` statements in the plugin — any file not imported by any other file (excluding entry points and `types.ts`) is unreferenced and should be deleted.835. For i18n keys: collect every key from both locale JSON files, then grep all `.ts`/`.tsx` files for `t('key')` calls. Any key not found in any call is unused.846. Apply each checklist item and collect all findings.857. Report all findings grouped by category with file path and line number.868. Fix every issue found by editing or deleting the relevant files. Do not skip any issue.879. After fixing, verify there are no TypeScript errors by checking IDE diagnostics or re-reading the changed files.