Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeBodyLengthRule should not count conditional directives #3139

Open
2 tasks done
Sega-Zero opened this issue Mar 6, 2020 · 3 comments
Open
2 tasks done

TypeBodyLengthRule should not count conditional directives #3139

Sega-Zero opened this issue Mar 6, 2020 · 3 comments
Labels
enhancement Ideas for improvements of existing features and rules.

Comments

@Sega-Zero
Copy link
Contributor

New Issue Checklist

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 version to 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
@stale
Copy link

stale bot commented Nov 8, 2020

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

@stale stale bot added the wontfix Issues that became stale and were auto-closed by a bot. label Nov 8, 2020
@Sega-Zero
Copy link
Contributor Author

commenting. still reproducing this

@stale stale bot removed the wontfix Issues that became stale and were auto-closed by a bot. label Nov 12, 2020
@stale
Copy link

stale bot commented Jan 11, 2021

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

@stale stale bot added the wontfix Issues that became stale and were auto-closed by a bot. label Jan 11, 2021
@stale stale bot closed this as completed Jan 18, 2021
@jpsim jpsim reopened this Feb 23, 2021
@jpsim jpsim added enhancement Ideas for improvements of existing features and rules. and removed wontfix Issues that became stale and were auto-closed by a bot. labels Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

No branches or pull requests

2 participants