Skip to content

False positives for rule DontRepeatTypeInStaticProperties #1103

@Jeehut

Description

@Jeehut

I recently turned on more rules in a swift-formatted project and while fixing all violations I noticed that there seem to be quite a few false positives for one rule in particular: DontRepeatTypeInStaticProperties. I'm using Xcode 26.1.1 (17B100).

Here are a few code examples where swift-format reports a violation even though there isn't any:

extension A.Operation {
	// [DontRepeatTypeInStaticProperties] remove the suffix 'Operation' from the name of the variable 'anyOperationType'
	static let anyOperationType = ...
}

There is no suffix Operation in the variable name. It's in the middle, which is a totally valid case and can't be removed.

Another example:

extension B.Metadata.FeatureLevel {
	// [DontRepeatTypeInStaticProperties] remove the suffix 'FeatureLevel' from the name of the variable 'predicateFeatureLevels'
	private static let predicateFeatureLevels: [NSExpression: Self] = [...]
}

Again, there is no suffix FeatureLevel – it's somewhere in the middle and removing is not possible.

public final class Application: NSObject, Identifiable {
	// [DontRepeatTypeInStaticProperties] remove the prefix 'Application' from the name of the variable 'applicationsDidChangeNotification'
	public static let applicationsDidChangeNotification = Notification.Name("ApplicationsDidChangeNotification")
}

While this is a more discussable case, the prefix here is applications and this plural variable has a different meaning and does not necessarily represent the same context as the type and therefore should not cause a violation. Another false positive.

Unfortunately we had to disable this rule, but would be great if we could enable it again once fixed.

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