Uploaded image for project: 'SonarSlang'
  1. SonarSlang
  2. SONARSLANG-88

Support statements list in match case in Slang

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Ruby
    • Labels:
      None

      Description

      Currently Slang grammar allows only block or single statement as body of match case:

      match {
      1 -> one_statement();
      2 -> { code_block() }
      }
      

      Still many languages allow statements list as body of a case, for example `Ruby`:

      case grade
      when "A"
        puts 'Well done!'
        puts 'Well done!'
      when "B"
        puts 'Try harder!'
      when "C"
        puts 'You need help!!!'
      else
        puts "You just making it up!"
      end
      

      During the mapping, such node will not be converted correctly, leading to FN in two rules, since they consider only block and top level trees.:

      • S122
        case grade
        when "A"
          return "something"
          puts 'Well done!' // FN
        else
          puts "You just making it up!"
        end
        
      • S1763
        case grade
        when "A"
          puts 'Well'; puts "done!" // FN
        else
          puts "You just making it up!"
        end
        

         

      `statements` metrics are also impacted.

      A possible solution keep Slang grammar as it is, and while converting languages allowing statements list, create a `BlockTree` without curly braces. Current API of `BlockTree` entirely supports it, as there is only one method `List<Tree> statementOrExpressions()`.

      The latter strategy has been used during the Go conversion and does not introduce unexpected behavior. We can therefore use it.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                amelie.renard Amélie Renard
                Reporter:
                elena.vilchik Elena Vilchik
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: