Skip to content

Commit

Permalink
Multiline Brackets (realm#2302)
Browse files Browse the repository at this point in the history
* Add new multiline_literal_brackets rule with examples

* Implement rule

* Add changelog entry

* Fix CHANGELOG and rule name

* Fix tests + Update stuff after rebasing

* Add more examples & fix whitespace issue

* Address feedback from @ornithocoder

* Add multiline rules for arguments and parameters

* Fix false positives in rule multiline_parameters_brackets

* Fix false positive for trailing closures in multiline_arguments_brackets

* Add nested examples to rule multiline_arguments_brackets

* Fix more false positives in multiline_arguments_brackets rule

* Use guard where appropriate instead of if

* Update generated artifacts after rebase

* Add CHANGELOG entry for all three new rules

* Move changelog entries to new version

* Fix changelog entries position

* Move new rules to correct subfolder

* Update Rules.md file contents

* Fixup changelog

* Refactor rules
  • Loading branch information
Jeehut authored and sjavora committed Mar 9, 2019
1 parent 16f36eb commit d7750b3
Show file tree
Hide file tree
Showing 9 changed files with 813 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
[Cihat Gündüz](https://github.com/Dschee)
[#1517](https://github.com/realm/SwiftLint/issues/1517)

* Add `multiline_arguments_brackets` opt-in rule to warn against multiline
function call arguments with surrounding brackets without newline.
[Cihat Gündüz](https://github.com/Dschee)
[#2306](https://github.com/realm/SwiftLint/issues/2306)

* Add `multiline_literal_brackets` opt-in rule to warn against multiline
literal arrays & dictionaries with surrounding brackets without newline.
[Cihat Gündüz](https://github.com/Dschee)
[#2306](https://github.com/realm/SwiftLint/issues/2306)

* Add `multiline_parameters_brackets` opt-in rule to warn against multiline
function definition parameters with surrounding brackets without newline.
[Cihat Gündüz](https://github.com/Dschee)
[#2306](https://github.com/realm/SwiftLint/issues/2306)

#### Bug Fixes

* Fix false positive in `nimble_operator` rule.
Expand Down
307 changes: 307 additions & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@
* [Missing Docs](#missing-docs)
* [Modifier Order](#modifier-order)
* [Multiline Arguments](#multiline-arguments)
* [Multiline Arguments Brackets](#multiline-arguments-brackets)
* [Multiline Function Chains](#multiline-function-chains)
* [Multiline Literal Brackets](#multiline-literal-brackets)
* [Multiline Parameters](#multiline-parameters)
* [Multiline Parameters Brackets](#multiline-parameters-brackets)
* [Multiple Closures with Trailing Closure](#multiple-closures-with-trailing-closure)
* [Nesting](#nesting)
* [Nimble Operator](#nimble-operator)
Expand Down Expand Up @@ -11091,6 +11094,95 @@ foo(



## Multiline Arguments Brackets

Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
--- | --- | --- | --- | --- | ---
`multiline_arguments_brackets` | Disabled | No | style | No | 3.0.0

Multiline arguments should have their surrounding brackets in a new line.

### Examples

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

```swift
foo(param1: "Param1", param2: "Param2", param3: "Param3")
```

```swift
foo(
param1: "Param1", param2: "Param2", param3: "Param3"
)
```

```swift
func foo(
param1: "Param1",
param2: "Param2",
param3: "Param3"
)
```

```swift
foo { param1, param2 in
print("hello world")
}
```

```swift
foo(
bar(
x: 5,
y: 7
)
)
```

```swift
AlertViewModel.AlertAction(title: "some title", style: .default) {
AlertManager.shared.presentNextDebugAlert()
}
```

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

```swift
foo(param1: "Param1", param2: "Param2",
param3: "Param3"
)
```

```swift
foo(
param1: "Param1",
param2: "Param2",
param3: "Param3")
```

```swift
foo(bar(
x: 5,
y: 7
)
)
```

```swift
foo(
bar(
x: 5,
y: 7
))
```

</details>



## Multiline Function Chains

Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
Expand Down Expand Up @@ -11207,6 +11299,118 @@ a.b {
## Multiline Literal Brackets
Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
--- | --- | --- | --- | --- | ---
`multiline_literal_brackets` | Disabled | No | style | No | 3.0.0
Multiline literals should have their surrounding brackets in a new line.
### Examples
<details>
<summary>Non Triggering Examples</summary>
```swift
let trio = ["harry", "ronald", "hermione"]
let houseCup = ["gryffinder": 460, "hufflepuff": 370, "ravenclaw": 410, "slytherin": 450]
```
```swift
let trio = [
"harry",
"ronald",
"hermione"
]
let houseCup = [
"gryffinder": 460,
"hufflepuff": 370,
"ravenclaw": 410,
"slytherin": 450
]
```
```swift
let trio = [
"harry", "ronald", "hermione"
]
let houseCup = [
"gryffinder": 460, "hufflepuff": 370,
"ravenclaw": 410, "slytherin": 450
]
```
```swift
_ = [
1,
2,
3,
4,
5, 6,
7, 8, 9
]
```
</details>
<details>
<summary>Triggering Examples</summary>
```swift
let trio = [↓"harry",
"ronald",
"hermione"
]
```
```swift
let houseCup = [↓"gryffinder": 460, "hufflepuff": 370,
"ravenclaw": 410, "slytherin": 450
]
```
```swift
let trio = [
"harry",
"ronald",
"hermione"↓]
```
```swift
let houseCup = [
"gryffinder": 460, "hufflepuff": 370,
"ravenclaw": 410, "slytherin": 450↓]
```
```swift
class Hogwarts {
let houseCup = [
"gryffinder": 460, "hufflepuff": 370,
"ravenclaw": 410, "slytherin": 450↓]
}
```
```swift
_ = [
1,
2,
3,
4,
5, 6,
7, 8, 9↓]
```
```swift
_ = [↓1, 2, 3,
4, 5, 6,
7, 8, 9
]
```
</details>
## Multiline Parameters
Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
Expand Down Expand Up @@ -11687,6 +11891,109 @@ class Foo {
## Multiline Parameters Brackets
Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
--- | --- | --- | --- | --- | ---
`multiline_parameters_brackets` | Disabled | No | style | No | 3.0.0
Multiline parameters should have their surrounding brackets in a new line.
### Examples
<details>
<summary>Non Triggering Examples</summary>
```swift
func foo(param1: String, param2: String, param3: String)
```
```swift
func foo(
param1: String, param2: String, param3: String
)
```
```swift
func foo(
param1: String,
param2: String,
param3: String
)
```
```swift
class SomeType {
func foo(param1: String, param2: String, param3: String)
}
```
```swift
class SomeType {
func foo(
param1: String, param2: String, param3: String
)
}
```
```swift
class SomeType {
func foo(
param1: String,
param2: String,
param3: String
)
}
```
```swift
func foo<T>(param1: T, param2: String, param3: String) -> T { /* some code */ }
```
</details>
<details>
<summary>Triggering Examples</summary>
```swift
func foo(↓param1: String, param2: String,
param3: String
)
```
```swift
func foo(
param1: String,
param2: String,
param3: String↓)
```
```swift
class SomeType {
func foo(↓param1: String, param2: String,
param3: String
)
}
```
```swift
class SomeType {
func foo(
param1: String,
param2: String,
param3: String↓)
}
```
```swift
func foo<T>(↓param1: T, param2: String,
param3: String
) -> T
```
</details>
## Multiple Closures with Trailing Closure
Identifier | Enabled by default | Supports autocorrection | Kind | Analyzer | Minimum Swift Compiler Version
Expand Down
3 changes: 3 additions & 0 deletions Source/SwiftLintFramework/Models/MasterRuleList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ public let masterRuleList = RuleList(rules: [
MarkRule.self,
MissingDocsRule.self,
ModifierOrderRule.self,
MultilineArgumentsBracketsRule.self,
MultilineArgumentsRule.self,
MultilineFunctionChainsRule.self,
MultilineLiteralBracketsRule.self,
MultilineParametersBracketsRule.self,
MultilineParametersRule.self,
MultipleClosuresWithTrailingClosureRule.self,
NestingRule.self,
Expand Down
Loading

0 comments on commit d7750b3

Please sign in to comment.