Skip to main content

SKY-A135 · AI-code defects

Code left unused by the change

Medium

Code is left unused by a change when a function, method, class or JavaScript file had a production caller in the base version and has none after the change. It usually sits in a file the change did not touch: an agent switched a call site to a new helper and left the old one behind.

Languages
Python, TypeScript/JavaScript (symbols and whole files), Java, Kotlin, Go (needs the skylos-go engine), PHP, Rust, and the other languages the dead-code engine reads
Turned on by
skylos done after a change (default base HEAD, so uncommitted edits), or skylos done --base origin/main for a pull request
Quality gate
not checked (full and diff scans). Only skylos done runs this rule, in its branch_orphans check, which advises by default: findings are listed and the verdict does not fail. With branch_orphans = "block" under [tool.skylos.done.checks] in the base commit's pyproject.toml, SKY-A135 findings fail the verdict, except the doubtful ones described below, which stay advice.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

Diff-based review never shows the orphan, because none of its lines changed. It stays in the code, keeps being maintained and tested, and the next reader or agent may call the old, now-wrong helper.

What Skylos flags

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

app/pricing.py · Python · changed
"""Price formatting for the shop pages."""  def price_label(cents):    return f"${cents / 100:,.2f}"
app/checkout.py · Python · changed
Removed: from app.pricing import price_labelAdded: from app.money import format_money  def line_text(item):Removed:     return f"{item['name']}: {price_label(item['cents'])}"Added:     return f"{item['name']}: {format_money(item['cents'], 'USD')}"
app/money.py · Python · new file
"""Money formatting in several currencies.""" SYMBOLS = {"USD": "$", "EUR": "€", "GBP": "£"}  def format_money(cents, currency):    return f"{SYMBOLS[currency]}{cents / 100:,.2f}"
1 committed file the change leaves alone
app/cli.py · Python
from app.checkout import line_text if __name__ == "__main__":    print(line_text({"name": "Mug", "cents": 1250}))

What Skylos leaves alone

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

app/checkout.py · Python · changed
Removed: from app.pricing import price_labelAdded: from app.money import format_money  def line_text(item):Removed:     return f"{item['name']}: {price_label(item['cents'])}"Added:     return f"{item['name']}: {format_money(item['cents'], 'USD')}"
app/money.py · Python · new file
"""Money formatting in several currencies.""" SYMBOLS = {"USD": "$", "EUR": "€", "GBP": "£"}  def format_money(cents, currency):    return f"{SYMBOLS[currency]}{cents / 100:,.2f}"
3 committed files the change leaves alone

app/pricing.py: same as in the flagged example.

app/receipts.py · Python
from app.pricing import price_label  def receipt_total(order):    return f"Total: {price_label(order['total_cents'])}"
app/cli.py · Python
from app.checkout import line_textfrom app.receipts import receipt_total if __name__ == "__main__":    print(line_text({"name": "Mug", "cents": 1250}))    print(receipt_total({"total_cents": 1250}))

Why Skylos leaves it alone

The same call to price_label was removed, but app/receipts.py still calls it. A symbol is reported only when no production caller is left.

More languages

JavaScript

Flagged

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

src/pricing.js · JavaScript · changed
export function priceLabel(cents) {  return `$${(cents / 100).toFixed(2)}`;}
src/checkout.js · JavaScript · changed
Removed: import { priceLabel } from "./pricing.js";Added: import { formatMoney } from "./money.js"; export function lineText(item) {Removed:   return `${item.name}: ${priceLabel(item.cents)}`;Added:   return `${item.name}: ${formatMoney(item.cents, "USD")}`;}
src/money.js · JavaScript · new file
const SYMBOLS = { USD: "$", EUR: "€", GBP: "£" }; export function formatMoney(cents, currency) {  return `${SYMBOLS[currency]}${(cents / 100).toFixed(2)}`;}
2 committed files the change leaves alone
package.json · JSON
{"name": "shop", "type": "module", "main": "src/index.js"}
src/index.js · JavaScript
import { lineText } from "./checkout.js"; console.log(lineText({ name: "Mug", cents: 1250 }));

Not flagged

A change: the first version of these files is committed, then the edit below is made without committing, and Skylos reviews it as a diff scan (--diff).

src/checkout.js · JavaScript · changed
Removed: import { priceLabel } from "./pricing.js";Added: import { formatMoney } from "./money.js"; export function lineText(item) {Removed:   return `${item.name}: ${priceLabel(item.cents)}`;Added:   return `${item.name}: ${formatMoney(item.cents, "USD")}`;}
src/money.js · JavaScript · new file
const SYMBOLS = { USD: "$", EUR: "€", GBP: "£" }; export function formatMoney(cents, currency) {  return `${SYMBOLS[currency]}${(cents / 100).toFixed(2)}`;}
4 committed files the change leaves alone

package.json: same as in the flagged example.

src/pricing.js: same as in the flagged example.

src/receipts.js · JavaScript
import { priceLabel } from "./pricing.js"; export function receiptTotal(order) {  return `Total: ${priceLabel(order.totalCents)}`;}
src/index.js · JavaScript
import { lineText } from "./checkout.js";import { receiptTotal } from "./receipts.js"; console.log(lineText({ name: "Mug", cents: 1250 }));console.log(receiptTotal({ totalCents: 1250 }));

Why Skylos leaves it alone

src/receipts.js still imports src/pricing.js, so the file keeps a production importer. In the flagged version nothing imports it any more, and the whole file is reported.

How Skylos decides

  1. Runs in skylos done when the change touches production code. Copies the base commit and the working tree (or pull request head) into private temporary folders, removes test files from both, and runs the regular dead-code analysis on each, with a confidence of 75 or more. Nothing in the repository runs.
  2. A function, method or class that is alive in the base copy and unused in the head copy is a candidate, matched by name, kind and base line. A JS or TS file that something imported at the base and nothing imports now is a candidate too. Generated files and test code are never reported.
  3. A symbol the analyzer is unsure about (a weak helper name, for example) is kept only when a line the change removed used it, and then stays advice. A candidate whose name appears in a file the analyzer could not parse, or in a template or config file, or that has a decorator which may register it with a framework, is not judged.
  4. Survivors go through the same grep check as skylos . (on the head copy without tests); any remaining use clears them. The message names the removed or changed line that used to call the symbol, and says when only tests still call it.

How to fix it

Delete the orphan in the same change (here, remove price_label from app/pricing.py, or the whole file once it holds nothing else), or point the old callers back at it if dropping them was a mistake.

When it can be wrong

  • Code reached only by reflection, string dispatch or a plugin system the dead-code engine does not know looks unused, as it does for SKY-U001.
  • Public library API that only other packages call is reported once its last caller in this repository goes away.
  • Languages whose engine is not installed (Go without skylos-go, Dart without Dart support) are listed as not checked, not passed.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • skylos done does not read # skylos: ignore comments for this rule. The check advises by default. To keep it advisory, or to turn it off, set its mode in the base commit's pyproject.toml.

    TOML
    [tool.skylos.done.checks]branch_orphans = "off"

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.