mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
#2423 - Fix EmptyCountRule for binary, octal and hexadecimal integer literals
This commit is contained in:
@@ -4722,6 +4722,21 @@ order.discount == 0
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
[Int]().count == 0xff
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
[Int]().count == 0b01
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
[Int]().count == 0o07
|
||||
|
||||
```
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>Triggering Examples</summary>
|
||||
@@ -4741,6 +4756,26 @@ order.discount == 0
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
[Int]().↓count == 0x0
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
[Int]().↓count == 0x00_00
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
[Int]().↓count == 0b00
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
[Int]().↓count == 0o00
|
||||
|
||||
```
|
||||
|
||||
```swift
|
||||
↓count == 0
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user