inline-method
Replace a call to a trivial method with the method's body directly.
SKILL.mdskills/code-quality/inline-method/SKILL.md
GitHubInline Method
When a method body is as clear as its name, remove the method and inline the body at the call site.
When to Use
- Method body is a single line or completely obvious
- Method is called only once and adds no clarity
- Excessive indirection makes code harder to follow
- Prelude to reorganising code into a more sensible structure
How to Apply
- Check the method is not polymorphic (no subclass overrides it)
- Find all call sites
- Replace each call with the method body
- Run tests
- Delete the method
Example
// Before
function getRating(driver: Driver): number {
return moreThanFiveLateDeliveries(driver) ? 2 : 1;
}
function moreThanFiveLateDeliveries(driver: Driver): boolean {
return driver.lateDeliveries > 5;
}
// After
function getRating(driver: Driver): number {
return driver.lateDeliveries > 5 ? 2 : 1;
}