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.

Configure coverage exclusions in your Jest config (jest.config.js or package.json):

1// jest.config.js
2module.exports = {
3 collectCoverageFrom: [
4 "src/**/*.{js,ts,jsx,tsx}",
5 "!src/**/*.test.{js,ts,jsx,tsx}",
6 "!src/**/index.{js,ts}",
7 "!src/generated/**",
8 ],
9 coveragePathIgnorePatterns: [
10 "/node_modules/",
11 "/vendor/",
12 "/dist/",
13 ],
14};
  • 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:

1{
2 "exclude": [
3 "test/**",
4 "**/*.test.js",
5 "vendor/**"
6 ]
7}

Configure exclusions in your pyproject.toml, setup.cfg, or .coveragerc:

1# pyproject.toml
2[tool.coverage.run]
3omit = [
4 "tests/*",
5 "*/migrations/*",
6 "setup.py",
7 "*/vendor/*",
8]

Or in .coveragerc:

1[run]
2omit =
3 tests/*
4 */migrations/*
5 setup.py

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

1if TYPE_CHECKING: # pragma: no cover
2 import SomeModule

Configure exclusions in your test helper where SimpleCov is initialized:

1require 'simplecov'
2SimpleCov.start do
3 add_filter '/test/'
4 add_filter '/spec/'
5 add_filter '/vendor/'
6 add_filter '/config/'
7 add_filter do |source_file|
8 source_file.lines.count < 5
9 end
10end

add_filter accepts strings, regex patterns, or blocks.

Configure exclusions in your build file.

Gradle:

1jacocoTestReport {
2 afterEvaluate {
3 classDirectories.setFrom(files(classDirectories.files.collect {
4 fileTree(dir: it, exclude: [
5 '**/generated/**',
6 '**/model/**',
7 '**/config/**',
8 ])
9 }))
10 }
11}

Maven:

1<plugin>
2 <groupId>org.jacoco</groupId>
3 <artifactId>jacoco-maven-plugin</artifactId>
4 <configuration>
5 <excludes>
6 <exclude>**/generated/**</exclude>
7 <exclude>**/model/**</exclude>
8 <exclude>**/config/**</exclude>
9 </excludes>
10 </configuration>
11</plugin>

Go’s built-in coverage tool uses build tags and package patterns to control coverage scope:

$# 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/)

Configure coverage exclusions in phpunit.xml:

1<phpunit>
2 <source>
3 <include>
4 <directory suffix=".php">src</directory>
5 </include>
6 <exclude>
7 <directory suffix=".php">src/Migrations</directory>
8 <file>src/Kernel.php</file>
9 </exclude>
10 </source>
11</phpunit>

When using Slather, configure exclusions in .slather.yml:

1coverage_service: cobertura_xml
2xcodeproj: YourProject.xcodeproj
3scheme: YourScheme
4output_directory: coverage
5ignore:
6 - "Pods/*"
7 - "../**/*/Xcode*"
8 - "YourProject/Generated/*"

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

In Elixir, configure which modules to exclude from coverage in mix.exs:

1def project do
2 [
3 test_coverage: [
4 tool: LcovEx,
5 ignore_modules: [
6 MyApp.Generated.Schema,
7 ~r/MyApp\.Vendor\..*/,
8 ]
9 ]
10 ]
11end

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.

1[coverage]
2ignores = [
3 "**/test_helpers/**",
4 "**/fixtures/**",
5 "**/*.generated.ts",
6]

Built-in default exclusions

Qlty applies a set of default exclude_patterns 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.

Using exclude_patterns for coverage exclusions is deprecated. Use [coverage].ignores for coverage-specific exclusions instead.

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:

$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