Uploaded image for project: 'SonarQube'
  1. SonarQube
  2. SONAR-11778

Measure 'new lines' doesn't match 'lines' if the file ends with new line

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 8.0
    • Component/s: Branch & PR
    • Labels:
      None
    • Edition:
      Developer
    • Production Notes:
      None

      Description

      If a file that ends with a new line char (\n), we count it as a line in the file in the scanner, but it doesn't get detected as a new line when working with git diff to detect new lines of code, in the context of SLB and PRs. 

      The behavior in the context of leak periods is unknown (haven't tested it).
       
      As a result, if the entire file is new and it ends with a new line char, the measure of lines will not match the measure of new lines.
       
      For example: A new file with the content 'my\nfile\n' will have 3 "lines" and 2 "new lines".

       

      The solution will be to detect this situation when getting the list of changed lines from the SCM and add the last line when it makes sense.

       

      See mismatching numbers here: 

       

       

      Result from /api/measures/component:

      {
        "component": {
          "id": "AWkwxUzV5YgM5HnNWSiB",
          "key": "org.sonarsource.scanner.cli:sonar-scanner-cli:src/main/java/org/sonarsource/scanner/cli/NewFile.java",
          "name": "NewFile.java",
          "qualifier": "FIL",
          "path": "src/main/java/org/sonarsource/scanner/cli/NewFile.java",
          "language": "java",
          "measures": [
            {
              "metric": "new_lines",
              "periods": [
                {
                  "index": 1,
                  "value": "8"
                }
              ]
            },
            {
              "metric": "lines",
              "value": "9"
            }
          ],
          "branch": "mybranch"
        }
      } 

       

        Attachments

        1. eclipse.png
          eclipse.png
          46 kB
        2. ss.png
          ss.png
          146 kB

          Activity

            People

            Assignee:
            duarte.meneses Duarte Meneses
            Reporter:
            duarte.meneses Duarte Meneses
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Due:
              Created:
              Updated:
              Resolved: