Skip to content

Conversation

@luizgustavo09
Copy link

Description

Fixes #325 #211

When generating mocks for protocols with methods that have @available attributes, mockolo was incorrectly placing the @available on the entire mock class instead of on the specific method.

Changes

  • Added attributes field to MethodModel to store method-level attributes
  • Modified MethodTemplate to render @available attributes above each method
  • Updated SwiftSyntaxExtensions to filter out @available from non-init methods when collecting class-level attributes
  • Preserved existing behavior for @available on variables and initializers (remain on class since I'm not sure where they should be)

Testing

  • All existing tests pass (129/129)

@CLAassistant
Copy link

CLAassistant commented Nov 28, 2025

CLA assistant check
All committers have signed the CLA.

@luizgustavo09 luizgustavo09 marked this pull request as ready for review November 28, 2025 14:21
@luizgustavo09 luizgustavo09 force-pushed the fix-available-on-function branch from 38026ec to 70d7fc3 Compare November 28, 2025 14:30
Comment on lines +229 to +237
if isNonInitMethod {
// For non-init methods, only add non-@available attributes to class
if !attrDesc.contains("@available") {
attributeList.append(attrDesc)
}
} else {
// For vars, inits, etc., add all attributes to class
attributeList.append(attrDesc)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This approach is dedicated to @available attribute.
Please consider other attributes like discardableResult and objc.

I believe other models like VariableModel should also inherit attribute from corresponding mockable's members.
(I am not familiar with current specification around attributes; why attributes of property or method are consolidated to that of class.)

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, that makes sense. I'll extend the implementation to cover these scenarios. Thanks for the review.
If you have another one scenario not covered feel free to comment

Copy link
Author

Choose a reason for hiding this comment

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

I just opened a new pr, could you look that one?
756faef

@sidepelican
Copy link
Collaborator

There are too many issues.
We don't welcome low-quality PRs from LLMs.

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.

@available attribute incorrectly placed on class instead of method

4 participants