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

Rule request: add unavailable to unimplemented function #2127

Closed
2 tasks done
marcelofabri opened this issue Mar 30, 2018 · 1 comment
Closed
2 tasks done

Rule request: add unavailable to unimplemented function #2127

marcelofabri opened this issue Mar 30, 2018 · 1 comment
Labels
rule-request Requests for a new rules.

Comments

@marcelofabri
Copy link
Collaborator

New Issue Checklist

Rule Request

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

It's common to add unimplemented methods just to fill protocol/init requirements. For example, if you don't use Interface Builder and create an UIView subclass overriding init, you'll be asked to implement init?(coder:). Xcode suggests a fix-it that adds an implementation with a fatalError .

In addition to the fatalError, one can also mark the method with @available(*, unavailable) to avoid someone from calling directly. It's just an extra safety net.

I'm not sure if we should trigger a warning for every method that only contains a fatalError inside or only the ones with the default template. Also not sure about protocols/overrides.

  1. Provide several examples of what would and wouldn't trigger violations.
// would trigger
public required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

// wouldn't trigger
@available(*, unavailable)
public required init?(coder aDecoder: NSCoder) {
     fatalError("init(coder:) has not been implemented")
}
  1. Should the rule be configurable, if so what parameters should be configurable?

No.

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md for guidelines on when to mark a
    rule as opt-in.

Probably opt-in.

@marcelofabri marcelofabri added the rule-request Requests for a new rules. label Mar 30, 2018
@marcelofabri marcelofabri changed the title Rule request: add unavailable to implemented function Rule request: add unavailable to unimplemented function Apr 6, 2018
@quinntaylor
Copy link
Contributor

Thanks for implementing this rule! Follow-up issue: #3374

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

No branches or pull requests

2 participants