Skip to content

Rule request: Comment lines in function bodies #2077

Open
@driver733

Description

New Issue Checklist

  • Updated SwiftLint to the latest version
  • I searched for existing GitHub issues

Rule Request

Description

The code, in my opinion, should not have in-line comments. If any kind of explanations is needed, it has to be put in the method or class documentation. Furthermore, if your code requires comments, then it might be necessary to refactor it, so that it would be self-explainatory.

What would trigger?

internal func exceedsLineCountExcludingCommentsAndWhitespace(_ start: Int, _ end: Int, _ limit: Int) -> (Bool, Int) {
        guard end - start > limit else {
            return (false, end - start)
        }
        // I will put this here instead of putting in the method doc, where it belongs.
        let count = end - start - numberOfCommentAndWhitespaceOnlyLines(startLine: start, endLine: end)
        return (count > limit, count)
    }

What would not trigger?

internal func exceedsLineCountExcludingCommentsAndWhitespace(_ start: Int, _ end: Int, _ limit: Int) -> (Bool, Int) {
        guard end - start > limit else {
            return (false, end - start)
        }
        let count = end - start - numberOfCommentAndWhitespaceOnlyLines(startLine: start, endLine: end)
        return (count > limit, count)
    }

Configurable?

The rule should not be configurable.

Opt-in or enabled?

This rule could be a personal preference or coding style from various individuals, so it could be kept as opt-in.

Metadata

Assignees

No one assigned

    Labels

    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