Skip to main content

SKY-U004 · Dead code

Unused class

No severity

Unused-code findings carry no severity in JSON. The terminal report shows them as LOW, SARIF as level note and GitLab as minor. A confidence score from 0 to 100 decides whether they are listed (60 or more by default); a public module-level Python class is capped at 90.

A class (or, in Go, a type) that nothing in the project creates, extends, imports or names. Its methods are dead with it, even if they call each other.

Languages
Python, TypeScript/JavaScript, Java, Go (types), PHP, Kotlin (private classes), Swift (private and fileprivate types), C#, Dart
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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

An unused class is usually an old implementation left behind after a rewrite. Readers and coding agents find it, extend it and fix bugs in it, and none of that work ever runs.

What Skylos flags

billing/exporters.py · PythonReported on line 13
"""Export invoices for the accounting system."""import csvimport io  class CsvExporter:    def export(self, invoices):        buffer = io.StringIO()        csv.writer(buffer).writerows(invoices)        return buffer.getvalue()  class LegacyXmlExporter:    """Old SAP export, replaced by CSV uploads in 2023."""     def export(self, invoices):        rows = "".join(f"<row>{number}</row>" for number, _ in invoices)        return f"<invoices>{rows}</invoices>"
main.py · Python
from billing.exporters import CsvExporter if __name__ == "__main__":    print(CsvExporter().export([("INV-1", 1200)]))

What Skylos leaves alone

audit/models.py · Python
"""Audit trail tables."""from django.db import models  class AuditEntry(models.Model):    action = models.CharField(max_length=50)    created = models.DateTimeField(auto_now_add=True)

main.py: same as in the flagged example.

billing/exporters.py · Python
"""Export invoices for the accounting system."""import csvimport io  class CsvExporter:    def export(self, invoices):        buffer = io.StringIO()        csv.writer(buffer).writerows(invoices)        return buffer.getvalue()

Why Skylos leaves it alone

Nothing in the project names AuditEntry, but it extends Django's models.Model. Django finds models through the app registry, so Skylos treats Django models, forms, management commands, views, admin classes and middleware as used.

How Skylos decides

  1. Runs on every scan; no flag is needed. Every class is a definition, and every reference to its name counts: a call, an import, a base-class list, a type annotation, a decorator or an isinstance check.
  2. Never reports a class a framework loads by convention: Django models, forms, commands, views, admin classes, app configs and middleware, DRF classes, Protocol classes, classes whose name starts with Test in a test path, and classes behind a framework decorator.
  3. Treats a class listed in __all__, or a public class in an __init__.py without __all__, as exported and never reports it. Lowers confidence by 15 for a class defined in an __init__.py and by 10 for a _private name.
  4. Skips test, example and benchmark paths and lines marked # skylos: ignore[SKY-U004], confirms with a text search of the project, and caps a public module-level Python class at 90. The rest is listed when it scores at least the threshold (--confidence, default 60).

How to fix it

Delete the class and the tests that only exercise it. If code outside this repository uses it, list it in the module's __all__.

Fix · Python
"""Export invoices for the accounting system."""import csvimport io  class CsvExporter:    def export(self, invoices):        buffer = io.StringIO()        csv.writer(buffer).writerows(invoices)        return buffer.getvalue()

When it can be wrong

  • Classes loaded by name from configuration (a dotted path in a settings file, a plugin entry point) are reported unless the name also appears in the project's text.
  • Library classes meant for other projects are reported when the module has no __all__.

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 class line, with a reason:

    Python
    class LegacyXmlExporter:  # skylos: ignore[SKY-U004] loaded by plugin name
  • [tool.skylos] ignore = ["SKY-U004"] turns the rule off for the project.

  • A baseline accepts the unused classes you already have.

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