SKY-U004 · Dead code
Unused class
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
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
"""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>"from billing.exporters import CsvExporter if __name__ == "__main__": print(CsvExporter().export([("INV-1", 1200)]))What Skylos leaves alone
"""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)"""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
- 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
isinstancecheck. - Never reports a class a framework loads by convention: Django models, forms, commands, views, admin classes, app configs and middleware, DRF classes,
Protocolclasses, classes whose name starts withTestin a test path, and classes behind a framework decorator. - Treats a class listed in
__all__, or a public class in an__init__.pywithout__all__, as exported and never reports it. Lowers confidence by 15 for a class defined in an__init__.pyand by 10 for a_privatename. - 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__.
"""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
classline, 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.