-
Notifications
You must be signed in to change notification settings - Fork 636
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
Allow user to customize additional variable names to be replaced by self with the strongifiedSelf rule #523
Open
krunk4ever
wants to merge
19
commits into
nicklockwood:main
Choose a base branch
from
krunk4ever:update-strongified-self
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4826cfe
Add additional variable names to exclude from strongifiedSelf
krunk4ever a0c1360
Update rule info
krunk4ever 7e3cb26
Update strongifiedSelf description
krunk4ever e12614b
Add test for strongSelf
krunk4ever 28470e2
Add strongifiedSelfIdentifiers option
krunk4ever 576a461
Use formatter options instead of hardcoding list
krunk4ever a99cba1
Add argument tests for strongifiedSelfIdentifiers
krunk4ever e3f5178
Update rules tests for when option is provided or missing for strongi…
krunk4ever 5364008
Update test manifest
krunk4ever d42fcca
Make test names clearer
krunk4ever 3fe0098
Update description for strongifiedSelf
krunk4ever 225dc96
List strongifiedSelfIdentifiers in strongifiedSelf rule option
krunk4ever 68131f1
Shorten strongifiedSelfIdentifiers to strongSelfIds
krunk4ever ad8294a
Update strongselfids description
krunk4ever 54da3b2
Shorten description to max of 80 characters
krunk4ever 099412d
Fix option name
krunk4ever d6a6258
Update help message for strongSelfIds to be the shortened version
krunk4ever a53b488
Update description
krunk4ever 5c604df
Don't define output when it's the same as input
krunk4ever File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't think this will work. It only replaces the identifier if it appears in an expression like
strongSelf = self
, but it won't replace any references tostrongSelf
in the subsequent code.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.
@nicklockwood, yeah, I also discussed this with my coworkers to see if autocorrect was the right thing to do here. there's actually 3 things that need to be autocorrected:
Example for number 3:
In the above example, we would also need to remove the trailing
?
afterself
:(2) and (3) both feel really complicated for autocorrection w/o full understanding of the code graph and would be probably better off with human intervention. However, we still found it to be useful for autocorrect to complete step (1) despite the fact it might leave the code uncompilable.
thoughts?
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.
is similar in complexity to what I already do for removing implicit self. It's certainly complicated because it requires an understanding of scope and tracking variable declarations and shadowing, but it's a local problem (i.e. it doesn't require knowledge of externally-defined symbols and their types) so it can be solved.
is probably too difficult since modifications from optional to non-optional may be nontrivial, but I also think it's a bad idea generally because the developer may have a good reason for referencing
self?
rather thanstrongSelf
and a formatter shouldn't second-guess that. However it wouldn't be hard to detect the user ofself
and not replacestrongSelf
in those cases.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.
Just doing 1) and leaving code non-compilable is not acceptable IMO. Now that SwiftFormat has fairly decent linting capability, it might make sense to introduce the concept of "lint-only" rules for cases like this, where it would warn but not actually replace the symbol.
But TBH, it would probably make more sense to make it a SwiftLint rule instead in that case.
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.
Yeah, we have a simple SwiftLint custom rule for detecting this for now:
If you have an idea of how to autocorrect for (2), that would be great! I can take a look at
removing implicit self
and see if I can mimic that behavior, but if you have pointers or have the bandwidth to add that, even better!