SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

When ignore_comment_only_lines is true SwiftLint also ignores closing bracket and empty lines

Open ashumeika-mkodo opened this issue 2 years ago • 1 comments

New Issue Checklist

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 version to 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 use swiftlint 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)
        }
    }
}

ashumeika-mkodo avatar Jan 25 '23 14:01 ashumeika-mkodo

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.

SimplyDanny avatar Jan 28 '23 12:01 SimplyDanny