-
Notifications
You must be signed in to change notification settings - Fork 93
Place member attributes on methods and variables instead of class #330
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
base: master
Are you sure you want to change the base?
Place member attributes on methods and variables instead of class #330
Conversation
c0d2381 to
756faef
Compare
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.
Thank you for the PR! I left a comment.
Please let me request a review to other collaborators. I'm not fully familiar with the current specifications related to this change.
sidepelican
left a comment
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.
It's better than before.
| let shouldFilterMemberAttributes = item is MethodModel || item is VariableModel | ||
|
|
||
| if shouldFilterMemberAttributes { | ||
| let memberAttributes = ["@available", "@objc", "@discardableResult"] |
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.
Why were only these three chosen?
If using filters, you'll need to cover all combinations of Model types and attributes.
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.
It's the same discussed here
We're thinking about we don't need to filter because there's no use case where the attribute should be on class scope
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.
I'm not filtering anymore, assuming the every attribute must be nested with the method/var
| let availableAttr = (attributes ?? []) | ||
| .filter { $0.contains("@available") } | ||
| .joined(separator: "\n") | ||
| let availableStr = availableAttr.isEmpty ? "" : "\(1.tab)\(availableAttr)\n" | ||
|
|
||
| let objcAttr = (attributes ?? []) | ||
| .filter { $0.contains("@objc") } | ||
| .joined(separator: " ") | ||
| let objcStr = objcAttr.isEmpty ? "" : "\(objcAttr) " |
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.
It would be endless to add processing for each attribute individually.
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.
I agree, but the problem is that the @available attribute is usually above the method/variable, etc.
@objc, @discardableResult remains in line with the declaration.
What is your suggestion for these cases? Could we handle only the @available attribute?
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.
changed to handle only @available, I don't remember if swift has another use case where the attribute stay above
|
Question: was expecting this |
955d020 to
e2df490
Compare
|
Actually, The following code won't compile, right? struct S {
@available(macOS 99, *) // stored properties cannot be marked potentially unavailable with '@available'
var a: Int
} |
This is something I'm fine with either way. |
Description
Fixes #211
Member attributes like
@available,@objc, and@discardableResultare now placed on methods and variables instead of the mock class.Changes
attributesfield toMethodModelandVariableModel@availableabove and any other inlineTesting
MemberAttributeTestscovering attributes on methods and variables