Ensure code quality using Luacheck linting and StyLua formatting. Covers common warnings, style rules, and auto-formatting...
Expert guidance for code quality and formatting in WoW addon development.
| Task | MCP Tool |
|---|---|
| Lint Addon | addon.lint(addon="MyAddon") |
| Format Addon | addon.format(addon="MyAddon") |
| Check Format Only | addon.format(addon="MyAddon", check=true) |
| Security Analysis | addon.security(addon="MyAddon") |
| Complexity Analysis | addon.complexity(addon="MyAddon") |
addon.deadcode (see s-clean)| Code | Meaning | Fix |
|---|---|---|
| W111 | Setting undefined global | Add to .luacheckrc globals or fix typo |
| W112 | Mutating undefined global | Same as W111 |
| W113 | Accessing undefined global | Check if API exists, add to read_globals |
| W211 | Unused local variable | Remove or prefix with _ |
| W212 | Unused argument | Prefix with _ (e.g., _event) |
| W213 | Unused loop variable | Prefix with _ |
| W311 | Value assigned but never used | Remove assignment or use the value |
| W431 | Shadowing upvalue | Rename the local variable |
Standard WoW addon configuration:
std = "lua51"
max_line_length = false
globals = {
-- Addon globals
"MyAddon",
}
read_globals = {
-- WoW API
"C_Timer", "C_Spell", "CreateFrame",
-- Ace3
"LibStub",
}
Standard .stylua.toml:
column_width = 120
line_endings = "Unix"
indent_type = "Tabs"
indent_width = 4
quote_style = "AutoPreferDouble"
call_parentheses = "Always"
# Check for issues
addon.lint(addon="MyAddon")
# Auto-format
addon.format(addon="MyAddon")
# Verify clean
addon.lint(addon="MyAddon")
.luacheckrc_ prefix for intentionally unused variablesBeyond syntax linting, use addon.security to detect runtime safety issues:
| Category | Description |
|---|---|
combat_violation |
Protected API calls without InCombatLockdown() guard |
secret_leak |
Logging/printing secret values (12.0+) |
taint_risk |
Unsafe global modifications (_G without namespace) |
unsafe_eval |
loadstring/RunScript with unsanitized input |
Use addon.complexity to identify maintainability issues:
| Category | Threshold | Description |
|---|---|---|
deep_nesting |
> 5 levels | Excessive if/for/while nesting |
long_function |
> 100 lines | Functions that should be split |
long_file |
> 500 lines | Files that need restructuring |
magic_number |
pattern-based | Unexplained numeric literals |
For comprehensive analysis, use c-audit.