SwiftLint
SwiftLint copied to clipboard
When ignore_comment_only_lines is true SwiftLint also ignores closing bracket and empty lines
New Issue Checklist
- [x] Updated SwiftLint to the latest version
- [x] I searched for existing GitHub issues
Describe the bug
I want to update file_legth rule to set true for ignore_comment_only_lines but it seems that it starts ignoring not only comments but also empty lines as well as lines with closing bracket only, which is unexpected judging by the name of the setting.
Environment
- SwiftLint version (run
swiftlint versionto be sure)? 0.50.3 - Installation method used (Homebrew, CocoaPods, building from source, etc)? CocoaPods
- Paste your configuration file:
only_rules:
- file_length
excluded:
- Pods
file_length:
ignore_comment_only_lines: true
warning: 1
-
Are you using nested configurations? No
-
Which Xcode version are you using (check
xcodebuild -version)? Xcode 14.2 Build version 14C18 -
Do you have a sample that shows the issue? Run
echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rulesto quickly test if your example is really demonstrating the issue. If your example is more complex, you can useswiftlint lint --path [file here] --no-cache --enable-all-rules.
Next code produces:
File Length Violation: File should contain 1 lines or less excluding comments and whitespaces: currently contains 8 (file_length)
However, this code has no comments and it's 15 lines long
struct Coffee {
let size: Int
}
class CoffeeShop {
func makeCoffee(large: Bool) -> Coffee {
if large {
return .init(size: 400)
} else {
return .init(size: 200)
}
}
}
Yes, the option ignores comments, empty lines and closing braces. I'm not sure which of them are unintentional. With a different name of the option like ignore_superficial_lines you can argue that ignoring these lines is okay as they do not contain any logic and are thus insignificant when measuring the number of lines in a file as a metric for complexity or some other category.