-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
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.