Using SwiftLint to reduce code smell on Xcode.

2020 @ https://www.google.com/maps?cid=3113512418631351453

I — Intro

Image 1 : SwiftLint warning
Image 2: SwiftLint error

II — Extra motivation.

Image 3 — Basic design language for images
var avatarView = UIImageView(image: UIImage(named: “avatar.1”))
var avatarView = UIImageView(image: ImageNames.avatar.image)
no_hardCodedImages:
included: “.*\\.swift”
name: “Fordiden hardCoded images”
regex: “UIImage[(]named:”
message: “Don’t use hardCoded images”
severity: error

III — Some of my (SwiftLint extra) rules.

No Print

no_print:
included: “.*\\.swift”
name: “Fordidden print”
regex: “print[(]”
message: “Use DevTools.Log…”
severity: warning

No let _ =

no_letUnderscore:
included: ".*\\.swift"
name: "No let _ = ..."
regex: 'let[ ][_][ ][=]'
message: "Don't use let _ = xxx , use xxx != nil"
severity: error

Numbers smell

numbers_smell:
regex: '(return |case |\w\(|: |\?\? |\, |== |<=? |>=? |\+= |\-= |\/= |\*= |%= |\w\.\w+ = )\(*-?\d{2,}'
message: "Numbers smell; define a constant instead."
severity: warning

Commented code

commented_code:
regex: '(?<!:|\/)\/\/\h*[a-z.](?!wiftlint)'
message: "Comment starting with lowercase letter - did you forget to delete old code?"
severity: warning

Singleton (vars naming)

naming_Singletons:
included: “.*\\.swift”
name: “Singleton naming”
regex: “static (var|let)[ ](instance|sharedInstance)[ ]*[:]”
message: “Use shared”
severity: error

Hardcoded TimeZones

no_hardCodedTimeZones:
included: “.*\\.swift”
name: “Fordiden hardcoded TimeZones”
regex: “\”UTC\”|\”GMT\””
message: “Use AppConstants.TimeZones”
severity: error
no_hardCodedDateFormats:
included: ".*\\.swift"
name: "Hardcoded DateFormats"
regex: '= "yyyy|DateFormatter(withFormat'
message: "Use AppContants.DateFormatterTypes"
severity: error

IV — Final considerations.

  • The more strong, coherent and consistent our code base will be.
  • The more easy is to ensure a the use of a specific Design Language.
  • The more developers will code using the same style.
  • The more easy will be to find things of the code.

V — Materials.

My SwiftLint basic template (always change depending of the project needs)

V — Related articles

--

--

--

https://github.com/ricardopsantos/ricardopsantos

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Imageview customization (circular image view)

How to add .gitignore file through Terminal

How To Save Data To Apple Health in Swift

[ios 강좌] ios 푸시 알림 2부 — 클라이언트 개발

Disable a Test ‘func testBusinessLogic()’

How To Implement A ZStack in UIKit using AutoLayout

A ZStack built with UIKit

Uptick on IRITA OPB/魔卡 (BSN Consortium Version) is released on the iOS App Store

Swap root view controllers using a custom container view controller

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ricardo Santos

Ricardo Santos

https://github.com/ricardopsantos/ricardopsantos

More from Medium

What is the Variables and Constants in Swift Language ?

SOLID Principles in Swift

Why SWIFT Is More Preferable Language For IOS App Development?

Taking a break (Part 1 of 2)