Skip to content

Commit

Permalink
realm#2423 - Fix EmptyCountRule for binary, octal and hexadecimal int…
Browse files Browse the repository at this point in the history
…eger literals
  • Loading branch information
Timofey Solonin authored and sjavora committed Mar 9, 2019
1 parent 0121f0f commit 4df518f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
35 changes: 35 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4723,6 +4723,21 @@ order.discount == 0

```

```swift
[Int]().count == 0xff

```

```swift
[Int]().count == 0b01

```

```swift
[Int]().count == 0o07

```

</details>
<details>
<summary>Triggering Examples</summary>
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,26 @@ 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"
],
triggeringExamples: [
"[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,
Expand Down

0 comments on commit 4df518f

Please sign in to comment.