-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
unused_closure_parameter autocorrect is too eager #1175
Comments
This is kind of hard, because if we always retain the type, I'd say in at least 95% of the cases it could be removed. On the other hand, |
Does swiftlint actually work out whether the closure parameter types can be removed? If it doesn't, the correct autocorrection behaviour is to have leave the type annotation. If it's not even supplied then that's a different story. func plainFunction(closure: (Int) -> Void) {
// stuff
}
plainFunction { (param: Int) -> Void in // this will be corrected to { (_: Int) -> Void in }
// stuff
}
plainFunction { param -> Void in // this will be corrected to { _ -> Void in }
// stuff
} |
@allen-zeng Do you want to try to submit a PR? |
Sure! I'll see what I can do :) |
I took a look at this today and the problem is that {
"key.nameoffset": 0,
"key.typename": "Int",
"key.length": 8,
"key.name": "int",
"key.kind": "source.lang.swift.decl.var.parameter",
"key.namelength": 0,
"key.offset": 25
} We could however check if there's a |
Yeah I noticed that and thought it was weird. I'm guessing this is a bug in SourceKitten? I've just got around making the changes, while all the tests pass in Xcode, they don't when I run |
If there's a bug here, it's likely in SourceKit rather than SourceKitten, which acts mostly just as a proxy in this situation. I look forward to seeing your patch @allen-zeng! |
Pull request created :) I do have a problem when running
I'm not entirely sure what's going on there, do you have the same problem @marcelofabri ? |
Try deleting |
Yep that worked! In that case it's probably better to update Makefile so that |
Probably |
I'll just add |
Actually there's a |
@marcelofabri I've created this pull request to run clean before docker test, can you take a look as well? |
Closed in #1247 |
When autocorrecting
unused_closure_parameter
, swiftlint also removes the type annotation. This isn't going to work in a situation where the type annotation is necessary, for example, when generics needs to use it for type inference. That is, the autocorrection will make the code fail to compile.Autocorrect replaces the entire parameter list with an underscore, which isn't valid syntax. It should instead retain the type, and replace the name with an underscore:
The text was updated successfully, but these errors were encountered: