15

We just added Swiftlint to our project and we want to follow all the rules but I'm not sure what's meant by 'type_body_length' warning. I'm not a native english speaker so I find it a bit confusing.

There is a rule for file length aswell so how do they differ? What falls under this definition?

enter image description here

andromedainiative
  • 4,414
  • 6
  • 22
  • 34
  • 2
    Am I getting downvoted for not having a grasp of the english language? That seems quite harsh. Type body is probably something I would understand in my own language but Type and Body are very generic to me. Type could mean anything really, body should mean the major code block I guess. But if this only means the entire length of a class for example how does this differ from file length? Are extensions "escaped" from this rule?. – andromedainiative Dec 21 '18 at 10:00
  • 3
    type_body_length violation means that the class has too many lines in it. I dont think it counts extensions – Scriptable Dec 21 '18 at 10:07
  • Thank you. A clear answer and definition I was looking for. You could post this comment as an answer and I will accept it. – andromedainiative Dec 21 '18 at 10:09

1 Answers1

13

type_body_length violation means that the class has too many lines in it. I dont think it counts extensions, comments or whitespace

Type name should only contain alphanumeric characters, start with an uppercase character and span between 3 and 40 characters in length.

The rules documentation linked here and above also gives examples of what would and wouldn't be accepted (Triggering & Non Triggering). - Edit suggested by @GoodSp33d, thanks

Scriptable
  • 19,402
  • 5
  • 56
  • 72
  • 1
    @andromedainiative Probably also a good idea to refer to the Triggering & NonTriggering examples in the documentation. If one cannot understand from the text (true for me as well) the examples help. – GoodSp33d Dec 21 '18 at 10:42
  • 1
    Thanks, I wont post them all here but i'll add a note to refer to them as the documentation will be updated over time – Scriptable Dec 21 '18 at 10:47
  • I actually don't understand the difference in the examples. At all. –  Feb 18 '20 at 21:41
  • A Type is a enum, class, struct, protocol etc. Something you define. The body of that type cannot be too long. – Scriptable Feb 18 '20 at 21:54
  • Kind of strange that it seems to be better to have a load full extensions than one class structured with pragma marks. – brainray Jan 11 '21 at 13:30