Skip to main content

SKY-A136 · AI-code defects

New code nothing calls

Low

New code nothing calls is a function, method, class or JavaScript file that the change added and that no code reaches, or that only other unused code calls. Agents often write a helper, then solve the task another way and leave the helper 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-A136 findings fail the verdict.
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

Unused new code makes a change look bigger and more finished than it is. It can also mean the wiring step was forgotten: the new handler or validator exists but nothing ever runs it.

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/orders.py · Python · changed
"""Order totals for the checkout service."""  def order_total(items):    return sum(item["cents"] * item["qty"] for item in items)Added:  Added:  Added: def apply_coupon(total_cents, percent_off):Added:     return round(total_cents * (100 - percent_off) / 100)
1 committed file the change leaves alone
app/cli.py · Python
from app.orders import order_total if __name__ == "__main__":    print(order_total([{"cents": 1250, "qty": 2}]))

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/orders.py · Python · changed
"""Order totals for the checkout service.""" Removed: from flask import FlaskAdded: from flask import Flask, request app = Flask(__name__)  def order_total(items):    return sum(item["cents"] * item["qty"] for item in items)Added:  Added:  Added: @app.post("/orders/total")Added: def order_total_view():Added:     return {"total_cents": order_total(request.json["items"])}

Why Skylos leaves it alone

No code in the repository calls order_total_view either, but Flask does: the route decorator registers it. Skylos treats framework routes as used, and does not judge a symbol under a decorator that may register it.

More languages

TypeScript

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/orders.ts · TypeScript · changed
export interface Item {  cents: number;  qty: number;} export function orderTotal(items: Item[]): number {  return items.reduce((sum, item) => sum + item.cents * item.qty, 0);}Added:  Added: function applyCoupon(totalCents: number, percentOff: number): number {Added:   return Math.round((totalCents * (100 - percentOff)) / 100);Added: }
2 committed files the change leaves alone
package.json · JSON
{"name": "shop", "type": "module", "main": "src/index.ts"}
src/index.ts · TypeScript
import { orderTotal } from "./orders.js"; console.log(orderTotal([{ cents: 1250, qty: 2 }]));

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/orders.ts · TypeScript · changed
export interface Item {  cents: number;  qty: number;} Removed: export function orderTotal(items: Item[]): number {Removed:   return items.reduce((sum, item) => sum + item.cents * item.qty, 0);Added: export function orderTotal(items: Item[], percentOff = 0): number {Added:   const total = items.reduce((sum, i) => sum + i.cents * i.qty, 0);Added:   return applyCoupon(total, percentOff);}Added:  Added: function applyCoupon(totalCents: number, percentOff: number): number {Added:   return Math.round((totalCents * (100 - percentOff)) / 100);Added: }
2 committed files the change leaves alone

package.json: same as in the flagged example.

src/index.ts: same as in the flagged example.

Why Skylos leaves it alone

The new applyCoupon is called by orderTotal, which the entry point uses, so the new code is wired in.

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 unused in the head copy and whose declaration line the change added is new when its name is on no removed line and most of its body is new lines; a definition moved or renamed from elsewhere in the change is not new. A JS or TS file the change added that nothing imports is reported as a whole.
  3. Entry points, framework roots (routes, views, fixtures, commands), exported public API and dispatch the dead-code engine recognises count as used. A new symbol the analyzer is unsure about, one whose name appears in a template, config file or a file it could not parse, and one under a decorator that may register it are not judged.
  4. Survivors go through the same grep check as skylos . (on the head copy without tests). A survivor that a test calls is reported as SKY-A137 instead.

How to fix it

Wire the new code in where it was meant to run, or delete it. A helper written for a later change belongs in that change.

Fix · Python
def order_total(items, percent_off=0):    total = sum(item["cents"] * item["qty"] for item in items)    return apply_coupon(total, percent_off)

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.
  • A new public library function that only other packages will call is reported until something in the repository uses it or exports it.
  • 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 SKY-A136 advisory while branch_orphans blocks, leave it out of branch_orphans_block_rules in the base commit's pyproject.toml.

    TOML
    [tool.skylos.done]branch_orphans_block_rules = ["SKY-A135"] [tool.skylos.done.checks]branch_orphans = "block"

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