Static Over Final Class
ID |
swift.static_over_final_class |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Code Smell |
Language |
Swift |
Tags |
code-smell, style |
Description
Reports a type-level member declared final class. The two modifiers
together mean exactly what static means on its own — a non-overridable
type member — but static is the recommended spelling and shorter to
read.
final class func make() -> Self { ... } // FLAW
static func make() -> Self { ... } // OK
class func make() -> Self { ... } // OK — overridable type method
Rationale
class func means "type method that subclasses may override".
Adding final strips the overridability away, leaving exactly the
semantics of static func. The combined form forces the reader to
remember the equivalence; the canonical static form does not.
Remediation
Replace final class with static:
static func make() -> Self { ... }
static var shared = Service()