nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.62k stars 623 forks source link

Rule idea: preferWhere #1727

Open nicklockwood opened 2 weeks ago

nicklockwood commented 2 weeks ago

Automatically convert loops with a nested if statement to a where clause:

for foo in bar {
  if foo ... {

  }
}

becomes

for foo in bar where foo ... {

}
calda commented 2 weeks ago

And maybe also the inverse, convert where to a guard:

for foo in bar where foo {
  ...
}

to

for foo in bar {
  guard foo else { continue }
  ...
}