realm / realm/SwiftLint

`implicit_return` doesn't trigger for if/switch expressions

Open
#6,167 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Description

The implicit_return rule does not trigger in cases where an if or switch is used as the only expression in a function, and each branch consists of only a single return statement:

// This does not trigger a violation:
func test() -> String {
    if .random() {
        return "A"
    } else {
        return "B"
    }
}

Mention the command or other SwiftLint integration method that caused the issue. Include stack traces or command output.

$ swiftlint
Environment
  • SwiftLint version: 0.59.1
  • Xcode version: Xcode 16.4 (16F6)
  • Installation method used: built from source
  • Configuration file:
    enabled_rules:
      - implicit_return
    
  • no nested configurations

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

Start by running swiftlint with the shown enabled_rules configuration against the example, then locate the implicit_return rule implementation and its tests. Confirm that the if/switch single-return cases are reported while existing behavior remains unchanged.

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
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.