Skip to content

Commit

Permalink
Merge branch 'master' into grouping-extension-ban
Browse files Browse the repository at this point in the history
  • Loading branch information
Mazyod authored Aug 26, 2017
2 parents d70e14d + b1c7063 commit 4c7f262
Show file tree
Hide file tree
Showing 12 changed files with 429 additions and 3 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ opt_in_rules:
- let_var_whitespace
- unneeded_parentheses_in_closure_argument
- extension_access_modifier
- pattern_matching_keywords

file_header:
required_pattern: |
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@

* Invalidate cache when Swift version changes.
[Marcelo Fabri](https://github.com/marcelofabri)

* Add `pattern_matching_keywords` opt-in rule to enforce moving `let` and `var`
keywords outside tuples in a `switch`.
[Marcelo Fabri](https://github.com/marcelofabri)
[#202](https://github.com/realm/SwiftLint/issues/202)

* Add `explicit_enum_raw_value` opt-in rule to allow refactoring the
Swift API without breaking the API contract.
[Mazyod](https://github.com/mazyod)
[#1778](https://github.com/realm/SwiftLint/issues/1778)

* Add `no_grouping_extension` opt-in rule to disallow the use of extensions
for code grouping purposes within the same file.
Expand Down
222 changes: 222 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [Empty Enum Arguments](#empty-enum-arguments)
* [Empty Parameters](#empty-parameters)
* [Empty Parentheses with Trailing Closure](#empty-parentheses-with-trailing-closure)
* [Explicit Enum Raw Value](#explicit-enum-raw-value)
* [Explicit Init](#explicit-init)
* [Explicit Top Level ACL](#explicit-top-level-acl)
* [Explicit Type Interface](#explicit-type-interface)
Expand Down Expand Up @@ -64,6 +65,7 @@
* [Operator Usage Whitespace](#operator-usage-whitespace)
* [Operator Function Whitespace](#operator-function-whitespace)
* [Overridden methods call super](#overridden-methods-call-super)
* [Pattern Matching Keywords](#pattern-matching-keywords)
* [Private Outlets](#private-outlets)
* [Private over fileprivate](#private-over-fileprivate)
* [Private Unit Test](#private-unit-test)
Expand Down Expand Up @@ -2091,6 +2093,103 @@ UIView.animateWithDuration(0.3, animations: {



## Explicit Enum Raw Value

Identifier | Enabled by default | Supports autocorrection | Kind
--- | --- | --- | ---
`explicit_enum_raw_value` | Disabled | No | idiomatic

Enums should be explicitly assigned their raw values.

### Examples

<details>
<summary>Non Triggering Examples</summary>

```swift
enum Numbers {
case int(Int)
case short(Int16)
}

```

```swift
enum Numbers: Int {
case one = 1
case two = 2
}

```

```swift
enum Numbers: Double {
case one = 1.1
case two = 2.2
}

```

```swift
enum Numbers: String {
case one = "one"
case two = "two"
}

```

```swift
protocol Algebra {}
enum Numbers: Algebra {
case one
}

```

</details>
<details>
<summary>Triggering Examples</summary>

```swift
enum Numbers: Int {
case one = 10, ↓two, three = 30
}

```

```swift
enum Numbers: NSInteger {
case ↓one
}

```

```swift
enum Numbers: String {
case ↓one
case ↓two
}

```

```swift
enum Numbers: String {
case ↓one, two = "two"
}

```

```swift
enum Numbers: Decimal {
case ↓one, ↓two
}

```

</details>



## Explicit Init

Identifier | Enabled by default | Supports autocorrection | Kind
Expand Down Expand Up @@ -7649,6 +7748,129 @@ class VC: UIViewController {



## Pattern Matching Keywords

Identifier | Enabled by default | Supports autocorrection | Kind
--- | --- | --- | ---
`pattern_matching_keywords` | Disabled | No | idiomatic

Combine multiple pattern matching bindings by moving keywords out of tuples.

### Examples

<details>
<summary>Non Triggering Examples</summary>

```swift
switch foo {
default: break
}
```

```swift
switch foo {
case 1: break
}
```

```swift
switch foo {
case bar: break
}
```

```swift
switch foo {
case let (x, y): break
}
```

```swift
switch foo {
case .foo(let x): break
}
```

```swift
switch foo {
case let .foo(x, y): break
}
```

```swift
switch foo {
case .foo(let x), .bar(let x): break
}
```

```swift
switch foo {
case .foo(let x, var y): break
}
```

```swift
switch foo {
case var (x, y): break
}
```

```swift
switch foo {
case .foo(var x): break
}
```

```swift
switch foo {
case var .foo(x, y): break
}
```

</details>
<details>
<summary>Triggering Examples</summary>

```swift
switch foo {
case (↓let x, ↓let y): break
}
```

```swift
switch foo {
case .foo(↓let x, ↓let y): break
}
```

```swift
switch foo {
case (.yamlParsing(↓let x), .yamlParsing(↓let y)): break
}
```

```swift
switch foo {
case (↓var x, ↓var y): break
}
```

```swift
switch foo {
case .foo(↓var x, ↓var y): break
}
```

```swift
switch foo {
case (.yamlParsing(↓var x), .yamlParsing(↓var y)): break
}
```

</details>



## Private Outlets

Identifier | Enabled by default | Supports autocorrection | Kind
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ extension Configuration {
.filter { rule in
return whitelistedRules.contains(type(of: rule).description.identifier)
}
case .default(let disabled, let optIn):
case let .default(disabled, optIn):
// Same here
return Set(
configuration.rules
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Models/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public struct Configuration: Equatable {
rules = configuredRules.filter { rule in
return validWhitelistedRuleIdentifiers.contains(type(of: rule).description.identifier)
}
case .default(let disabledRuleIdentifiers, let optInRuleIdentifiers):
case let .default(disabledRuleIdentifiers, optInRuleIdentifiers):
let validDisabledRuleIdentifiers = validateRuleIdentifiers(
ruleIdentifiers: disabledRuleIdentifiers.map(handleAliasWithRuleList),
validRuleIdentifiers: validRuleIdentifiers)
Expand Down
2 changes: 2 additions & 0 deletions Source/SwiftLintFramework/Models/MasterRuleList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public let masterRuleList = RuleList(rules: [
EmptyEnumArgumentsRule.self,
EmptyParametersRule.self,
EmptyParenthesesWithTrailingClosureRule.self,
ExplicitEnumRawValueRule.self,
ExplicitInitRule.self,
ExplicitTopLevelACLRule.self,
ExplicitTypeInterfaceRule.self,
Expand Down Expand Up @@ -72,6 +73,7 @@ public let masterRuleList = RuleList(rules: [
OperatorFunctionWhitespaceRule.self,
OperatorUsageWhitespaceRule.self,
OverriddenSuperCallRule.self,
PatternMatchingKeywordsRule.self,
PrivateOutletRule.self,
PrivateOverFilePrivateRule.self,
PrivateUnitTestRule.self,
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFramework/Models/YamlParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal enum YamlParserError: Error, Equatable {

internal func == (lhs: YamlParserError, rhs: YamlParserError) -> Bool {
switch (lhs, rhs) {
case (.yamlParsing(let x), .yamlParsing(let y)):
case let (.yamlParsing(x), .yamlParsing(y)):
return x == y
}
}
Expand Down
Loading

0 comments on commit 4c7f262

Please sign in to comment.