nicklockwood / SwiftFormat

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

Turn off all code-affecting rules by default #1705

Open dankinsoid opened 1 month ago

dankinsoid commented 1 month ago

I've spent the whole day debugging a bug and finally figured out that my app delegate function signatures look like this:

public func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool

because of the unusedArguments rule that is enabled by default.

There are some absolutely harmless formatting rules like indentation and many rules that can affect code functionality like unusedArguments. I believe that by default, only harmless rules should be enabled. Or, at least, some default rule presets should exist, so I could choose a safe preset as a base and then configure it in my .swiftformat file.

nicklockwood commented 1 month ago

What was the bug?

dankinsoid commented 1 month ago

@nicklockwood it was my fault, incorrect protocol implementation, I was in a hurry to create an issue. However, I also had a problem: swiftformat replaced writer.forEach with for item in writer, but writer was not a Collection, it just had a forEach method. I know that I can avoid such problems with //swiftformat:disable, but I would like to have some default safe rules preset to ensure that nothing in my project can be broken by the formatter, especially when using swiftformat for the first time on a large project.

nicklockwood commented 1 month ago

@dankinsoid understood. The safest option for now is to use --disable all and then manually enable just the rules that you would like.

But I think the safe ruleset option is a good idea and I will investigate adding that.