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

[swift] UnavailableFunction Swift rule #1882

Merged
merged 12 commits into from
Aug 14, 2019

Conversation

tomidelucca
Copy link
Contributor

@tomidelucca tomidelucca commented Jun 21, 2019

Before submitting a PR, please check that:

  • The PR is submitted against master. The PMD team will merge back to support branches as needed.
  • ./mvnw clean verify passes. This will build and test PMD, execute PMD and checkstyle rules. Check this for more info

PR Description:

We are adding a second Java rule for Swift. This rule checks that an availability modifier was added to any function that's unimplemented.

Here is an example:

class ViewController: UIViewController {
  public required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

This is a perfectly valid piece of Swift code, but if you call the init?(coder:) initializer of the ViewController class the app will crash due to the fatalError(). This initializer needs to be implemented to extend UIViewController, so removing the method will not work.

This rule checks that you add the @available(*, unavailable) attribute to the function and initializer declarations. With this attribute present, the function will not be able to be called, but the compiler will see it as implemented so there won't be any compile errors.

The expected non-triggering version of the code snippet looks like this:

class ViewController: UIViewController {
  @available(*, unavailable)
  public required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
}

@pmd-test
Copy link

1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

@adangel adangel added this to the 7.0.0 milestone Jun 30, 2019
Tomi De Lucca and others added 2 commits August 4, 2019 14:23
Co-Authored-By: Juan Martín Sotuyo Dodero <juansotuyo@gmail.com>
@jsotuyod
Copy link
Member

@tomidelucca please rebase, #1877 has now been merged

@tomidelucca
Copy link
Contributor Author

@jsotuyod done!

@jsotuyod jsotuyod added the a:new-rule Proposal to add a new built-in rule label Aug 14, 2019
@jsotuyod jsotuyod merged commit 6281f81 into pmd:pmd/7.0.x Aug 14, 2019
jsotuyod added a commit that referenced this pull request Aug 14, 2019
@adangel adangel mentioned this pull request Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:new-rule Proposal to add a new built-in rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants