diff --git a/Rules.md b/Rules.md index e7e936554..a94eea78d 100644 --- a/Rules.md +++ b/Rules.md @@ -9022,7 +9022,19 @@ var foo = true, let kFoo = true ```swift let - kFoo = true + kFoo = true +``` + +```swift +var foo: Int { + return a + b +} +``` + +```swift +let kFoo = { + return a + b +}() ``` @@ -9058,6 +9070,12 @@ let ↓foo = true ``` +```swift +let ↓foo = { + return a + b +}() +``` + diff --git a/Source/SwiftLintFramework/Rules/PrefixedTopLevelConstantRule.swift b/Source/SwiftLintFramework/Rules/PrefixedTopLevelConstantRule.swift index 3bc2af0ce..f8c7e62ca 100644 --- a/Source/SwiftLintFramework/Rules/PrefixedTopLevelConstantRule.swift +++ b/Source/SwiftLintFramework/Rules/PrefixedTopLevelConstantRule.swift @@ -36,7 +36,13 @@ public struct PrefixedTopLevelConstantRule: ASTRule, OptInRule, ConfigurationPro "var foo = true, bar = true", "var foo = true, let kFoo = true", "let\n" + - " kFoo = true" + " kFoo = true", + "var foo: Int {\n" + + " return a + b\n" + + "}", + "let kFoo = {\n" + + " return a + b\n" + + "}()" ], triggeringExamples: [ "private let ↓Foo = 20.0", @@ -46,7 +52,10 @@ public struct PrefixedTopLevelConstantRule: ASTRule, OptInRule, ConfigurationPro "let ↓foo = 2, ↓bar = true", "var foo = true, let ↓Foo = true", "let\n" + - " ↓foo = true" + " ↓foo = true", + "let ↓foo = {\n" + + " return a + b\n" + + "}()" ] ) @@ -56,6 +65,7 @@ public struct PrefixedTopLevelConstantRule: ASTRule, OptInRule, ConfigurationPro guard kind == .varGlobal, dictionary.setterAccessibility == nil, + dictionary.bodyLength == nil, dictionary.name?.hasPrefix(topLevelPrefix) == false, let nameOffset = dictionary.nameOffset else {