Static analysis for Frontend codebases. Detect patterns, measure complexity, and catch anti-patterns across 11 state management libraries.
npm install -g state-analyzer
Starting state analysis... === Analysis Summary === Total components: 68 Components with state: 12 (17.6%) Total state usage: 20 Average: 1.7 states/component Custom hooks: 30 Usage by type: useState: 16 Zustand: 4 === Complexity === Project grade: A (score: 1.1) Component grades: A ████████████████████ (64) B ██ (2) C ██ (2) === Suggestions === ! ToastProvider (src/contexts/ToastContext.tsx) 4 state hooks detected — consider extracting to a custom hook
React hooks, Redux, Zustand, Jotai, MobX, Recoil, Valtio, TanStack Query, SWR — all detected automatically.
Detects custom hook definitions and traces what state management patterns they use internally.
A~F grade per component and project-wide. Use --threshold as a CI gate.
Warns about unused state, excessive hooks, library mixing, and useContext overuse.
Terminal, Markdown tables, Mermaid diagrams, and JSON export for CI pipelines.
Register custom state patterns for internal libraries via .stateanalyzerrc.json.
npm install -g state-analyzer
# or yarn global add state-analyzer
state-analyzer init
state-analyzer analyze ./src
state-analyzer analyze ./src --threshold C
state-analyzer analyze ./src --format md
state-analyzer analyze ./src --mermaid
state-analyzer diff before.json after.json
state-analyzer watch ./src
Create a .stateanalyzerrc.json in your project root:
{
"exclude": ["legacy/", "generated/"],
"threshold": "C",
"format": "default",
"plugins": [
{
"name": "legend-state",
"patterns": [{ "regex": "useObservable\\s*\\(", "type": "legend-state" }],
"label": "Legend State"
}
]
}
exclude
File path patterns to skip during analysis
threshold
Default complexity threshold grade
format
Default output format (default, md)
plugins
Custom state patterns for internal/third-party libraries
{
"summary": {
"totalComponents": 68,
"totalStateUsages": 20,
"byType": { "useState": 16, "zustand": 4 },
"complexity": { "averageScore": 1.1, "grade": "A" }
},
"components": [ ... ],
"customHooks": [ ... ],
"suggestions": [ ... ]
}