Community코딩 & 개발github.com

inline-function

Replace a function call with the function's body when the indirection adds no meaning. Use when a function body is as clear as its name, a wrapper only delegates, a helper is used once and forces unnecessary navigation, or bad factoring should be undone by inlining before re-extracting. Scans the target file, proposes candidates, and edits only after approval.

inline-function란 무엇인가요?

inline-function is a Claude Code agent skill that replace a function call with the function's body when the indirection adds no meaning. Use when a function body is as clear as its name, a wrapper only delegates, a helper is used once and forces unnecessary navigation, or bad factoring should be undone by inlining before re-extracting. Scans the target file, proposes candidates, and edits only after approval.

지원 대상~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Bouzidi-Youssef/refactor-skill/tree/HEAD/.opencode/skills/inline_function

Installed? Explore more 코딩 & 개발 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

즐겨 사용하는 AI에게 물어보기

이 에이전트 스킬이 미리 로드된 새 채팅을 엽니다.

문서

Inline Function

Category A — Simplifying and restructuring functions

Replace calls to a function with the function's body, then remove the function.

Inline Function is the inverse of Extract Function. Use it when a name no longer earns its keep: the reader has to jump to the definition and learns nothing they could not see at the call site.


Motivation

The smell

  • The body is as clear as the name. return age >= 18 does not need is_adult() if the domain already speaks in ages at that call site.
  • Needless indirection. A wrapper delegates to another function or returns a constant/simple expression without adding policy, validation, or vocabulary.
  • One-off helper. A function is called once, is unlikely to be reused, and makes the local flow harder to follow.
  • Bad factoring. A group of functions is split in the wrong places. Inline them back into their callers, then extract the right abstractions.
  • Dead abstraction after change. A function used to matter, but refactoring left it as a thin shell.

Fowler's test: when a function body is as clear as its name, inline it.

The design principle

  • Names must earn indirection. A function call is useful when it compresses intent, hides a meaningful decision, or creates a stable boundary. Otherwise it is navigation cost.
  • Local readability. Sometimes the clearest code is the code right there, not behind another name.
  • Behavior preservation. Inlining changes structure, not observable behavior: same arguments evaluated in the same order, same side effects, same return value, same errors.

Inline Function is not:

  • a license to delete useful domain vocabulary;
  • a way to make large functions bigger without a follow-up plan;
  • a mechanical expansion of every small helper.

When not to inline

  • The name adds domain meaning. isEligibleForDiscount(order) may be clearer than its boolean expression.
  • The function is a boundary. Public API, plugin hook, override point, test seam, or polymorphic method.
  • The function is overridden or implements an interface/contract where removing it changes behavior or type structure.
  • Multiple callers rely on one clear abstraction. Inlining duplicates knowledge.
  • The body is complex. Inlining would make callers harder to read. Consider re-extracting differently instead.
  • Dynamic/reflection use. The function may be called by name, framework, serialization, or external consumers.

Mechanic

Before you start

  1. Read the whole file and locate every caller. Search for references, including imports, re-exports, tests, and dynamic uses.
  2. Confirm the function is not part of a required contract: overrides, interface implementations, public API, framework hooks, or reflected calls.
  3. Find existing checks (tests/type checker/linter/run). Use what exists. Do not add tests unless asked.
  4. Work on one function at a time. Run checks after each removal.

Steps

  1. Pick one function. Prefer a trivial, private, single-caller, non-polymorphic function.
  2. Check the call sites. Count callers and note argument evaluation, side effects, and return use.
  3. Copy the body mentally or literally. Map parameters to arguments. Preserve evaluation order.
  4. Replace one caller. Substitute the call with the inlined body, adapting names to the caller's scope.
  5. Run checks. If behavior changes, stop and report.
  6. Repeat for remaining callers.
  7. Remove the function definition only when no callers remain and it is not externally required.
  8. Clean up. Remove now-unused imports, variables, or helpers exposed only for the old function. If inlining made a caller too large, name that as a follow-up Extract Function; do not silently re-extract unrelated code.

Resolving variables and call shapes

