Skip to content

Flag redundant access levels same as enclosing context #1048

@danwood

Description

@danwood

It would be great to flag code that is marked with an explicit access level (internal, private, fileprivate) that is redundant to the access level of the type that is enclosing that code.

I have already implemented this on a private branch - I'm just waiting to deal with #1042 before presenting this.

Not determined : Should this have its own flag? Or to avoid having too many new flags, could this feature be folded into an existing flag?

Here are some example of code that should be flagged. (The inner declarations, not the outer, and not the "(set)" specifiers)

private class Private {
    private var x: Int
}

fileprivate class FilePrivate {
    fileprivate var data: String = ""
    fileprivate func method() {}

    fileprivate struct Config {
        fileprivate var value: Int = 0
    }
}

internal class Internal {
    internal var count: Int = 0
}

fileprivate class SetterExample {
    fileprivate fileprivate(set) var redundantSetter: Int = 0
    fileprivate private(set) var redundantAccess: Int = 0
}

internal class InternalSetterExample {
    internal internal(set) var redundantBoth: Int = 0
    fileprivate fileprivate(set) var redundantSetter: Int = 0
    internal private(set) var redundantAccess: Int = 0
}

private class PrivateSetterExample {
    private private(set) var redundantBoth: Int = 0
}

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