> ## 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.

# Excluding Files from Coverage

There are two ways to exclude files from coverage in Qlty:

1. **In your coverage tool** — exclude files before the coverage report is generated
2. **In `qlty.toml`** — filter files out of coverage data during upload

If you use other coverage tools or dashboards alongside Qlty, configuring exclusions in your coverage tool keeps your coverage data consistent everywhere. If Qlty is where you manage coverage, either approach works — `qlty.toml` is often the simpler option.

## Excluding files in your coverage tool

Each coverage tool has its own configuration for excluding files. Below are examples for common tools.

<AccordionGroup>
  <Accordion title="JavaScript / TypeScript (Jest / Istanbul)">
    Configure coverage exclusions in your Jest config (`jest.config.js` or `package.json`):

    ```javascript theme={"system"}
    // jest.config.js
    module.exports = {
      collectCoverageFrom: [
        "src/**/*.{js,ts,jsx,tsx}",
        "!src/**/*.test.{js,ts,jsx,tsx}",
        "!src/**/index.{js,ts}",
        "!src/generated/**",
      ],
      coveragePathIgnorePatterns: [
        "/node_modules/",
        "/vendor/",
        "/dist/",
      ],
    };
    ```

    * `collectCoverageFrom`: Specify which files to include (use `!` to exclude patterns)
    * `coveragePathIgnorePatterns`: Exclude files matching these patterns

    If using NYC (Istanbul) directly, configure in `.nycrc` or `package.json`:

    ```json theme={"system"}
    {
      "exclude": [
        "test/**",
        "**/*.test.js",
        "vendor/**"
      ]
    }
    ```
  </Accordion>

  <Accordion title="Python (pytest-cov / coverage.py)">
    Configure exclusions in your `pyproject.toml`, `setup.cfg`, or `.coveragerc`:

    ```toml theme={"system"}
    # pyproject.toml
    [tool.coverage.run]
    omit = [
        "tests/*",
        "*/migrations/*",
        "setup.py",
        "*/vendor/*",
    ]
    ```

    Or in `.coveragerc`:

    ```ini theme={"system"}
    [run]
    omit =
        tests/*
        */migrations/*
        setup.py
    ```

    You can also exclude specific lines or blocks using inline comments:

    ```python theme={"system"}
    if TYPE_CHECKING:  # pragma: no cover
        import SomeModule
    ```
  </Accordion>

  <Accordion title="Ruby (SimpleCov)">
    Configure exclusions in your test helper where SimpleCov is initialized:

    ```ruby theme={"system"}
    require 'simplecov'
    SimpleCov.start do
      add_filter '/test/'
      add_filter '/spec/'
      add_filter '/vendor/'
      add_filter '/config/'
      add_filter do |source_file|
        source_file.lines.count < 5
      end
    end
    ```

    `add_filter` accepts strings, regex patterns, or blocks.
  </Accordion>

  <Accordion title="Java / Kotlin (JaCoCo)">
    Configure exclusions in your build file.

    **Gradle:**

    ```groovy theme={"system"}
    jacocoTestReport {
        afterEvaluate {
            classDirectories.setFrom(files(classDirectories.files.collect {
                fileTree(dir: it, exclude: [
                    '**/generated/**',
                    '**/model/**',
                    '**/config/**',
                ])
            }))
        }
    }
    ```

    **Maven:**

    ```xml theme={"system"}
    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <configuration>
            <excludes>
                <exclude>**/generated/**</exclude>
                <exclude>**/model/**</exclude>
                <exclude>**/config/**</exclude>
            </excludes>
        </configuration>
    </plugin>
    ```
  </Accordion>

  <Accordion title="Go">
    Go's built-in coverage tool uses build tags and package patterns to control coverage scope:

    ```bash theme={"system"}
    # Cover only specific packages
    go test -coverprofile=coverage.out ./pkg/... ./internal/...

    # Exclude specific packages by listing only what you want
    go test -coverprofile=coverage.out $(go list ./... | grep -v /generated/ | grep -v /vendor/)
    ```
  </Accordion>

  <Accordion title="PHP (PHPUnit)">
    Configure coverage exclusions in `phpunit.xml`:

    ```xml theme={"system"}
    <phpunit>
        <source>
            <include>
                <directory suffix=".php">src</directory>
            </include>
            <exclude>
                <directory suffix=".php">src/Migrations</directory>
                <file>src/Kernel.php</file>
            </exclude>
        </source>
    </phpunit>
    ```
  </Accordion>

  <Accordion title="Swift (Xcode / Slather)">
    When using Slather, configure exclusions in `.slather.yml`:

    ```yaml theme={"system"}
    coverage_service: cobertura_xml
    xcodeproj: YourProject.xcodeproj
    scheme: YourScheme
    output_directory: coverage
    ignore:
      - "Pods/*"
      - "../**/*/Xcode*"
      - "YourProject/Generated/*"
    ```

    When using `xccov`, exclusions must be configured at the Xcode scheme level or by post-processing the coverage data before uploading.
  </Accordion>

  <Accordion title="Elixir (lcov_ex)">
    In Elixir, configure which modules to exclude from coverage in `mix.exs`:

    ```elixir theme={"system"}
    def project do
      [
        test_coverage: [
          tool: LcovEx,
          ignore_modules: [
            MyApp.Generated.Schema,
            ~r/MyApp\.Vendor\..*/,
          ]
        ]
      ]
    end
    ```
  </Accordion>
</AccordionGroup>

## Excluding files in qlty.toml

You can also exclude files from coverage using the `[coverage].ignores` setting in `qlty.toml`. When `qlty coverage publish` runs, any file path in the coverage report that matches an ignore pattern is dropped before uploading.

```toml lines theme={"system"}
[coverage]
ignores = [
  "**/test_helpers/**",
  "**/fixtures/**",
  "**/*.generated.ts",
]
```

### Built-in default exclusions

Qlty applies a set of [default `exclude_patterns`](https://github.com/qltysh/qlty/blob/main/qlty-config/default.toml) that automatically propagate to coverage ignores. These include paths like:

```
**/node_modules/**    **/vendor/**     **/dist/**
**/build/**           **/generated/**  **/target/**
**/fixtures/**        **/testdata/**   **/cache/**
*.min.*               **/*.d.ts        **/deps/**
```

Any patterns you add to `[coverage].ignores` are combined with these defaults.

### Using exclude\_patterns for coverage

The top-level `exclude_patterns` setting in `qlty.toml` automatically propagates to `[coverage].ignores`. This means any pattern in `exclude_patterns` also excludes files from coverage.

<Warning>
  Using `exclude_patterns` for coverage exclusions is deprecated. Use `[coverage].ignores` for
  coverage-specific exclusions instead.
</Warning>

### Removing missing files

If your coverage report contains paths for files that don't exist on disk (e.g., generated during CI but not checked in), you can drop them during upload:

```bash lines theme={"system"}
qlty coverage publish --skip-missing-files coverage/lcov.info
```

## Common files to exclude

Depending on your project, you may want to exclude:

* **Generated code**: API clients, protobuf files, GraphQL types
* **Vendor/third-party code**: Dependencies copied into your repository
* **Configuration files**: Setup, bootstrap, or configuration modules
* **Migration files**: Database migration scripts
* **Test utilities**: Test helpers, fixtures, and factories

## See Also

* [Generating Coverage Data](/coverage/generating-data) for language-specific setup
* [Excluding Files from Analysis](/excluding-files) for static analysis exclusions (separate from coverage)
* [Unexpected Coverage Changes](/coverage/unexpected-changes) for troubleshooting coverage differences
