realm / realm/SwiftLint

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

Open
#5,618 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

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
  • SwiftLint version (run swiftlint version to be sure)?
    0.55.1
  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    Homebrew
  • Paste your configuration file:
# insert yaml contents here
  • Are you using nested configurations?
    If so, paste their relative paths and respective contents.
  • Which Xcode version are you using (check xcodebuild -version)?
    Xcode 15.4
    Build version 15F31d
  • Do you have a sample that shows the issue? Run echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules
    to quickly test if your example is really demonstrating the issue. If your example is more
    complex, you can use swiftlint lint --path [file here] --no-cache --enable-all-rules.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the shown Swift snippet and YAML configuration using SwiftLint's --use-stdin command. Start by tracing the attributes rule and its configuration handling; done means attributes without arguments remain on the same line while attributes with arguments are enforced on their own line, with coverage for both cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.