0

Amazing people!!

I have a project which needs a TechDebt to be executed where, all the existing code files having 2 space indentation. Now I want to convert all the 2 space indentation to 4 space indentation, is there any way I can automate this process rather going with Manual approach.

Potentially with any sort of Shel scripting in XCode editor configuration settings where I can inject that script and get things done.

Help would be highly appreciated.

Thanks a ton in advance guys.

Kuldeep
  • 2,589
  • 1
  • 18
  • 28

3 Answers3

1

I think you should be able to do what you're after using Regex in Xcode Find and Replace. Using ⌥⇧⌘F to bring up the Find Navigator, checking Replace is shown. Switch from Text to Regular Expression if not already shown and ensure In Workspace is selected (or change to required scope)

Use ^\s\s for Find and ^\s\s\s\s for Replace. This will replace all 2 space indentation from the start of each line to 4 space indentation.

Leon Storey
  • 3,274
  • 2
  • 25
  • 40
1

Leon's answer is close... but that will also change existing 4-leading-spaces to 6, 3-leading to 5, 6-leading to 8, etc...

Try search pattern:

^  [\S]

hard to tell here, but that is ^ followed by two spaces followed by [\S] (beginning of line + two spaces followed by non-whitespace),

replace pattern:

  $0

hard to tell here, but that is two spaces + $0 (the matched string)

DonMag
  • 69,424
  • 5
  • 50
  • 86
0

Hey Guys @DonMag and @Leon Storey

I did a bit research and I found a significant solution which is below :

  1. Install SwiftLint brew install swiftlint

  2. Go to your project in terminal

  3. Execute below command

    swiftlint autocorrect --format

There you are!

This will edit all your files automatically and convert them into 4 spacing and also it will fix other formatting errors inside your project if any. For me it was 790 files which got executed just in seconds.

Thanks for the answers guys.

Kuldeep
  • 2,589
  • 1
  • 18
  • 28