Skip to content

Commit

Permalink
Merge pull request #2430 from biboran/empty-count-fix
Browse files Browse the repository at this point in the history
#2423 - Fix EmptyCountRule for binary, octal and hexadecimal integer literals
  • Loading branch information
marcelofabri authored Oct 2, 2018
2 parents 5bcaa61 + 21cd4e0 commit 34f513a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@
[Ornithologist Coder](https://github.com/ornithocoder)
[#2374](https://github.com/realm/SwiftLint/issues/2374)

* Fix false positive on `empty_count` rule when assesing binary, octal and
hexadecimal integer literals.
[Timofey Solonin](https://github.com/biboran)
[#2423](https://github.com/realm/SwiftLint/issues/2423)

## 0.27.0: Heavy Duty

#### Breaking
Expand Down
35 changes: 35 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4712,6 +4712,21 @@ var count = 0

```

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

```

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

```

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

```

```swift
discount == 0

Expand Down Expand Up @@ -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

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 34f513a

Please sign in to comment.