SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Feature request: Add an option that changes behavior depending on whether attributes have arguments

Open woxtu opened this issue 2 years ago • 3 comments

New Issue Checklist

New feature request

The attributes_with_arguments_always_on_line_above option which has added to the attributes rule in version 0.52.0 is only working for variables and imports. I think it would be nice if there was a way to work for functions and types as well.

In the current version, variables and imports can change the behavior of the attributes rule depending on whether their attributes have arguments, but functions and types cannot. I think it would be nice if they had a way to do the same.

An use case:

@objc(Foo)
class Foo: NSObject {
    @objc func foo() {}
}

ref. Google's Swift Style Guide

woxtu avatar May 15 '23 15:05 woxtu

On types and functions, the rule makes sure that attributes are always on the line above no matter if they have arguments or not.

What is your particular request? Is it an option like attributes_without_arguments_always_on_same_line that applies to type and function declarations?

SimplyDanny avatar May 15 '23 18:05 SimplyDanny

Yes, it's exactly! I fixed the description.

woxtu avatar May 15 '23 23:05 woxtu

Just wanted to resurface this issue, as it also breaks the default convention for Swift Testing functions, like:

@Test func foodTruckExists() {
  // Test logic goes here.
}

mateusz-ramp avatar Dec 09 '25 16:12 mateusz-ramp