SKY-U001 · Dead code
Unused function
A function or method that nothing in the project calls. It still has to be read, tested and kept compiling, but removing it changes nothing. Skylos reports it with a confidence score that says how sure it is.
- Languages
- Python, TypeScript/JavaScript, Java, PHP, Dart, Go, Ruby (partial), C# (partial), C++ (file-local functions), Kotlin (private functions), Swift (private and fileprivate functions), Rust (hidden below the default threshold)
- Quality gate
- counted toward the gate limits (full and diff scans). Counts toward
max_dead_code, which has no limit by default, so it only fails a gate where you set one. - Finding type
- review
Why it matters
Dead functions mislead readers and coding agents, who copy and extend code that never runs. They also hide real bugs: a fix applied to an unused copy of a function never reaches production.
What Skylos flags
"""Invoice maths for the checkout service.""" TAX_RATE = 0.2 def calculate_total(items): subtotal = sum(item["price"] * item["qty"] for item in items) return round(subtotal * (1 + TAX_RATE)) def legacy_invoice_number(number): """Old INV-0000123 format, replaced by UUID invoice ids in 2024.""" return f"INV-{number:07d}"from billing.invoices import calculate_total def main(): items = [{"price": 1200, "qty": 2}, {"price": 350, "qty": 1}] print(f"Total: {calculate_total(items) / 100:.2f}") if __name__ == "__main__": main()What Skylos leaves alone
from flask import Blueprint, jsonify from billing.invoices import legacy_invoice_number bp = Blueprint("billing", __name__) @bp.route("/invoices/<int:number>/legacy-id")def show_legacy_id(number): return jsonify({"legacy_id": legacy_invoice_number(number)})Why Skylos leaves it alone
show_legacy_id carries a Flask route decorator, so Skylos treats it as an entry point that the framework calls. legacy_invoice_number is reachable from it, even though no code in the project calls the route directly.
How Skylos decides
- Runs on every scan; no flag is needed. Skylos lists every function and method in the project and every reference to them: calls, imports, attribute access, decorators.
- Starts each candidate at confidence 100 and drops it (confidence 0) when you said to keep it (an inline ignore, a whitelist entry, a configured entry point) or when something outside the code calls it: a framework decorator such as
@app.route,@app.commandor@shared_task, a known hook in a loaded pytest plugin or aconftest.py, a unittest hook, or a dunder method. Test, example and benchmark paths (tests/,test_*.py,conftest.py,*.spec.ts,examples/,benchmarks/and similar) are skipped too. The exception is Go: an unexported helper in a_test.gofile that the Go engine proves nothing calls is reported. - Lowers confidence for names that are often called by convention:
handle_*,*_callback,setup_*,on_*,visit_*,_privatenames, definitions in__init__.py, and code behind version checks. - Follows reachability: a function called only by other dead code is still dead. Roots are module-level code,
if __name__ == "__main__"blocks, framework entry points, package entry points and tests. - Treats names in a module's
__all__, and public names of an__init__.pywithout__all__, as exported API, and never reports them. - Searches the project's text for each remaining candidate (grep verification) and keeps it alive on a real reference that the parser missed, such as a string dispatch through
getattr. A function named only in a YAML or TOML file is still reported; for Python, config files count only when they name the module's file path. - Caps confidence by the weakest evidence (90 for a public module-level name, 80 for a public method, 40 for deprecated code) and lists the function only when it has no references, is not exported and scores at least the threshold (
--confidence, default 60). Uncertain cases, such asformat_*and*_namehelpers, are held back and only appear in JSON underdead_code_abstentions.
How to fix it
Delete the function, and its tests if they only test it. If projects outside this repository import it, it is public API: list it in the module's __all__, which Skylos treats as exported.
__all__ = ["calculate_total", "legacy_invoice_number"]When it can be wrong
- Library functions that only other projects call are reported when the module has no
__all__. - Functions called through a plugin registry, a string name or
getattr()can be reported when Skylos cannot follow the lookup. - It stays quiet on routes whose blueprint is never registered, on everything under
tests/, and onformat_*and*_namehelpers, so some dead code is missed.
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
On the
defline (or its decorator line), with a reason:Python def legacy_invoice_number(number): # skylos: ignore[SKY-U001] export jobKeep names alive by pattern in
pyproject.toml, optionally with a reason or an expiry date:TOML [tool.skylos.whitelist]names = ["legacy_*"]documented = { "plugin_*" = "loaded through entry points" }[[tool.skylos.dead_code.entrypoints]]declares extra entry points. A baseline accepts the unused functions you already have; it matches the bare name in any file, so a new unused function with the same name elsewhere is hidden too.