Skip to content
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 force_unwrapping when returning collection from function #2042

Closed
2 tasks done
marcelofabri opened this issue Feb 10, 2018 · 1 comment
Closed
2 tasks done
Labels
bug Unexpected and reproducible misbehavior.

Comments

@marcelofabri
Copy link
Collaborator

New Issue Checklist

Bug Report

Complete output when running SwiftLint, including the stack trace and command used
$ echo "func foo() -> [AnyHashable: Any]\!" | swiftlint lint --no-cache --use-stdin --enable-all-rules 
Loading configuration from '.swiftlint.yml'
<nopath>:1:33: warning: Force Unwrapping Violation: Force unwrapping should be avoided. (force_unwrapping)

Environment

  • SwiftLint version (run swiftlint version to be sure)? 0.24.2
  • Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew
  • Paste your configuration file:
opt_in_rules:
  - force_unwrapping
  • Are you using nested configurations?
    If so, paste their relative paths and respective contents. No
  • Which Xcode version are you using (check xcode-select -p)? 9.2
  • 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.
// This triggers a violation:
func foo() -> [AnyHashable: Any]!
func bar() -> [Int]!
@Coeur
Copy link

Coeur commented Feb 28, 2018

If the rule force_unwrapping doesn't trigger a violation for return types, then I can declare:

extension Optional {
    var forceUnwrapped: Wrapped! {
        return self
    }
}

Then I replace all the foo! with foo.forceUnwrapped and SwiftLint will never trigger the force_unwrapping rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected and reproducible misbehavior.
Projects
None yet
Development

No branches or pull requests

2 participants