About code-quality
A code-quality skill for Rust development, focused on correctness, explicit error handling, and avoiding unnecessary complexity. It is aimed at contributors working on production database code.
Key features
- 01Assert invariants and handle errors
- 02Represent invalid states with types
- 03Use exhaustive pattern matching
- 04Avoid unnecessary abstractions and comments
- 05Check index mutation ordering
Use cases
- 01Reviewing Rust changes for silent failure paths
- 02Maintaining database integrity during index updates
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ tursodatabase/ turso --skill code-qualityAfter installing, type/code-qualityin Claude Code to confirm it loaded.
Details
From the project READMECode Quality Guide
Core Principle
Production database. Correctness paramount. Crash > corrupt.
Correctness Rules
- No workarounds or quick hacks. Handle all errors, check invariants
- Assert often. Never silently fail or swallow edge cases
- Crash on invalid state if it risks data integrity. Don't continue in undefined state
- Consider edge cases. On long enough timeline, all possible bugs will happen
Rust Patterns
- Make illegal states unrepresentable
- Exhaustive pattern matching
- Prefer enums over strings/sentinels
- Minimize heap allocations
- Write CPU-friendly code (microsecond = long time)
If-Statements
Wrong:
if condition {
// happy path
} else {
// "shouldn't happen" - silently ignored
}
Right:
// If only one branch should ever be hit:
assert!(condition, "invariant violated: ...");
// OR
return Err(LimboError::InternalError("unexpected state".into()));
// OR
unreachable!("impossible state: ...");
Use if-statements only when both branches are expected paths.
Comments
- Don't add code comments, except for rust
SAFETYcomments.
Avoid Over-Engineering
- Only changes directly requested or clearly necessary
- Don't add features beyond what's asked
- Don't add docstrings/comments to unchanged code
- Don't add error handling for impossible scenarios
- Don't create abstractions for one-time operations
- Three similar lines > premature abstraction
Index Mutations
When code involves index inserts, deletes, or conflict resolution, double-check the ordering against SQLite. Wrong ordering causes index inconsistencies. and easy to miss.
Ensure understanding of IO model
Cleanup
- Delete unused code completely
- No backwards-compat hacks (renamed
_vars, re-exports,// removedcomments)
Single-use helpers
If a helper function has no meaning outside of a single use case, move it inside the function that uses it:
fn do_something() {
something_specific();
fn something_specific() {
}
}
Comments
Markdown supported