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: Empty and comment lines in function bodies #2065

Closed
2 tasks done
driver733 opened this issue Feb 25, 2018 · 0 comments
Closed
2 tasks done

Rule request: Empty and comment lines in function bodies #2065

driver733 opened this issue Feb 25, 2018 · 0 comments

Comments

@driver733
Copy link

driver733 commented Feb 25, 2018

New Issue Checklist

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

Rule Request

Description

Each method should fulfill only one goal, therefore, it should not contain any "parts". If you see that the code blocks in your method beg for logical separation - do not separate these blocks using an empty line, instead, refactor your method by splitting it into several ones or create a new class.

In addition, 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.

Read: An Empty Line is a Code Smell, Adoption of a custom checkstyle rule

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 method documentation. I will also put an empty line below.

        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.

@driver733 driver733 changed the title Rule request: Empty and in-line comment lines in function bodies Rule request: Empty and comment lines in function bodies Feb 25, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 25, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 25, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 25, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 25, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 25, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 25, 2018
Replaced loop with flatMap
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 25, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
Replaced loop with flatMap
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 26, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Feb 28, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Mar 1, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Mar 1, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Mar 1, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Mar 1, 2018
driver733 pushed a commit to driver733/SwiftLint that referenced this issue Mar 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants