mirror of
https://github.com/alirezarezvani/claude-skills.git
synced 2026-09-07 08:26:02 +00:00
Adds 6 new language files to the code-reviewer skill, expanding coverage from 7 to 13 languages. Each file follows the established hybrid structure — language-specific rules inline, universal rules in rules/universal.md. Files added: - languages/c.md — memory safety, banned functions, pointer ownership, buffer bounds, UB - languages/cpp.md — smart pointers, RAII, reinterpret_cast, virtual destructors, C++17/20 - languages/rust.md — unsafe blocks, .unwrap() in production, Tokio pitfalls, clippy - languages/ruby.md — Rails-aware N+1, strong_parameters, YAML.safe_load, Marshal.load - languages/php.md — SQLi, unserialize, eval, file inclusion, CSRF, XSS, PHP 8.x - languages/dart.md — Dart + Flutter: dispose(), BuildContext across async, const widgets SKILL.md dispatch table and --language valid values updated accordingly.
4.5 KiB
4.5 KiB
| language | extensions | ||||||
|---|---|---|---|---|---|---|---|
| cpp |
|
C++ — Language-Specific Review Notes
Load this file alongside rules/universal.md. Universal rules are not repeated here — only C++-specific rules and idioms.
PR Analyzer — C++ Risk Signals
- Raw
new/deleteoutside of smart pointer wrappers reinterpret_cast— almost always a red flag; require justification- Disabled compiler warnings (
#pragma warning(disable:...),-w) // TODO/// FIXMEnear ownership or lifetime code- Hardcoded credentials or keys in source
- Use of deprecated C-style functions:
strcpy,sprintf,gets
Code Quality — C++ Checks
- Raw owning pointers (
T*) used whereunique_ptr/shared_ptrwould express ownership shared_ptroverused whereunique_ptrsuffices — implies shared ownership unnecessarilystd::endlused in hot paths — flushes the buffer every call; prefer'\n'- Implicit conversions between signed and unsigned integers
- Virtual destructor missing on base classes with virtual methods
catch (...)swallowing all exceptions without logging or re-throwing
Security
- Flag
reinterpret_caston user-controlled data — potential type confusion - Flag raw array indexing without bounds check — use
.at()or assert bounds - Flag
std::stringdata passed to C APIs without null-termination guarantee — use.c_str() - Flag hardcoded buffer sizes — derive from
sizeofor usestd::array<T, N> - Flag
sscanf/sprintf— usestd::istringstreamorstd::format(C++20) - Flag user-controlled data used as a format string
Async / Concurrency
- Flag
std::shared_ptraccessed from multiple threads — the pointer itself is not thread-safe for write; usestd::atomic<std::shared_ptr<T>>(C++20) or external locking - Flag
std::vector/std::mapmutated from multiple threads without a mutex - Flag
std::mutexlocked twice in the same thread withoutstd::recursive_mutex— deadlock - Flag detached threads (
std::thread::detach) with no lifetime coordination - Flag
volatileused instead ofstd::atomicfor inter-thread communication
Resource Management
- Flag raw
newreturning an owning pointer — wrap immediately instd::make_uniqueorstd::make_shared - Flag
deletecalled manually outside of a destructor or smart pointer — ownership confusion - Flag RAII violations — resources acquired in constructor but not released via destructor
- Flag
std::ifstream/std::ofstreamnot checked for open failure before use - Flag exceptions thrown from destructors — causes
std::terminateif thrown during stack unwinding
Exception Handling
- Flag
catch (...)that swallows exceptions without logging or re-throwing - Flag exceptions thrown from destructors — wrap in
try/catchinside the destructor - Flag
noexcepton functions that can actually throw — causesstd::terminate - Flag exception specifications (
throw(...)) — deprecated since C++11, removed in C++17 - Flag using exceptions for control flow in performance-critical paths
Performance
- Flag pass-by-value for non-trivial types where pass-by-const-reference suffices
- Flag
std::vector::push_backin a loop withoutreservewhen size is known — repeated reallocations - Flag
std::mapused wherestd::unordered_mapwould give O(1) lookup - Flag
std::endlin loops — prefer'\n'to avoid repeated buffer flushes - Flag unnecessary copies from missing
std::moveon local temporaries being returned or passed
Idioms and Best Practices
Ownership and Lifetime
- Prefer
std::unique_ptrfor sole ownership,std::shared_ptronly for shared ownership - Prefer
std::make_unique/std::make_sharedovernew— exception-safe - Use
std::weak_ptrto breakshared_ptrcycles - Never use raw owning pointers in new code — they are for non-owning observation only
Modern C++ (17/20)
- Prefer
std::optional<T>over sentinel values or nullable pointers for optional returns - Prefer
std::variantover tagged unions - Prefer
std::string_viewoverconst std::string&for read-only string parameters - Prefer range-based
forloops over index loops where the index isn't needed - Prefer
if constexprover#ifdeffor compile-time branching
Type Safety
- Prefer
static_castover C-style casts — explicit and auditable - Avoid
reinterpret_castexcept in low-level I/O or FFI code with a comment - Use
enum classover plainenumto avoid implicit integer conversions