Skip to content

Wrong line numbers and absolute paths in GitLab output #1744

@qcz

Description

@qcz

There are two issues with the GitLab output which renders the output unusable with the GitLab Code Quality UI integration:

  • The first is that the line numbers are wrong (one fewer than it should be) in the GitLab output.
  • The output contains absolute paths which makes file links and the code quality issue display on the changes screen not work at all. Also it should contain / as path separator insead of \

For example there is a problem in the CLI:

MyFile.cs(131,10): error CA2201: Exception type System.Exception is not sufficiently specific

In the standard XML output we can see:

<Diagnostic Id="CA2201">
    <Severity>Error</Severity>
    <Message>Do not raise reserved exception types</Message>
    <FilePath>C:\My\Repo\Path\SubDirectory\MyCsharpFile.cs</FilePath>
    <Location Line="131" Character="10" />
</Diagnostic>

In the Gitlab output however:

{
    "type": "issue",
    "fingerprint": "2af2bff19cc84a89e8f603cd2acaf3150dbe2a8504751eb6ac8635dac24a7590",
    "check_name": "CA2201",
    "description": "Do not raise reserved exception types",
    "severity": "critical",
    "location": {
      "path": "C:\\My\\Repo\\Path\\SubDirectory\\MyCsharpFile.cs",
      "lines": {
        "begin": 130
      }
    },
    "categories": [
      "Usage"
    ]
  },

Note the wrong line number and the absolute path. The correct content for GitLab should be (if the repo is at C:\My\Repo\Path):

{
    "type": "issue",
    "fingerprint": "2af2bff19cc84a89e8f603cd2acaf3150dbe2a8504751eb6ac8635dac24a7590",
    "check_name": "CA2201",
    "description": "Do not raise reserved exception types",
    "severity": "critical",
    "location": {
      "path": "SubDirectory/MyCsharpFile.cs",
      "lines": {
        "begin": 131
      }
    },
    "categories": [
      "Usage"
    ]
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions