TypeBodyLengthRule should not count conditional directives
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
type_body_length rule counts lines with conditional directives as lines of code, which is not correct. Example:
class Test {
func foo() {
#if DEBUG
print("test")
#endif
}
}
How many lines are in foo function? swiftlint thinks there are 5 lines, but there's 3 lines of code.
This rule ignores comments and whitespaces already since they are not an actual lines of code (#369). So, why a conditional directives does count?
I believe it's an incorrect rule behaviour.
Environment
- SwiftLint version (run
swiftlint versionto be sure)?
0.39.1 - Installation method used (Homebrew, CocoaPods, building from source, etc)?
CocoaPods
swiftlint ouptut for sample above:
$ pbpaste | swiftlint lint --no-cache --use-stdin --enable-all-rules
Loading configuration from '.swiftlint.yml'
<nopath>:1:1: warning: Type Body Length Violation: Type body should span 3 lines or less excluding comments and whitespace: currently spans 4 lines (type_body_length)
using sample yml:
type_body_length: 3
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 with the TypeBodyLengthRule entry point and reproduce the reported result using the SwiftLint stdin command and sample configuration from the issue. The work is done when conditional directives are excluded from the counted lines while comments and whitespace remain excluded, and the sample reports the expected three lines.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100