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

Clarify Rule: Use Swift's automatic enum values unless they map to an external source. #216

Merged
merged 2 commits into from
Mar 21, 2023

Conversation

teddy5518
Copy link
Contributor

@teddy5518 teddy5518 commented Mar 21, 2023

Summary

This PR fixes placement of swiftformat:disable redundantRawValues and swiftformat:enable redundantRawValues.

Reasoning

As discussed here, enum ErrorType: String' in WRONG is the one that needs to be implemented with swiftformat:disable redundantRawValuesandswiftformat:enable redundantRawValues` as it needs to be excepted from swiftformat rules.

And, enum Planet: Int needs to be reverted as before, because it is straightly following Swift's automatic enum values, and it does not contain any redundant raw values.

Please react with 👍/👎 if you agree or disagree with this proposal.

README.md Outdated
@@ -1804,10 +1804,12 @@ _You can enable the following settings in Xcode by running [this script](resourc

```swift
// WRONG
// swiftformat:disable redundantRawValues
Copy link
Member

Choose a reason for hiding this comment

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

Why is this "wrong"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@calda Are we talking "wrong" as comment "// WRONG"?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand why this needs both // WRONG and // swiftformat:disable redundantRawValues. Doesn't the SwiftFormat directive mean this is correct (e.g. we're manually indicating that these values should be preserved because they map to an external source)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was there even before I requested PR #216 and PR #215 . And, I thought it was there as it was not relying on Swift's automatic enum values. (Error could be coming from internal source.)

If you think otherwise then shouldn't line 1807 to 1812 (enum ErrorType) switched with 1841 to 1845 (enum ErrorType)?

Copy link
Contributor Author

@teddy5518 teddy5518 Mar 21, 2023

Choose a reason for hiding this comment

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

I'm not sure I understand why this needs both // WRONG and // swiftformat:disable redundantRawValues. Doesn't the SwiftFormat directive mean this is correct (e.g. we're manually indicating that these values should be preserved because they map to an external source)?

Oh, sorry I saw this after commenting as I was writing a comment when you posted yours.

I thought we were agreed to state it as wrong and make exception to show example of wrongdoings. Here is our previous chat.

Sorry, if I misunderstood your intention, in this case would it be better to just delete // swiftformat:disable redundantRawValues?

Copy link
Member

Choose a reason for hiding this comment

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

haha yeah I think removing the directive is fine, otherwise this may be confusing

Copy link
Contributor Author

@teddy5518 teddy5518 Mar 21, 2023

Choose a reason for hiding this comment

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

@calda Thank you for sharing your thoughts. Fixed it accordingly!

@@ -1854,7 +1856,6 @@ _You can enable the following settings in Xcode by running [this script](resourc

// RIGHT
// Relying on Swift's automatic enum values
// swiftformat:disable redundantRawValues
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
Contributor Author

@teddy5518 teddy5518 Mar 21, 2023

Choose a reason for hiding this comment

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

🙂

@calda calda merged commit 67391af into airbnb:master Mar 21, 2023
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