SituationAction
Argument is a simple name/valueSubstitute directly.
Argument is an expression with side effectsEvaluate it once in the same place/order as before. Assign to a local if needed.
Parameter name collides with caller localRename the inlined local to a clear, non-colliding name.
Function returns a value used in an expressionInline as an expression when simple; otherwise assign to a well-named local.
Function has multiple return pointsUse early returns only if caller control flow stays equivalent; otherwise restructure carefully or do not inline.
Function mutates state or performs I/OPreserve order and frequency exactly.
Caller passes different argument shapes across sitesInline each site carefully; do not force a bad shared abstraction.

Rules that keep the move safe:

  • Preserve argument evaluation order.
  • Preserve side effects and their order.
  • Do not inline polymorphic/contract methods.
  • Do not change public behavior while "cleaning up".
  • One function at a time; keep the diff attributable.

Example

Before

def get_order_status(paid: bool, shipped: bool) -> str:
    if not paid:
        return "Pending Payment"
    if shipped:
        return "Shipped"
    return order_ready()


def order_ready() -> str:
    return "Ready to Ship"

order_ready() adds no vocabulary beyond the string it returns. The indirection makes the reader jump for no gain.

After

def get_order_status(paid: bool, shipped: bool) -> str:
    if not paid:
        return "Pending Payment"
    if shipped:
        return "Shipped"
    return "Ready to Ship"

Behavior is unchanged. The call site is clearer because the value is immediately visible.

A non-example

def is_eligible_for_discount(order: Order) -> bool:
    return order.customer.is_premium and order.total > 100

Even if used once, this name may carry domain meaning. Inline only when the name does not earn its keep.


Related refactorings

  • Extract Function — the inverse; after inlining bad factoring, extract the right abstraction.
  • Replace Temp with Query — can create small functions that later become inline candidates, or vice versa.
  • Remove Dead Code — once inlined and unreferenced, the old function becomes dead code.
  • Substitute Algorithm — sometimes clearer than inlining a tangled body into callers.

Running this skill on a file

When invoked with @inline_function:

  1. Confirm the target. Use the file named by the user. If none is named, ask for one. Read it completely before proposing anything.
  2. Inventory candidates. For each candidate, report:
    • function name and location,
    • caller count and locations,
    • why the indirection is weak (trivial body, wrapper, one-off, clearer inline),
    • contract risk (public API, override, dynamic use, import/export surface),
    • risk: low (private, single caller, pure), medium (multiple callers or side effects), high (contract/polymorphism/dynamic use).
  3. Propose before editing. Present the plan and wait for approval. Do not change files on the first pass.
  4. Apply one function at a time. Inline one caller at a time when practical. Keep edits small and preserve style.
  5. Run existing checks after each step. If no checks exist, show the diff and state what was not verified.
  6. Report. Say what was inlined, what was removed, what remains, and any follow-up (such as Extract Function if a caller grew too large).
  7. Stop and ask if the function is polymorphic, externally used, dynamically referenced, or if inlining would change behavior or readability significantly.

Checklist

  • Every caller was found and updated.
  • Argument evaluation order and side effects are preserved.
  • The function is removed only when no required references remain.
  • The inlined code is at least as readable as the indirection.
  • Checks pass, or the unverified risk is stated.

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

extract-class

Split a class or module that has multiple responsibilities into smaller cohesive units. Use when a class has distinct clusters of fields and methods that change together, when a subset of behavior belongs to a separate concept, or when a class is hard to name because it does too much. Scans the target file, proposes extraction boundaries, and edits only after approval.

extract-function

Turn a coherent block of code into a well-named function without changing behavior. Use when a block needs a comment to be understood, a function is long or mixes levels of abstraction, logic is duplicated, or a loop or conditional arm does several jobs. Scans the target file, proposes candidates and names, and edits only after approval.

refactoring-router

Entry-point refactoring and rewrite skill. Use when the user wants to refactor, clean up, improve, simplify, or rewrite a codebase/file/module and needs smell-driven analysis, technique selection, or a new implementation approach. Detects refactor vs rewrite intent, asks type/mode/risk/scope/depth or ambition, then dispatches specialized subagents in an automatic loop. Triggers: "refactor this", "rewrite this", "clean this up", "improve this codebase", "reimplement this".

remove-dead-code

Delete code that is never executed, never referenced, or no longer reachable. Use when you find unused functions, variables, imports, parameters, branches, or files; when obsolete compatibility paths are no longer needed; or when dead code obscures behavior. Scans the target file, proposes safe deletions, and edits only after approval.

관련 스킬