nicklockwood / SwiftFormat

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

--onelineforeach ignore is not working #1884

Open bauyrzhanabdi opened 2 days ago

bauyrzhanabdi commented 2 days ago

My .swiftformat file contains this

format options

--onelineforeach ignore

rules

-enable isEmpty

This is the original code

let letters: [String] = ["h", "e", "l", "l", "o"]
letters.forEach { letter in
   print(letter)
}

After I run swiftformat script, it updates the code into this

let letters: [String] = ["h", "e", "l", "l", "o"]
for letter in letters {
   print(letter)
}

Even though onelineforeach is set to ignore, the format option is not ignored. Despite this, its default state is set to convert and not to ignore as it was stated in documentation. So, even without explicitly setting onelineforeach to ignore, it still converts the code

nicklockwood commented 2 days ago

--onelineforeach refers to code like

letters.forEach { letter in print(letter) }

if you want to disable the rule altogether, use:

--disable preferForLoops