diff --git a/Rules.md b/Rules.md index dbf3bb4a7f9..91142bbdcb9 100644 --- a/Rules.md +++ b/Rules.md @@ -4723,6 +4723,21 @@ order.discount == 0 ``` +```swift +[Int]().count == 0xff + +``` + +```swift +[Int]().count == 0b01 + +``` + +```swift +[Int]().count == 0o07 + +``` +
Triggering Examples @@ -4742,6 +4757,26 @@ order.discount == 0 ``` +```swift +[Int]().↓count == 0x0 + +``` + +```swift +[Int]().↓count == 0x00_00 + +``` + +```swift +[Int]().↓count == 0b00 + +``` + +```swift +[Int]().↓count == 0o00 + +``` + ```swift ↓count == 0 diff --git a/Source/SwiftLintFramework/Rules/Performance/EmptyCountRule.swift b/Source/SwiftLintFramework/Rules/Performance/EmptyCountRule.swift index 6bef0a29bf4..0404effdaa1 100644 --- a/Source/SwiftLintFramework/Rules/Performance/EmptyCountRule.swift +++ b/Source/SwiftLintFramework/Rules/Performance/EmptyCountRule.swift @@ -15,6 +15,9 @@ public struct EmptyCountRule: ConfigurationProviderRule, OptInRule, AutomaticTes "[Int]().isEmpty\n", "[Int]().count > 1\n", "[Int]().count == 1\n", + "[Int]().count == 0xff\n", + "[Int]().count == 0b01\n", + "[Int]().count == 0o07\n", "discount == 0\n", "order.discount == 0\n" ], @@ -22,12 +25,16 @@ public struct EmptyCountRule: ConfigurationProviderRule, OptInRule, AutomaticTes "[Int]().↓count == 0\n", "[Int]().↓count > 0\n", "[Int]().↓count != 0\n", + "[Int]().↓count == 0x0\n", + "[Int]().↓count == 0x00_00\n", + "[Int]().↓count == 0b00\n", + "[Int]().↓count == 0o00\n", "↓count == 0\n" ] ) public func validate(file: File) -> [StyleViolation] { - let pattern = "\\bcount\\s*(==|!=|<|<=|>|>=)\\s*0" + let pattern = "\\bcount\\s*(==|!=|<|<=|>|>=)\\s*0(\\b|([box][0_]+\\b){1})" let excludingKinds = SyntaxKind.commentAndStringKinds return file.match(pattern: pattern, excludingSyntaxKinds: excludingKinds).map { StyleViolation(ruleDescription: type(of: self).description,