Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 216
Malika Arora Avatar asked Jul 16 '19 04:07

Malika Arora


People also ask

How do I delete trailing spaces in Xcode?

Select Scripts Menu > Edit User Scripts... Press the + button and select New Shell Script. Give it a name like "Strip Trailing Spaces", and give it a shortcut like ⌃⇧R. Set Input to "Selection" and Output to "Replace Selection"

What is a trailing whitespace?

Trailing whitespace. Description: Used when there is whitespace between the end of a line and the newline.


2 Answers

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

like image 151
Joakim Danielson Avatar answered Oct 19 '22 07:10

Joakim Danielson


Check the 2 checkboxes in While editing section

enter image description here

like image 22
JMGM Avatar answered Oct 19 '22 06:10

JMGM