| name | Code Cleanup |
| description | Find unused variables, check formatting, apply fixes following FLEKS coding standards |
Code Cleanup
This skill performs code cleanup tasks following FLEKS coding standards.
Coding Standards Reference
From docs/Coding_standards.md:
- Memory Management: Use
shared_ptr or unique_ptr, avoid raw new
- Naming Conventions:
- Files:
PascalCase (e.g., GridUtility.cpp)
- Classes:
PascalCase (e.g., FluidInterface)
- Variables:
camelCase (e.g., nCellPerPatch)
- Functions:
snake_case (e.g., apply_float_boundary)
- Namespace:
using namespace amrex allowed only in .cpp files
- Header Order: std headers → AMReX headers → user headers
- Pointers: Use
nullptr, not NULL
- Const: Always use
const when possible
- Lambdas: Prefer regular functions for universal or long functions
- Commits: Follow Conventional Commits
Clang-Format (C++ files)
The project uses .clang-format with Mozilla-based style (2-space indent,
80-column limit).
Format Single File
clang-format -i src/FileName.cpp
Format All Source Files (Preferred)
Use the project's formatting script, which handles both C++ and Fortran in one pass:
python3 tools/format_all.py
This is also required before submitting a PR (see CONTRIBUTING.md).
Format All Source Files (Manual)
find src include -name "*.cpp" -o -name "*.h" | xargs clang-format -i
Check Formatting Without Changing
clang-format --dry-run -Werror src/FileName.cpp
Fortran Formatting (srcInterface files)
For .f90/.F90 files in srcInterface/, use findent configured
to match Emacs' f90-mode indentation:
findent < srcInterface/PC_wrapper.f90 > /tmp/formatted.f90
diff srcInterface/PC_wrapper.f90 /tmp/formatted.f90
Finding Issues
1. Unused Variables
The default C++ flags already include -Wall -Wextra -Wno-unused-parameter.
Build and review compiler warnings:
make LIB -j8 2>&1 | grep -i 'warning.*unused'
Or use clang-tidy on a specific file:
clang-tidy src/FileName.cpp -p compile_commands.json
2. Find Raw new Usage
grep -rn '\bnew\b' src/ include/ --include="*.cpp" --include="*.h"
3. Find NULL Usage (should be nullptr)
grep -rn '\bNULL\b' src/ include/ --include="*.cpp" --include="*.h"
4. Find using namespace in Headers
grep -rn 'using namespace' include/ --include="*.h"
5. Check Naming Conventions
Look for:
- Functions not using
snake_case
- Variables not using
camelCase
- Classes not using
PascalCase
Automated Cleanup Tasks
Task 1: Fix NULL to nullptr
grep -rn '\bNULL\b' src/ include/ --include="*.cpp" --include="*.h"
find src include \( -name "*.cpp" -o -name "*.h" \) -exec sed -i '' 's/\bNULL\b/nullptr/g' {} +
Task 2: Remove Trailing Whitespace
find src include \( -name "*.cpp" -o -name "*.h" \) -exec sed -i '' 's/[[:space:]]*$//' {} +
Task 3: Ensure Newline at End of File
for f in src/*.cpp include/*.h; do
[ -n "$(tail -c1 "$f")" ] && echo >> "$f"
done
Review Checklist
When reviewing cleanup changes:
Commit Message Format
For cleanup commits, use conventional commit format:
refactor: remove unused variables in Pic.cpp
- Removed unused `tempVar` variable
- Fixed NULL → nullptr
- Applied clang-format