Details

    • Type: Language-Specification
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Impact:
      Unknown 'null' severity
    • Likelihood:
      Unknown 'null' severity

      Description

      The number of elements in a collection, an array or a string are always greater than or equal to zero. So testing that a size or length is greater than or equal to zero doesn't make sense, since the result is always true. Similarly testing that it is less than zero will always return false. Perhaps the intent was to check the non-emptiness instead.

      Noncompliant Code Example

      if (myArray.count >= 0) { ... }
      
      if (myString.characters.count < 0) { ... }
      

      Compliant Solution

      if (myArray.isEmpty) { ... }
      
      if (myString.isEmpty) { ... }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            elena.vilchik Elena Vilchik
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: