Skip to content
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

Merged
merged 2 commits into from
Sep 3, 2024
Merged

Add SwiftFormat void rule #288

merged 2 commits into from
Sep 3, 2024

Conversation

miguel-jimenez-0529
Copy link
Contributor

Summary

This PR replaces the SwiftLint void_return in favor to the SwiftFormat void rule in conjunction with the existing redundantVoidReturnType which cover the same functionality and additional rules described in the PR.

Reasoning

This is an effort to migrate all autocorrect rules to SwiftFormat

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`.
Copy link
Member

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

Copy link
Contributor Author

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
Comment on lines 3685 to 3690
struct Wrapper<T> { ... }
// WRONG
let wrapper = Wrapper<()>()

// RIGHT
let wrapper = Wrapper<Void>()
Copy link
Member

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.

Suggested change
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
Comment on lines 3699 to 3709
struct Resolver<T> {
func resolve(T) { ... }
}

let resolver = Resolver()

// WRONG
resolver.resolve(Void())

// RIGHT
resolver.resolve(())
Copy link
Member

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

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Member

@calda calda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@calda calda merged commit 6022593 into master Sep 3, 2024
5 checks passed
@calda calda deleted the mj-replace-void-rule branch September 3, 2024 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants