-
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
Add unused_capture_list rule #2719
Add unused_capture_list rule #2719
Conversation
Generated by 🚫 Danger |
] | ||
) | ||
|
||
private let captureListRegex = regex("^\\{\\h*\\[([^\\]]+)\\].*\\bin\\b") |
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.
any particular reason to use \h
here? although not common, the capture list could be in a new line
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.
ah, good point.
identifier: "unused_capture_list", | ||
name: "Unused Capture List", | ||
description: "Unused reference in a capture list should be removed.", | ||
kind: .lint, |
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.
can you add swiftVersion: .fourDotTwo
? SwiftSyntaxKind.closure
is only returned by SourceKit in 4.2+
} | ||
} | ||
|
||
private func identifierStrings(in file: File, byteRange: NSRange) -> [String] { |
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.
nitpick: this could return a Set<String>
They're reported as local variables inside the closure, but you'd need to be creative to figure out if it's a captured variable (i.e. check if the location is before the |
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.
Thanks for another great contribution, @daltonclaybrook! 🥇
Thanks for the contribution @daltonclaybrook, and this is indeed a useful rule, although there are some false positives (3/4 of the violations reported by OSSCheck are false positives). If we can't avoid those false positives, I think we should make this rule opt-in (disabled by default). |
@jpsim oh whoops, I guess I missed those warnings. I may have some time this afternoon to take a look at this. |
Resolves #2715
I'm using an
ASTRule
in order to find closures, but I was unable to find any first-class parsing support within SourceKitten for capture lists, so I am doing this with regex and string manipulation. Let me know if I missed something.