-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SwiftFormat void rule #288
Conversation
README.md
Outdated
@@ -3677,6 +3677,39 @@ _You can enable the following settings in Xcode by running [this script](resourc | |||
|
|||
</details> | |||
|
|||
* <a id='generic-void'></a>(<a href='#generic-void'>link</a>) **Avoid using `()` as a generic type**. Prefer `Void`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of saying "Avoid using ()
as a generic type" maybe we should say "Avoid using ()
as a type"
e.g. the rule would convert let result: ()
to let result: Void
(right?) but that's not covered by the "generic type" wording here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, let me update it
README.md
Outdated
struct Wrapper<T> { ... } | ||
// WRONG | ||
let wrapper = Wrapper<()>() | ||
|
||
// RIGHT | ||
let wrapper = Wrapper<Void>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we use Result
instead. Result<Void, Error>
is pretty common.
struct Wrapper<T> { ... } | |
// WRONG | |
let wrapper = Wrapper<()>() | |
// RIGHT | |
let wrapper = Wrapper<Void>() | |
// WRONG | |
let result: Result<(), Error> | |
// RIGHT | |
let result: Result<Void, Error> |
README.md
Outdated
struct Resolver<T> { | ||
func resolve(T) { ... } | ||
} | ||
|
||
let resolver = Resolver() | ||
|
||
// WRONG | ||
resolver.resolve(Void()) | ||
|
||
// RIGHT | ||
resolver.resolve(()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use Result
here as well
struct Resolver<T> { | |
func resolve(T) { ... } | |
} | |
let resolver = Resolver() | |
// WRONG | |
resolver.resolve(Void()) | |
// RIGHT | |
resolver.resolve(()) | |
let completion: (Result<Void, Error>) -> Void | |
// WRONG | |
completion(.success(Void())) | |
// RIGHT | |
completion(.success(())) |
@@ -6,7 +6,6 @@ only_rules: | |||
- legacy_constructor | |||
- legacy_nsgeometry_functions | |||
- unused_optional_binding | |||
- void_return # TODO: Replace with SwiftFormat void rule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
Summary
This PR replaces the SwiftLint
void_return
in favor to the SwiftFormatvoid
rule in conjunction with the existingredundantVoidReturnType
which cover the same functionality and additional rules described in the PR.Reasoning
This is an effort to migrate all autocorrect rules to SwiftFormat