When ignore_comment_only_lines is true SwiftLint also ignores closing bracket and empty lines
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
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-rules
to 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)
}
}
}
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
Reproduce the report with the shown SwiftLint configuration and the sample Swift code, using swiftlint lint --no-cache --use-stdin --enable-all-rules. Start at the file_length rule and trace how ignore_comment_only_lines counts lines. Done means the option ignores comment-only lines without also ignoring empty lines or lines containing only closing brackets, with the reported count matching that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100