diff --git a/Rules.md b/Rules.md index 16dc39536..49487df5e 100644 --- a/Rules.md +++ b/Rules.md @@ -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
Examples diff --git a/Sources/Examples.swift b/Sources/Examples.swift index 350b0616b..104269520 100644 --- a/Sources/Examples.swift +++ b/Sources/Examples.swift @@ -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 = """ diff --git a/Sources/OptionDescriptor.swift b/Sources/OptionDescriptor.swift index a19a32672..121bc3f18 100644 --- a/Sources/OptionDescriptor.swift +++ b/Sources/OptionDescriptor.swift @@ -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