How to fix "Trailing Whitespace Violation" warnings caused by swiftlint in Xcode?

Malika Arora picture Malika Arora · Jul 16, 2019 · Viewed 11.3k times · Source

How can we fix the "Trailing Whitespace Violation" warnings caused by swiftlint in my iOS project all in one go? I don't want to manually correct each one of them. Moreover, I don't want to disable these warnings so you can skip that suggestion.

I have been trying Find And Replace option but I am not getting a correct keyword to sort this out.

Image :

enter image description here

Answer

Joakim Danielson picture Joakim Danielson · Jul 16, 2019

swiftlint has an autocorrect option that will fix some issues for you, so when I get trailing whitespace warnings I run swiftlint from the command line in my project

$ swiftlint autocorrect

Update

As of version 0.43 autocorrect has been deprecated and replaced with --fix so now the command is

$ swiftlint --fix

autocorrect is still available for the time being, for more info see the change log