SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Validate that self is only used in escaping closures and conflicts

Open jpsim opened this issue 10 years ago • 16 comments

Use of self should be limited to escaping closures and scopes in which other declarations conflict.

jpsim avatar May 28 '15 22:05 jpsim

Counterpart of #321

scottrhoyt avatar Feb 03 '16 21:02 scottrhoyt

:+1:

eneko avatar Feb 03 '16 22:02 eneko

Love this. It would make searching for ref-cycles quiet a bit easier... :-)

diederich avatar Oct 05 '17 01:10 diederich

I could find the "explicit_self" rule but I couldn't find the identifier for this one.

Anyone could help me with finding it ?

Thanks!

charleyfromage avatar Nov 06 '18 15:11 charleyfromage

Anyone could help me with finding it ?

Doesn't exist yet. If anyone would like to build this rule, please go ahead!

jpsim avatar Nov 28 '18 04:11 jpsim

Any update on this?

ptrkstr avatar Aug 06 '20 06:08 ptrkstr

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

stale[bot] avatar Nov 08 '20 01:11 stale[bot]

Reopening, as there is still demand for this rule based on #3579 and prior comments on 2020.

sethfri avatar May 02 '21 21:05 sethfri

Would love to see that implemented.

pronebird avatar Jul 16 '21 10:07 pronebird

Any status update on this "implicit_self" rule inclusion? 🤔

Thanks

YannickGagnon avatar Oct 29 '21 13:10 YannickGagnon

bump - my team would find this rule to be super useful ❤️

lizjakubowski avatar Apr 29 '22 18:04 lizjakubowski

Bumptiybumpbump.

Any status updates on this issue? I think we all want it ❤️

mqln avatar Jun 07 '22 15:06 mqln

Any updates on this?

amadeu01 avatar Jul 07 '22 12:07 amadeu01

Has this been implemented already? I would love to have this rule in SwiftLint!

TripwireNL avatar Aug 31 '22 08:08 TripwireNL

hello, bump any updates on the concerns/challenges of implementing this?

acicartagena avatar Nov 06 '22 22:11 acicartagena

Bumpbumpbump part 2?

mqln avatar Dec 06 '22 12:12 mqln

Bump. FYI https://github.com/apple/swift-evolution/blob/main/proposals/0365-implicit-self-weak-capture.md

romanmazeev avatar Apr 03 '23 14:04 romanmazeev

I've implemented parts for this rule in #4911. As mentioned there, what's missing ~~are two cases~~ is one case:

  • ~~Weakly captured self with explicit unwrapping according to SE-0365~~
  • Implicit self in classes when the closure isn't @escaping

~~These~~ It can be implemented in a later step (probably as a separate Analyzer rule). I didn't want to make the first implementation overly complex and rather gather your feedback on other cases I might have missed.

Please have a look into the PR and let me know which other test cases you can think of, what I've missed or what doesn't work like the rule assumes!

SimplyDanny avatar Apr 20 '23 10:04 SimplyDanny

Closing this as completed. The remaining part "implicit self in classes when the closure isn't @escaping" is requested by #4964.

SimplyDanny avatar May 05 '23 19:05 SimplyDanny