Open sindresorhus opened 4 years ago
A good configuration option would be to allow it to only apply to imported sources. That way developers can still use implicitly unwrapped options as they are intended to be used, that is, without any callsite unwrap.
This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!
Please keep it open.
This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!
Please keep it open.
New Issue Checklist
New rule request
Many of Apple's API's export "implicitly unwrapped optionals" instead of plain optionals. Usually because those APIs doesn't yet have null annotations. This is a footgun as Swift will not force you to properly unwrap it, which often cause crashes in production.
One example is
EKCalendarItem#title
, which exportsvar title: String! { get set }
. It's very easy to just use it directly asevent.title
instead of doingevent.title ?? ""
or guard/if.It would be great to have a rule that forces you to explicitly unwrap "implicitly unwrapped optionals" from imported frameworks. I don't think it should trigger on "implicitly unwrapped optionals" in the same file as that's usually intentional.
Some relevant discussion: https://forums.swift.org/t/disable-objc-bridging-as-implicitly-unwrapped-optionals/21966
Would trigger:
Wouldn't trigger:
No
I would make it default as it helps catch a lot of potential crashes in production.
This should really be an opt-in warning in Swift, but it doesn't look like that will happen anytime soon: