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

[SR-11289] Break rule for generic where clause in swift-format #348

Closed
swift-ci opened this issue Aug 10, 2019 · 2 comments
Closed

[SR-11289] Break rule for generic where clause in swift-format #348

swift-ci opened this issue Aug 10, 2019 · 2 comments

Comments

@swift-ci
Copy link

Previous ID SR-11289
Radar None
Original Reporter kitasuke (JIRA User)
Type Improvement
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Improvement
Assignee None
Priority Medium

md5: 5e4d000558f77f1d06c1e68edf21a975

is duplicated by:

  • SR-11290 Break rule for where clause in swift-format

Issue Description:

I assume this is intended, but it would be nice to set `.break(.continue), .open` tokens for `where` keyword instead to follow format of Apple's documentation

https://docs.swift.org/swift-book/LanguageGuide/Generics.html#ID192

Input:

func allItemsMatch<C1: Container, C2: Container>(_ someContainer: C1, _ anotherContainer: C2) where C1.Item == C2.Item, C1.Item: Equatable {}

swift-format produces:

func allItemsMatch<C1: Container, C2: Container>(_ someContainer: C1, _ anotherContainer: C2) 
where C1.Item == C2.Item, C1.Item: Equatable {}

Expected:

func allItemsMatch<C1: Container, C2: Container>(_ someContainer: C1, _ anotherContainer: C2) 
  where C1.Item == C2.Item, C1.Item: Equatable 
{}

Submitted my draft PR about my ideas:
#33

@allevato
Copy link
Collaborator

Your assumption that this is intended is correct; we treat where clauses as being on "equal footing" as the original declaration, because of situations like these:

class SomeClass<T, U, V>:
  SomeSuperclass,
  SomeProtocol,
  SomeOtherProtocol
where
  T.SomeAssociatedType == Foo,
  U.SomeOtherThing == V
{
} 

This indentation clearly delimits the section of inheritances/conformances from generic constraints, whereas indenting the where keyword would blend them (which can be seen in the changes to the tests in your PRs), and also introduce an (IMO) unnecessary level of indentation in front of the entire section.

Since there's no "official/default/recommended" Swift style, if you'd like to continue pursuing your PRs then we're happy to explore alternative approaches, but since the current style applied by the formatter is being depended on by folks using it in production, any explicit style changes (rather than bug fixes) to that style will need to be placed behind a configuration option that is false by default.

@swift-ci
Copy link
Author

Comment by Yusuke Kita (JIRA)

If that's the case, I'm totally okay with current format.

I think adding a new option in the configuration would be an alternative approach. However, I would like to hold until we get more demand from others to avoid adding unuseful option. I'll close this ticket

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants