0

I'm trying to enforce my team to use data type when declairing a var/let Instead of var name = "john" I want var name: String = "john"

Can anyone name the rule of swiftLint to implement this change?

Asperi
  • 228,894
  • 20
  • 464
  • 690
  • 4
    Please don't do that to your team – George Sep 22 '21 at 00:04
  • There is a bigger power above me who is making me do this – Haroon Maqsood Sep 22 '21 at 00:11
  • 1
    You should probably remind them what type of language Swift is - the types are [inferred](https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID322), and unnecessarily adding types like this is just clutter. I don't know how to enforce this in SwiftLint, but it's probably for the better if the rule doesn't exist :p It's not like there will be issues where if a value is changed (so the underlying type changes), everything breaks - the variable still has a specific type. It's not JavaScript, the compiler will complain about type errors. – George Sep 22 '21 at 00:16
  • 1
    Just throwing something out there. I have reduced compile times significantly by declaring type vs letting it be inferred. If you add `-Xfrontend -warn-long-expression-type-checking=200 -Xfrontend -warn-long-function-bodies=200` to "Other Swift Flags" in Build Settings you will see where you can benefit from it. It is definitely a preference thing and it does look more cluttered but in large projects it can make a difference. – lorem ipsum Sep 22 '21 at 01:44

1 Answers1

0

In the .yml file add this rule "explicit_type_interface"