Add configuration for excluding files from coverage

Hi there,

I’d like to request an extension to the configuration options - allowing to exclude files from coverage.

In some language you can exclude an entire file from coverage using a comment at the top of the file - for example in python:

# pragma: no cover

# ... rest of code

Or using Istanbul in JS:

/* Istanbul ignore: next */

// ... rest of code

But in other languages, for example Golang, you cannot skip coverage at all or cannot skip it for files. Some files though are either untestable, or include code that should not be tested - being a waste of time.

For example, I define a datatypes package that is shared with DTOs. The file only contains structs with json tags. While I can nominally test it to get coverage, this is a waste of my time.

I can exclude this file from analysis altogether, but than I wont have other useful metrics such as documentation coverage etc.

What I would like to do is to be able to exclude the file from the coverage analyer - and only from it:

``toml
[[analyzers]]
name = “test-coverage”
enabled = true

coverage_exclude_patterns = [
“services//internal/dto/.go”
]


For example. This can of course be more flexible - like in sonarQube, to have include patterns etc.

Thanks for the note @Goldziher. The immediate workaround I can think of is to trim/remove the unnecessary files from the coverage report after it is generated, before it is sent to DeepSource (or) use build tags. But they do add unnecessary complexity.

Providing an option to specify exclude_patterns at the analyzer level (in addition to repo level) makes sense. I’ll bring this up with the team.

1 Like