Skip to content

Commit

Permalink
Add nilinit option descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
rakuyoMo committed Apr 19, 2024
1 parent b63b803 commit 92dc6a8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ Remove/insert redundant `nil` default value (Optional vars are nil by default).

Option | Description
--- | ---
`--nilinit` | Explicit self: "insert", "remove" (default)
`--nilinit` | "remove" (default) redundant nil or "insert" missing nil

<details>
<summary>Examples</summary>
Expand Down
10 changes: 5 additions & 5 deletions Sources/Examples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -564,17 +564,17 @@ private struct Examples {
let foo: Int? = nil
```
```diff
// doesn't affect non-nil initialization
var foo: Int? = 0
```
`--nilinit insert`
```diff
- var foo: Int?
+ var foo: Int? = nil
```
```diff
// doesn't affect non-nil initialization
var foo: Int? = 0
```
"""

let redundantObjc = """
Expand Down
6 changes: 6 additions & 0 deletions Sources/OptionDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,12 @@ struct _Descriptors {
fromArgument: { FormatTimeZone(rawValue: $0) },
toArgument: { $0.rawValue }
)
let nilInitType = OptionDescriptor(
argumentName: "nilinit",
displayName: "Nil init type",
help: "\"remove\" (default) redundant nil or \"insert\" missing nil",
keyPath: \.nilInitType
)

// MARK: - Internal

Expand Down

0 comments on commit 92dc6a8

Please sign in to comment.