swift-spyable icon indicating copy to clipboard operation
swift-spyable copied to clipboard

Inherit protocol modifiers

Open bradleymackey opened this issue 2 years ago • 5 comments

  • Allows protocols with any modifiers, like public, fileprivate etc. to inherit this access on the spy and all the generated members. This is done by taking the modifiers on the original protocol definition and applying it to all generated members.
    • private protocol members will inherit an access level fileprivate instead. A protocol declared private at file-scope is effectively treated as fileprivate. This access level on the generated members is required to satisfy the protocol requirements
  • Generate an init with the same access level, allowing the spy to be created outside of the current module (as the default init level is internal).
  • Adds tests for all use cases.
  • Closes #73 , fixes #72

Thanks for the great library! This is the best spy/mock generator out there atm.

bradleymackey avatar Jan 19 '24 11:01 bradleymackey

Hi @bradleymackey, welcome to the project!

Thank you for your contribution! I'll try to review it over the weekend! 🙌

Matejkob avatar Jan 19 '24 17:01 Matejkob

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 96.92%. Comparing base (288c860) to head (13b69a5). Report is 104 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #80      +/-   ##
==========================================
+ Coverage   96.69%   96.92%   +0.23%     
==========================================
  Files          17       18       +1     
  Lines         695      748      +53     
==========================================
+ Hits          672      725      +53     
  Misses         23       23              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 19 '24 17:01 codecov[bot]

Hey @Matejkob could you merge this improvement by any chance?

damian-kolasinski avatar May 19 '24 09:05 damian-kolasinski

Oops, this one fell off my radar, apologies for not addressing the feedback as requested. I'm using Mockolo now for my personal projects as it has a lot of features I need anyway with a bit more control over certain aspects of the mock generation.

I'll see about having a look at addressing these improvements in a week or so, but no promises as I may be a little busy.

bradleymackey avatar May 19 '24 13:05 bradleymackey

I would love to see this implemented because i am facing exactly the same issue. Is there any effort any time soon to merge this? :)

armintelker avatar Aug 05 '24 21:08 armintelker

Hello! Do we have any updates on this? When will the @Spyable create a public class?

KonDouvris avatar Nov 27 '24 15:11 KonDouvris

Thank you so much @bradleymackey, for your hard work on this feature! Your approach of modifying each node individually was a great step forward and really helped shape the direction of this functionality.

I’m closing this PR in favor of a new implementation (#130) that uses a syntax rewriter to handle access level inheritance. This simplifies the logic and ensures consistent behavior for all declaration members.

Your contribution was invaluable, and I truly appreciate the effort you put into this. Looking forward to more contributions from you in the future! 😊

Matejkob avatar Nov 30 '24 16:11 Matejkob

Hi @damian-kolasinski, @armintelker, @KonDouvris! Thank you for your patience and for highlighting the importance of this feature. I’ve created a new PR (#130 ) that implements access level inheritance using a syntax rewriter, ensuring consistent behavior across all members.

I’m planning to merge it in 2/3 days to allow the community some time to review and provide feedback. I’d love to hear your thoughts or suggestions on the new implementation before it’s finalized! Your input is always appreciated. 😊

Thanks again for your support and enthusiasm for this project!

Matejkob avatar Nov 30 '24 16:11 Matejkob