Uploaded image for project: 'SonarSwift'
  1. SonarSwift
  2. SONARSWIFT-429

Update rule S2201 to ignore single statement functions (Swift 5.1)

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.2
    • Component/s: Rules
    • Labels:
      None

      Description

      In Swift 5.1 there is a new feature:  implicit returns from single-expression functions. Like these:

      func double(_ number: Int) -> Int {
          number * 2
      }
      

      Thus rule RSPEC-2201 might raise FPs:

      func doubleAbs(_ number: Int) -> Int {
          abs(number * 2) // FP here since Swift 5.1
      }
      

      So to avoid FP we should check if this statement is the only one in the function.
       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                guillaume.dequenne Guillaume Dequenne
                Reporter:
                elena.vilchik Elena Vilchik
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: