Skip to content

Commit

Permalink
Adds new opt-in rule, private_action
Browse files Browse the repository at this point in the history
Implements realm#1931. (+1 squashed commit)
Squashed commits:
[5911dcc] Fix false positives in control_statement when methods with keyword names are used

Fixes realm#1946 (+1 squashed commit)
Squashed commits:
[4cdcc48] Updates changelog entry
  • Loading branch information
ornithocoder authored and Daniel Metzing committed Dec 18, 2017
1 parent e5d5a22 commit 7f513b2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
18 changes: 13 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
* Add `yoda_condition` opt-in rule which warns to avoid Yoda conditions.
[Daniel Metzing](https://github.com/dirtydanee)
[#1924](https://github.com/realm/SwiftLint/issues/1924)
* Add `private_action` opt-in rule which warns against public
@IBAction methods.
[Ornithologist Coder](https://github.com/ornithocoder)
[#1931](https://github.com/realm/SwiftLint/issues/1931)

##### Bug Fixes

* None.
* Fix false positives in `control_statement` rule when methods with keyword
names are used.
[Marcelo Fabri](https://github.com/marcelofabri)
[#1946](https://github.com/realm/SwiftLint/issues/1946)

## 0.24.0: Timed Dry

Expand Down Expand Up @@ -77,6 +84,10 @@
[JP Simard](https://github.com/jpsim)
[#1822](https://github.com/realm/SwiftLint/issues/1822)

* Add `private_action` opt-in rule which warns agaist public @IBAction methods.
[Ornithologist Coder](https://github.com/ornithocoder)
[#1931](https://github.com/realm/SwiftLint/issues/1931)

##### Bug Fixes

* Extend `first_where` and `contains_over_first_not_nil` rules to also detect
Expand Down Expand Up @@ -110,10 +121,7 @@

##### Enhancements

* Add `private_action` opt-in rule which warns agaist public
@IBAction methods.
[Ornithologist Coder](https://github.com/ornithocoder)
[#1931](https://github.com/realm/SwiftLint/issues/1931)
* None.

##### Bug Fixes

Expand Down
4 changes: 4 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,10 @@ do {
}
```

```swift
foo().catch(all: true) {}
```

</details>
<details>
<summary>Triggering Examples</summary>
Expand Down
12 changes: 11 additions & 1 deletion Source/SwiftLintFramework/Rules/ControlStatementRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public struct ControlStatementRule: ConfigurationProviderRule {
"} while condition {\n",
"do { ; } while condition {\n",
"switch foo {\n",
"do {\n} catch let error as NSError {\n}"
"do {\n} catch let error as NSError {\n}",
"foo().catch(all: true) {}"
],
triggeringExamples: [
"↓if (condition) {\n",
Expand Down Expand Up @@ -72,6 +73,15 @@ public struct ControlStatementRule: ConfigurationProviderRule {
let matchString = file.contents.substring(from: match.location, length: match.length)
return !isFalsePositive(matchString, syntaxKind: syntaxKinds.first)
}
.filter { match, _ -> Bool in
let contents = file.contents.bridge()
guard let byteOffset = contents.NSRangeToByteRange(start: match.location, length: 1)?.location,
let outerKind = file.structure.kinds(forByteOffset: byteOffset).last else {
return true
}

return SwiftExpressionKind(rawValue: outerKind.kind) != .call
}
.map { match, _ -> StyleViolation in
return StyleViolation(ruleDescription: type(of: self).description,
severity: configuration.severity,
Expand Down

0 comments on commit 7f513b2

Please # to comment.