refactoring — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited refactoring (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.
Restructure code safely while preserving behavior.
Before refactoring, ensure tests exist:
# Run existing tests
npm test
pytest
go test ./...If no tests cover the code:
Map the code:
# Find usages
grep -r "functionName" --include="*.ts"
# Find dependencies
grep -r "import.*from.*module" --include="*.ts"Identify the target state:
Choose your approach:
| Situation | Approach |
|---|---|
| Large function | Extract methods |
| Duplicated code | Extract shared function |
| Complex conditionals | Replace with polymorphism |
| Long parameter list | Introduce parameter object |
| Feature envy | Move method to data's class |
| Data clump | Extract class |
The safe refactoring cycle:
1. Make ONE small change
2. Run tests
3. Commit if green
4. RepeatNever skip steps:
# Run full test suite
npm test
# Check for regressions
npm run test:e2e
# Manual smoke test if neededMost IDEs can do these automatically:
| Refactoring | Shortcut (VS Code) |
|---|---|
| Rename | F2 |
| Extract function | Ctrl+Shift+R |
| Extract variable | Ctrl+Shift+R |
| Inline variable | Ctrl+Shift+R |
| Move to file | Drag in explorer |
#### Extract Function
// Before
function processOrder(order) {
// validate
if (!order.items.length) throw new Error('Empty order');
if (!order.customer) throw new Error('No customer');
// calculate total
let total = 0;
for (const item of order.items) {
total += item.price * item.quantity;
}
// apply discount
if (order.coupon) {
total *= (1 - order.coupon.discount);
}
return { ...order, total };
}
// After
function processOrder(order) {
validateOrder(order);
const total = calculateTotal(order);
return { ...order, total };
}
function validateOrder(order) {
if (!order.items.length) throw new Error('Empty order');
if (!order.customer) throw new Error('No customer');
}
function calculateTotal(order) {
const subtotal = order.items.reduce(
(sum, item) => sum + item.price * item.quantity,
0
);
return order.coupon
? subtotal * (1 - order.coupon.discount)
: subtotal;
}#### Replace Conditional with Polymorphism
// Before
function getSpeed(vehicle) {
switch (vehicle.type) {
case 'car': return vehicle.horsepower * 0.5;
case 'bike': return vehicle.gears * 5;
case 'boat': return vehicle.engineSize * 2;
}
}
// After
class Car {
getSpeed() { return this.horsepower * 0.5; }
}
class Bike {
getSpeed() { return this.gears * 5; }
}
class Boat {
getSpeed() { return this.engineSize * 2; }
}#### Introduce Parameter Object
// Before
function createUser(name, email, age, country, role) {
// ...
}
// After
function createUser({ name, email, age, country, role }) {
// ...
}
// Or with type
interface CreateUserParams {
name: string;
email: string;
age: number;
country: string;
role: string;
}
function createUser(params: CreateUserParams) {
// ...
}| Smell | Refactoring |
|---|---|
| Long method | Extract method |
| Large class | Extract class |
| Duplicate code | Extract function |
| Long parameter list | Parameter object |
| Switch statements | Polymorphism |
| Feature envy | Move method |
| Data clump | Extract class |
| Primitive obsession | Value object |
| Comments explaining code | Extract well-named method |
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.