Linting & Static Analysis
Ion brings Rust-like memory safety analysis to C++ without compromising speed.
Running a Check
To analyze the current project, simply run:
bash
ion checkFlags supported by the linter include:
--fix: Automatically apply suggestions where the linter is confident.--watch: Rerun the linter automatically when files change.--list-rules: Display all active rules.--rule <id>: Only run a specific rule check.
Output Formats
Ion can output diagnostic data in machine-readable formats for CI pipelines or editor integration.
bash
ion check --format json
ion check --format sarif > out.sarifEngines
Ion uses two engines for linting: a fast AST-based tree-sitter pass for stylistic rules, and a deeper libclang pass for type-aware memory flow analysis if libclang is available on your system.
Rule Catalogue
| Rule ID | Auto-fix | Description |
|---|---|---|
| memory/leak | Detects allocated heap memory not freed on all paths | |
| memory/use-after-free | Detects use of pointer after free() or delete | |
| memory/double-free | Detects freeing the same pointer twice | |
| modern/nullptr | Replace NULL/0 with nullptr | |
| modern/c-cast | Replace C-style cast with static_cast where safe | |
| memory/smart-get | Detects raw-pointer use via .get() on smart pointer | |
| memory/raw-from-smart | Detects passing unique_ptr::get() to owning functions | |
| memory/move-after-use | Detects use of moved-from object | |
| memory/shared-cycle-hint | Hints at potential shared_ptr reference cycles |