Navigation Menu

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-11830] SwiftFormat suggests turning types with #if‐wrapped properties into enumerations #338

Closed
swift-ci opened this issue Nov 22, 2019 · 2 comments
Labels
bug Something isn't working swift-format

Comments

@swift-ci
Copy link

Previous ID SR-11830
Radar None
Original Reporter SDGGiesbrecht (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee kpa (JIRA)
Priority Medium

md5: 9f8deb0542ab451d59b896ce48e8f474

Issue Description:

When run from Linux (at least), the following warning appears for the given source code.

replace struct 'Structure' with an enum when used as a namespace.

struct Structure {

  // ...

  #if canImport(AppKit)
      var native: NSSomething
  #elseif canImport(UIKit)
      var native: UISomething
  #endif

  // ...

}

I don’t know yet if only uncompiled sections hide members, or if all #if statements do.

@allevato
Copy link
Collaborator

We look at the properties inside the decl to see if it contains any that are instance variables, and if not, we suggest that the type is a "namespace" and should be an enum instead. In this case, it looks like we're not looking "through" IfConfigDecl blocks to pick up any that might be inside there, so if your type only contains properties inside such blocks, it'll trip this check incorrectly.

@swift-ci
Copy link
Author

Comment by Klaas Pieter Annema (JIRA)

This was resolved by #113

@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
Labels
bug Something isn't working swift-format
Projects
None yet
Development

No branches or pull requests

2 participants