#2423 - Fix EmptyCountRule for binary, octal and hexadecimal integer literals

This commit is contained in:
Timofey Solonin
2018-10-02 19:47:52 +03:00
parent 5bcaa613cc
commit e9d2552888
2 changed files with 43 additions and 1 deletions
+35
View File
@@ -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,