7

Current SwiftLint rules:

file_length:
  warning: 800
  error: 1500

The error

enter image description here

I followed this answer but the error doesn't go away

// swiftlint:disable force_cast

import UIKit

class MyClass: UIViewController {

}

// swiftlint:enable force_cast

How can I ignore SwiftLint rules in certain file?

Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
  • huh, 800 is a pretty big number for just a warning limit. – Sulthan Mar 23 '20 at 17:29
  • I inherited the project from someone else. I thought it was too low. What do you think the warning limit should be? – Lance Samaria Mar 23 '20 at 17:30
  • 3
    Personally, my limits are `function_body_length: 40`, `file_length: 500` (error limits). I saw people using even less but in my opinion using lower limits, especially for functions, destroys readability. A file limit shouldn't be definitely greater than 1000 lines. A file with 1000 lines is just too much. Refactor your code out, use view components, child view controllers, move your business code to services etc. Your controllers should be relatively simple classes. – Sulthan Mar 23 '20 at 17:33
  • 500 is very low!!! Abstracting code is a skill in and of itself. I’ll try it though. Thanks for the advice – Lance Samaria Mar 23 '20 at 17:35

1 Answers1

20

The rule name is file_length, so you have to disable this rule:

// swiftlint:disable file_length

import UIKit

class MyClass: UIViewController {

}

Note: // swiftlint:enable <rule> is for cases when you want to ignore a specific rule only in a small code block (like a single func). If you'd like to disable a rule in file scope, there is no need to enable anything.

See Swiftlint docs.

balazs630
  • 3,421
  • 29
  • 46