swiftlang / swift-format

Formatting technology for Swift source code
Apache License 2.0
2.49k stars 229 forks source link

Suggestion: a new rule `NoEmptyLinesOpeningClosingBracesOnMethods` - No empty lines on opening or closing braces in methods only #819

Open Pispa339 opened 1 month ago

Pispa339 commented 1 month ago

The existing rule NoEmptyLinesOpeningClosingBraces is somewhat too much of a catch-all rule. I'd like to request a more fine-grained rule where empty lines on opening or closing braces would be disallowed for methods, but allowed for type declarations.

For example the following would be disallowed within the rule

func hello() {

    // code starts here

whereas the following would be allowed

class SomeClass {

    // Code starts here
ahoppen commented 1 month ago

Synced to Apple’s issue tracker as rdar://136754857

allevato commented 1 month ago

These are the kinds of extremely fine-grained customizations that I'm really hesitant to add. NoEmptyLinesOpeningClosingBraces was added because it allows the formatter to be more opinionated across the board (which I think is a good goal). What would be the benefit of allowing the blank line for types but not functions?

Pispa339 commented 2 weeks ago

This request stems mostly from this our team's preference and our desire to be able to configure the formatter to our liking. However, this also seems to be the formatting used in Apple's example projects like DiffableDataSourceSample for example. I can definitely see why customization like this is not something one would consider worth pursuing given there's no real benefit beyond personal preference.