一键导入
code-quality
Use when refactoring for duplication, complexity, or dead code — includes the plugin's on-demand analysis scripts.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Use when refactoring for duplication, complexity, or dead code — includes the plugin's on-demand analysis scripts.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | code-quality |
| description | Use when refactoring for duplication, complexity, or dead code — includes the plugin's on-demand analysis scripts. |
| file_patterns | ["**/*.ex","**/*.heex"] |
| auto_suggest | true |
Automated detection of code quality issues in Elixir projects. These checks run automatically via hooks when files are written, and can be run on-demand for full project analysis.
run_analysis.sh to establish a baseline before and afterDetects when the same function appears in multiple modules with >70% body similarity.
How it works: AST-based analysis parses function bodies and compares them using trigram similarity. Functions with the same name, arity, and similar bodies are flagged.
Example output:
Duplication Detected
Function `format_time/1` (85% similar)
lib/app_web/live/cycle_time.ex:45
lib/app_web/live/lead_time.ex:52
Suggestion: Extract to a shared module
How to fix:
# Create: lib/app_web/live/helpers.ex
defmodule AppWeb.Live.Helpers do
def format_time(%Decimal{} = seconds) do
seconds |> Decimal.to_float() |> format_time()
end
def format_time(seconds) when is_number(seconds) do
# shared formatting logic
end
end
# In each LiveView:
import AppWeb.Live.Helpers, only: [format_time: 1]
Measures function complexity using the ABC metric (Assignments, Branches, Conditions).
= operatorscase, cond, if, unless, with, -> clauses&&, ||, and, or, ==, !=, >, <, >=, <=, when guardsABC = sqrt(A² + B² + C²) — threshold is 30.
Example output:
High Complexity Detected
Function `calculate_trend_line/1` — ABC complexity 41 (threshold: 30)
lib/app_web/live/helpers.ex:45
Suggestion: Break into smaller functions with single responsibilities
How to fix:
# Before: one large function (complexity 41)
def calculate_trend_line(data) do
# 50 lines of assignments, branches, conditions
end
# After: composed smaller functions (complexity <20 each)
def calculate_trend_line(data) do
sums = calculate_regression_sums(data)
slope = calculate_slope(sums)
intercept = calculate_intercept(sums, slope)
build_trend_points(data, slope, intercept)
end
Detects defp functions that are defined but never called within the module.
Example output:
Unused Private Functions
`old_format_date` defined at line 123 but never called
Suggestion: Remove if no longer needed
Common after refactoring — when you extract code to a shared module, the original private functions may become dead code.
Detects when HEEx templates in the same directory share >40% identical markup.
Example output:
Template Duplication Detected
86 identical lines (72%) between:
cycle_time.html.heex
lead_time.html.heex
Suggestion: Extract shared markup to a function component
How to fix:
# Create a function component for the shared markup
defmodule AppWeb.Live.Components do
use Phoenix.Component
def metric_filters(assigns) do
~H"""
<div class="filters">
<!-- shared filter markup -->
</div>
"""
end
end
Code quality checks run automatically when files are written or edited:
.ex/.exs files trigger duplication, complexity, and unused function checks.heex files trigger template duplication checksRun a complete analysis from a checkout of this repo:
bash scripts/run_analysis.sh
Or target specific checks:
# Single file analysis
elixir scripts/code_quality.exs all lib/app_web/live/my_live.ex
# Specific check
elixir scripts/code_quality.exs complexity lib/app_web/live/my_live.ex
elixir scripts/code_quality.exs duplication lib/app_web/live/my_live.ex
elixir scripts/code_quality.exs unused lib/app_web/live/my_live.ex
# Scan entire lib/ directory
elixir scripts/code_quality.exs scan lib/
When installed as a plugin, the scripts live inside the plugin install directory rather than at a fixed path in the project — run the commands above from a checkout of this repo instead.
For testing guidance, see testing-essentials. When writing tests for refactored shared modules, ensure:
Use when a form or operation manages parent and child records together — cast_assoc/cast_embed, on_replace, Ecto.Multi across tables, FK cascade design.
Use when writing GenServer, Supervisor, Task, Agent, or Registry code — init/handle_continue, call vs cast, supervision strategies, process naming.
Use when defining schemas, writing queries, or creating migrations — schema design, Repo usage, indexes, query composition.
Use when writing or refactoring core Elixir — pattern matching, case/cond/with, pipes, {:ok, _}/{:error, _} contracts. Baseline style for any .ex/.exs change not covered by a more specific skill.
Use when writing LiveView modules or HEEx templates — mount/handle_params lifecycle, assigns, streams, events, components.
Use when adding logging, metrics, or instrumentation — structured Logger usage, telemetry handler attachment, Ecto/Phoenix telemetry events.