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

False positive in unused_closure_parameter #1979

Closed
jpsim opened this Issue Dec 21, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@jpsim
Collaborator

jpsim commented Dec 21, 2017

New Issue Checklist

Bug Report

Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint --path test.swift
Linting Swift files at path test.swift
Linting 'test.swift' (1/1)
/Users/jsimard/Downloads/test.swift:3:5: warning: Unused Closure Parameter Violation: Unused parameter "manager" in a closure should be replaced with _. (unused_closure_parameter)
Done linting! Found 1 violation, 0 serious in 1 file.

Environment

  • SwiftLint version (run swiftlint version to be sure)?

0.24.0

  • Installation method used (Homebrew, CocoaPods, building from source, etc)?

Homebrew

  • Paste your configuration file:

None.

None.

  • Which Xcode version are you using (check xcode-select -p)?

/Applications/Xcode-9.2.app/Contents/Developer

  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.
import Foundation

({ (manager: FileManager) in
  print(manager)
})(FileManager.default)

Also, as reported by @irace:

image

@jpsim jpsim added the bug label Dec 21, 2017

@irace

This comment has been minimized.

Show comment
Hide comment
@irace

irace Dec 21, 2017

irace commented Dec 21, 2017

@jpsim

This comment has been minimized.

Show comment
Hide comment
@jpsim

jpsim Dec 21, 2017

Collaborator

So SourceKit is returning some BS with closures of this format. Here's what it thinks the name of the closure is: ({ (manager: FileManager) in\n print(manager)\n}), and the body is (FileManager.default).

Looking into making a workaround.

Collaborator

jpsim commented Dec 21, 2017

So SourceKit is returning some BS with closures of this format. Here's what it thinks the name of the closure is: ({ (manager: FileManager) in\n print(manager)\n}), and the body is (FileManager.default).

Looking into making a workaround.

@marcelofabri

This comment has been minimized.

Show comment
Hide comment
@marcelofabri

marcelofabri Dec 21, 2017

Collaborator

This would be way easier/more reliable if we SourceKit returned closures in the structure (https://bugs.swift.org/browse/SR-6116). I started implementing it a few months ago, but it looks like I lost my WIP branch ¯_(ツ)_/¯

Collaborator

marcelofabri commented Dec 21, 2017

This would be way easier/more reliable if we SourceKit returned closures in the structure (https://bugs.swift.org/browse/SR-6116). I started implementing it a few months ago, but it looks like I lost my WIP branch ¯_(ツ)_/¯

jpsim added a commit that referenced this issue Dec 21, 2017

Fix false positives in `unused_closure_parameter` rule
when closure is wrapped in parentheses. Fixes #1979.

Definitely not elegant, but it should help.

@jpsim jpsim closed this in #1980 Dec 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment