跳到正文
cccskills
免费在 GitHub 公开中文介绍

duplicate-and-dead-code

查找可能承担相同职责的现有代码,并列出疑似未使用的声明和图片资源。可在规划变更前核对已有实现,也可在评审时检查重复候选,辅助判断是否删除。

原文查看原文说明

Find semantic copies and dead code before a plan or a review.

JetBrains/intellij-community星标 20,684(GitHub 20,684 + cccskills 0)

实测评分 未实测

查看安装方法

适用场景

  • 实现前查找已有负责代码
  • 评审变更中的语义重复候选
  • 检查疑似未使用的代码或图片

中文介绍

功能

在规划变更前,此技能会查找可能已经承担拟新增工作的代码。它根据行为和任务内容搜索可能的代码负责人,并沿着调用关系和引用继续检查。评审时,它会运行复制检查,找出语法或含义相似的函数,并从报告中筛选出与变更文件相关的候选项。它还可以列出疑似未使用的声明和图片,并说明删除前的确认步骤。

适用场景

如果您想避免在不同位置重复实现同一职责、在评审变更时检查重复候选,或调查疑似未使用的代码和图片,可以使用此技能。检测结果只是线索,并不能证明代码可以删除;请先阅读相关代码,再作判断。

使用示例

  • “请检查是否已有代码负责处理我计划新增的行为。”
  • “请检查已修改目录中的语义重复候选。”
  • “请查找这个范围内疑似未使用的代码。”

注意事项

此技能使用 accio 和 jscpd。如果 accio 不在 PATH 中,请使用 ./community/tools/accio.cmd;运行 jscpd 时须通过指定的包装脚本。首次进行语义分析需要一个 548 MB 的模型。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

文档检查

AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。

安全性发送数据、删除文件、执行命令等是否有说明
A良好资料要求先阅读候选项,并在删除前不限定范围再次搜索确认。
安装难易度所需工具和 API 密钥是否少且有说明
B部分不足资料列出 `accio`、`jscpd`、包装脚本和 548 MB 模型,但未写安装步骤。

不计入评分。 由 AI(OpenAI Codex)于 2026年10月29日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(1)

  • SKILL.md6.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

<!-- Generated by community/.ai/render-guides.mjs; edit community/.agents/skills/duplicate-and-dead-code/SKILL.md -->

Duplicate and dead code

The exact copy-paste gate finds a copied text only. This skill finds one responsibility in two pieces of different code, and dead code. Each tool gives candidates, not a proof. Read each candidate before you act on it.

The tools

ToolWhat it findsUse
jscpd exact, --exit-code 1a copied text (Type-1)the gate of an area
jscpd --ignore-identifiers --kind renameda copy with renamed names (Type-2)burn-down
jscpd --similarity 0.9 --kind asttwo functions with one syntax tree (Type-3)the copy lint
jscpd --semantic --kind semantictwo functions that do one thing (Type-4)the copy lint
jscpd --compare <a>/ <b>/the functions of <a> with no counterpart in <b>a port or two implementations
accio locate '<question>' --mode semantic, accio context '<task>'the code of a behaviour or a taskthe owner check
accio trace <Name> --direction callers, accio references <Name>the callers and every use of a namethe owner check, dead code
accio unused --scope <dir>/declarations, bundle keys and image variants used nowheredead code

Without accio on the PATH, run ./community/tools/accio.cmd. Run jscpd only through ./community/tools/jscpd.cmd -c <config>. <config> is the .jscpd.json of the area, for example plugins/air/.jscpd.json. An area without a .jscpd.json runs the commands without -c and has no exact gate. Write each JSON report to a temporary directory of your session. The jscpd_test target of the area runs the gate too, for example //plugins/air:air-duplicate-code_test.

Before a plan: the owner check

Do this for each responsibility that the plan adds: a mapping, a policy, a parser, a cache, a lifecycle step.

  1. accio locate '<a full question about the behaviour>' --mode semantic --scope <area>/. On a miss, ask again in other words.
  2. accio context '<the task in words>' --scope <area>/. Name the task by the nouns of the domain, not by a role word such as "mapper".
  3. accio references <ResultType> --scope <area>/ --no-tests --files. A private function that builds the type is an owner too.
  4. For a V1 or V2 change, find the other version: accio files '<Prefix>V1*', accio files '<Prefix>V2*'.
  5. accio trace <Name> --direction callers for each candidate, then read it. A call site marked ? (:57?) fits more than one overload: read it.

The plan then has an Existing owners line. It names each owner and the decision: extend it, move it, or write new code with the reason why the owner does not fit. When the check finds nothing, the line names the queries.

Before a review: the copy lint

The copy lint is a report, not a gate. Run it after the exact gate of the area passes, when the area has one. Give the touched directories and the directories of their owners: the scan compares only the files under the paths it gets.

./community/tools/jscpd.cmd -c <config> --similarity 0.9 --kind ast --absolute \
  --reporters json --output <temp-dir>/ast <touched-dir>...
./community/tools/jscpd.cmd -c <config> --semantic --semantic-scope same --kind semantic \
  --semantic-same-threshold 0.9 --ignore '**/testSrc/**,**/test/**,**/tests/**,**/testFramework/**' \
  --absolute --reporters json --output <temp-dir>/semantic <touched-dir>...

Then keep the pairs that touch a file of the change. Run this from the repository root:

{ git diff --name-only <base>; git ls-files --others --exclude-standard; } | sed "s|^|$PWD/|" \
  | jq -R . | jq -s . > <temp-dir>/changed.json
jq -r --slurpfile c <temp-dir>/changed.json '.duplicates[]
  | select(.firstFile.name as $a | .secondFile.name as $b | $c[0] | index($a) or index($b))
  | "\(.similarity) \(.firstFile.name):\(.firstFile.start)-\(.firstFile.end) ~ \(.secondFile.name):\(.secondFile.start)-\(.secondFile.end)"' \
  <temp-dir>/ast/jscpd-report.json <temp-dir>/semantic/jscpd-report.json

Filter the report by file, not by kind. An --kind ast pair has "kind": "similar".

  • Do not use --changed or --baseline-from-ref. Each makes a git worktree of the base revision with 1.4 million files.
  • The first --semantic run on a machine needs --semantic-download (a model of 548 MB). The first run on a directory takes minutes. A later run takes below 1 s.
  • Read each pair at 0.90 or more. Below 0.80, most pairs are two functions of one shape.
  • A pair in one file whose two parts are one line apart is a table, not a copy.
  • A pair that the change did not touch is a lead. Report it and do not fix it.
  • A pair that you keep needs a reason in the review: two sides that no shared module can hold, or a wire DTO and its model.

Dead code

accio unused --scope <dir>/ --limit 1000 gives the candidates. Each candidate is a lead. The note of the answer explains each mark, and accio unused --help says what the scan leaves out and cannot see.

  • A (generated) icon field: delete its SVG and generate the icon class again with the icon-resources skill. First search the SVG file name over the whole repository. A SKILL.md can name it as an icon, and then the fix is an icon-robots.txt skip.
  • A (published) candidate is a published API. Keep it unless its owner decides otherwise.
  • An area can keep a guide of the candidates that stay, for example plugins/air/docs/guides/dead-code-guide.md. Read it before the triage, and add each candidate that you keep.

To delete a candidate, prove it with accio locate '<name>' without --scope. Then delete it, the tests that test only it, the imports that only it needed, and the KDoc links to it. Delete a dead key from the English bundle only. The translations under localization/ belong to the localization team. Run the tests of the area, and run accio unused again.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

actions

免费有简介

实现或修改 IntelliJ `AnAction`,并在 `plugin.xml` 中注册。将显示名称和说明写入消息资源文件,按需设置图标,并通过事件协程作用域启动挂起任务,避免同步处理阻塞 IDE。

  • 为 IDE 菜单添加操作
  • 修改操作注册或图标
  • 整理操作名称和说明
JetBrains/intellij-community2.1万2026年10月29日 更新

bazel-test-migration

免费有简介

将 IntelliJ JPS 测试模块迁移到 Bazel,并排查仅在 Bazel 中出现的失败。根据症状检查依赖、插件、测试数据和 runfiles,重新生成并验证目标。

  • 将 JPS 测试模块迁移到 Bazel
  • 排查仅在 Bazel 中失败的测试
  • 检查测试依赖和数据配置
JetBrains/intellij-community2.1万2026年10月29日 更新

code-style

免费有简介

按 IntelliJ 项目规范编写或审查 Kotlin 和 Java 代码,涵盖语言选择、格式、密封类型、线程注解及控制流异常处理。

  • 按 IntelliJ 规范编写 Kotlin
  • 审查 Java 代码
  • 检查异常处理和密封类型分支
JetBrains/intellij-community2.1万2026年10月29日 更新

commits

免费有简介

本指南帮助您按 IntelliJ 项目规则拆分更改并撰写提交信息:有工单时使用编号和变更说明,无工单时使用标签与子系统名,并在需要时说明原因和决定。

  • 按项目格式编写带工单号的提交信息
  • 整理测试或文档提交并选择合适标签
  • 按规则修改已有提交信息
JetBrains/intellij-community2.1万2026年10月29日 更新

使用多个 Python 类型检查器比较代码片段或文件的类型推断和报错判断,并汇总各工具的结论、耗时与诊断信息,可保存为 Markdown 报告。

  • 比较不同检查器的类型推断
  • 确认代码是否会被判为类型错误
  • 查看多个工具的诊断差异
JetBrains/intellij-community2.1万2026年10月29日 更新

整理 Compose Desktop 界面中的状态和副作用,让可组合函数负责绘制,由展示器或协调器处理应用决策。了解状态归属、Effect、可复用组件接口、延迟列表键、动画和性能,适用于单项界面修改。

  • 分离界面绘制与展示器决策
  • 整理界面状态的归属
  • 检查 Effect 键和协程用法
JetBrains/intellij-community2.1万2026年10月29日 更新

查看 JetBrains 的全部技能

报告此技能的问题