Rule request: Empty lines in function bodies
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
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.
Read:
An Empty Line is a Code Smell,
Adoption of a custom checkstyle rule
What would trigger?
// Notice empty line in the method body
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)
}
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing SwiftLint's existing rule implementations and tests to find the entry point for an opt-in rule that inspects empty lines inside function bodies. Use the triggering and non-triggering examples in this issue to define the expected behavior, and consider the rule complete when those cases are detected correctly without configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100