Skip to content

Rule Request: No Empty Function #5615

@Ueeek

Description

@Ueeek

New Issue Checklist

New rule request

A Function body should not be empty. Otherwise, show a warning.

An empty function, init and deinit can harm readability and lead to confusion because readers need to guess whether it's intentional or not.
Developers should put a comment to explain why the function/ init / deinit body is empty.

SonarLint for Swift and ESLint have the same rule.
SwiftLint can be better by having this rule.

Triggering and Non-Triggering

Triggering:
func f1 () {}

func f2 () {
}

// Comment
func f3 () {}

init() {}

deinit {}
Non-Triggering
func f4 () {
    let s = "xyz"
}

func f5 () { /* Comment*/  }

func f6() {
    // Comment
}

init() { /* comment */ }

deinit { /* comment */ }

Just so you know, this behavior is the same as SonarLint and ESLint.

Should be configurable?

No parameter to configure.

Should be opt-in?

In my opinion, this rule should be "opt-in rule" since there is no consensus, though it's active by default in SonarLint and ESLint.
Got feed back, and change to default.

If this rule makes sense, I will work for this!
Thanks.

Future enhancement

We can implement rules for closures and initializers as well.
But, they should be implemented as separate rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssue to be taken up by new contributors yet unfamiliar with the project.rule-requestRequests for a new rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions