Same Class Field Names

ID

swift.same_class_field_names

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Swift

Tags

code-smell, naming

Description

Reports a stored property whose name matches the enclosing type’s name (case-insensitive). The duplication creates confusing references like Order.order.

class Order {
    var order: Int = 0           // FLAW
    var orderID: String = ""     // OK
}

Rationale

A property whose name echoes the enclosing type adds no information and produces awkward references at the call site (order.order, item.item). It also tends to mask intent — the field is almost always an identifier or a domain attribute that deserves a more specific name.

Remediation

Pick a more specific property name:

class Order {
    var id: Int = 0
    var orderID: String = ""
}