Skip to content

Add a NoLeadingUnderscores mode that allows them when duplicating an existing property. #1150

@kdubb

Description

@kdubb

Basically, if you generally don't want people adding underscores to all private properties for composite datatypes there is a specific case that is so common it seems like it should be naturally allowed:

Prefixing backing variables

Example:

private var _count: AtomicInt<Int>

public var count: Int { _count.load(...} }

Yes this lint can easily be removed with // swift-format-ignore: NoLeadingUnderscores but in this specific case it can easily be determined why the prefix exists and should be allowed; if not always then in some new mode outside of the current true/false configuration.

Rule is simply (without considering multiple modes):

let userDefinedPropertyNamesInType: [String] = ...
let propertyName: String = ...
if propertyName.first == "_" and !userDefinedPropertyNamesInType.contains(propertyName.dropFirst()) {
   // produce lint
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions