realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.45k stars 2.2k forks source link

Enforce attributes to be on the same line only if they don't have arguments #5618

Open Reyshawn opened 3 weeks ago

Reyshawn commented 3 weeks ago

New Issue Checklist

Describe the bug

When I set the @objc attribute always at the same line and set the option attributes_with_arguments_always_on_line_above to true.

It triggers a warning when I put the @objc(addEpisodesObject:), which has arguments on its own line;

// MARK: Generated accessors for episodes
extension Season {
    @objc(addEpisodesObject:)
    @NSManaged public func addToEpisodes(_ value: Episode)
}
opt_in_rules:
  - attributes
attributes:
  attributes_with_arguments_always_on_line_above: true
  always_on_same_line:
    - "@IBSegueAction"
    - "@IBAction"
    - "@NSManaged"
    - "@objc"
    - "@nonobjc"

How could I enforce attributes to be on their own line if they have arguments, and on the same line if they don't have arguments?

Environment

# insert yaml contents here
SimplyDanny commented 3 weeks ago

I wouldn't consider this as a bug. The implementation is just giving always_on_same_line precedence over attributes_with_arguments_always_on_line_above which might be exactly the behavior others want. So I'm not sure whether and, if so, how to change it.