refactor — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited refactor (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Execute safe refactoring operations with verification at each step. Refactoring changes code structure without altering external behavior.
Preserve behavior. Every refactoring must pass tests before and after. If behavior changes, it's not refactoring—it's a rewrite.
Rename variables, functions, classes, files, or directories while maintaining all references.
When to use:
Steps:
# Find all usages before renaming
grep -r "oldName" --include="*.ts" --include="*.js" --include="*.py"Pull out a code block into a new function, method, class, or module.
When to use:
Steps:
Extraction targets:
Replace a function call with the function body.
When to use:
Steps:
Relocate code to a more appropriate location in the codebase.
When to use:
Steps:
Before any refactoring, verify:
# 1. Ensure clean git state
git status
git stash # or commit work-in-progress
# 2. Run existing tests to establish baseline
# Pick the appropriate test command for your project
npm test 2>/dev/null || go test ./... 2>/dev/null || pytest 2>/dev/null || cargo test 2>/dev/null
# 3. Create a checkpoint
git checkout -b refactor/<description>Pre-refactoring checklist:
# Ensure tests exist
# If no tests, consider adding characterization tests first
# Create refactoring branch
git checkout -b refactor/<description> # Run tests
npm test 2>/dev/null || go test ./...
# Verify build succeeds
npm run build 2>/dev/null || go build ./... git add -A
git commit -m "ref: <what changed>" # Comprehensive verification
npm test 2>/dev/null && npm run lint 2>/dev/null # Remove any dead code
# Update documentation if needed
# Merge or create PR// Before
function processOrder(order: Order) {
// 50 lines of validation
// 30 lines of calculation
// 20 lines of persistence
}
// After
function processOrder(order: Order) {
const validated = validateOrder(order);
const calculated = calculateTotals(validated);
return persistOrder(calculated);
}# Before: utils.js has 500 lines
# After: Split into organized modules
mkdir -p src/utils/validation
mkdir -p src/utils/formatting
# Move validation functions
mv src/utils/validateUser.js src/utils/validation/
mv src/utils/validateOrder.js src/utils/validation/
# Update imports
find . -name "*.ts" -exec sed -i 's|from.*utils/validateUser|from../utils/validation/validateUser|g' {} \;# For large codebases, use language server
# TypeScript
npx tsserver --rename <file> <oldName> <newName>
# Or use find + sed for simpler cases
grep -rl "oldFunctionName" src/ | xargs sed -i 's/oldFunctionName/newFunctionName/g'When moving code creates circular imports:
If refactoring must change public API:
For codebase-wide changes:
# 1. Check what changed
git diff HEAD~1
# 2. Verify test expectations
# Look for tests that assert implementation details
# 3. Consider if test needs updating (rare)
# Only if refactoring exposed test as brittle# TypeScript: Check for missing imports
npx tsc --noEmit
# Go: Check for unused imports
goimports -l .
# General: Search for references to old names
grep -r "oldName" --include="*.ts" --include="*.js" --include="*.go"# Profile before and after
# Compare key metrics
# Ensure refactoring didn't introduce N+1 queries or unnecessary copies~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.