> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qlty.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Integrate Code Coverage Formats

Qlty accepts coverage data in multiple formats compatible with various tools and languages.

See [Supported Languages and Formats](/coverage/generating-data) for more information.

In rare cases where Qlty does not appear to support the coverage format you're using, below are some possible options to pursue:

1. Change the output format

   Some coverage tools support either output coverage data in multiple formats, or support conversion to popular formats. `gcovr`, for example, [supports conversion](https://gcovr.com/en/stable/output/clover.html) from a Go-specific format to Clover XML, supported by Qlty.

   LCOV (files in the form of `*.info`, `lcov.info`, `*.lcov`) is another popular format supported by Qlty to look out for.

2. Write your own parser

   Because the Qlty CLI is Open Source, you also have the opportunity to contribute your formatter back to the community. See [the parser directory](https://github.com/qltysh/qlty/tree/main/qlty-coverage/src/parser) for other examples.

   An LLM should be able to produce a simple parser given the pre-existing parsers and an example of the new input format.

   The target format, qlty, is described below under [Qlty format](#qlty-format)

3. Contact us

   If writing a formatter is not something you're up for, or you need assistance, feel free to [contact us](https://qlty.sh/contact/support).

## Qlty Format

Qlty supports the import of a generic format, named `qlty`, which can be used as a target for custom conversion of reports from tools that are not directly supported.

### Specification

The `qlty` format follows the [JSON Lines text file format](https://jsonlines.org/), also called newline-delimited JSON. Each line contains one JSON object.

The structure of each JSON object is described using the [JSON schema standard](https://json-schema.org/), a declarative language that provides a standardized way to describe JSON data.

```JSON lines theme={"system"}
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "File Line Coverage",
  "description": "Indicates which lines of a file have been covered",
  "type": "object",
  "properties": {
    "path": {
      "description": "The file's path to inform code coverage for",
      "type": "string"
    },
    "hits": {
      "description": "Sepcifies the number of times each line of the file has been covered",
      "type": "array",
      "items": {
        "description": "The number of hits for a specific line in the file, where -1 indicates the line was excluded from the report or it's irrelevant, and non-negative integers indicate the number of hits",
        "type": "string",
        "pattern": "^(-1|[0-9]+)$",
      }
    }
  }
}
```

Following, an example of a consolidated `qlty` report:

```
{ path: "user.js", hits: ["-1", "-1", "0", "0", "1", "4", "1", "2", "0", "-1"] }
{ path: "todo.js", hits: ["3", "3", "3", "0", "-1", "-1", "1", "2", "0", "4", "4", "4", "4"] }
{ path: "item.js", hits: ["0", "0", "0", "0", "0", "-1", "0", "0", "0", "0", "0", "0", "0"] }
{ path: "account.js", hits: ["1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"] }
```

JSON Lines files are generally saved with the `.jsonl` extension, so it's recommended to save your
`qlty` formatted coverage report with this extension.

#### The `path` Property

Ideally, the file path for your code coverage report should be relative to your Git project's root. However, you can transform the path using the universal reporter tool with the `--strip-prefix` and `--add-prefix` flags, modifying the final path of the uploaded report.

#### The `hits` Property

Depending on the tool used to exercise your code base, a single line could be:

* Irrelevant regarding code coverage (e.g., comments) ("-1")
* Not covered ("0")
* Covered, possibly multiple times.

This structure ensures that you can translate and submit coverage reports in a consistent format, regardless of the tool used to generate them.

### Uploading a `qlty` formatted Coverage Report

Uploading a `qlty` formatted coverage report is no different than uploading a code coverage report in any other format. Follow these steps:

1. Convert your report to the `qlty` format.

2. Get your Qlty coverage token from your project's settings page under the Code Coverage section.

3. Upload the report using Qlty's coverage reporter:

```sh lines theme={"system"}
export QLTY_COVERAGE_TOKEN=your_token
./qlty coverage publish path/to/coverage_report.jsonl
```

For explicitness, you can use the `--format=qlty` flag to specify the format, though `qlty` will infer it by default:

```sh lines theme={"system"}
./qlty coverage publish --format=qlty path/to/coverage_report.jsonl
```

## Need help?

If you need support for a specific code coverage format, [contact our support team](https://qlty.sh/contact/support). We may be able to complete the process within one week.
