## Static Defect Detection

> Static defects are issues that can be found through code structure analysis without relying on runtime, simulating the behavior of a compiler/type checker.
> This file is the detection routing table -- it locates the detection subtask subfiles to load based on code characteristics.

### Detection Routing Table

| Trigger Signals (Code Characteristics) | Detection Subtask Triggered | File |
|---------------------|-----------|------|
| Mismatched brackets/braces/parentheses, missing semicolons, keyword typos | Syntax & Dependencies | [syntax-and-deps.md](syntax-and-deps.md) |
| Module path referenced by `import`/`require`/`#include` does not exist | Syntax & Dependencies | [syntax-and-deps.md](syntax-and-deps.md) |
| Imported symbol not used in current file (`import X` but no `X` reference) | Symbol Resolution | [symbol-resolution.md](symbol-resolution.md) |
| Variable declared but not used (`const x = 1` with no subsequent reference) | Symbol Resolution | [symbol-resolution.md](symbol-resolution.md) |
| Inner variable shadows outer variable with same name (`let x = 1; { let x = 2 }`) | Symbol Resolution | [symbol-resolution.md](symbol-resolution.md) |
| Variable/function/class used before definition | Symbol Resolution | [symbol-resolution.md](symbol-resolution.md) |
| Function call argument count/type mismatch with definition | Type Matching | [type-matching.md](type-matching.md) |
| Variable assignment type inconsistent with declared type | Type Matching | [type-matching.md](type-matching.md) |
| Interface implementation signature inconsistent with interface definition | Type Matching | [type-matching.md](type-matching.md) |
| Code after `return`/`throw`/`break` (unreachable) | Dead Code | [dead-code.md](dead-code.md) |
| Always true/false conditions (`if (true)`, `if (1)`) | Dead Code | [dead-code.md](dead-code.md) |
| Exported function/class not referenced by any file | Dead Code | [dead-code.md](dead-code.md) |
| `switch` branch without `break`/`return` and no `// fallthrough` comment | Dead Code | [dead-code.md](dead-code.md) |
| `import A` where A also `import`s the current file (circular reference) | Circular Dependencies | [circular-deps.md](circular-deps.md) |
| Dependency chain A→B→C→A exists between modules | Circular Dependencies | [circular-deps.md](circular-deps.md) |

### Usage

1. Read the changed code and identify the trigger signals above
2. Based on matched trigger signals, **only load** the corresponding subfiles (no need to load everything)
3. No matched trigger signals → do not execute static defect detection
4. Prefer LSP tools (`find_definition`, `find_references`) for precise analysis; fall back to Grep + Read when LSP is unavailable

### General Exclusion Rules

The following situations are not reported as defects:
- **Test files**: `*.test.*`, `*.spec.*`, `__tests__/` directories
- **Generated code**: `generated/`, `*.generated.*`, `node_modules/`, vendor
- **Third-party dependencies**: only code within the current project is visible; third-party dependencies that need to be installed are not visible. Imports, types, and symbols involving third-party dependencies are not reported
- **Type declaration files**: `*.d.ts`, `*.pyi` (declarations only without implementation, some detection items do not apply)
- **Issues already detected by compiler/IDE**: TypeScript compilation errors, Python mypy errors (duplicate reporting has no value)
