coverlint

command module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 3 Imported by: 0

README

coverlint

Workflow for coverlint Action codecov

coverlint checks Go test coverage for each package. Thresholds are fractions in [0, 1] (0.80 = 80%). Empty rules default to ** / 0.80.

It can run as:

  • a standalone CLI;
  • a plugin inside a custom golangci-lint binary.

Use as a CLI

Install
go get github.com/gostafa/coverlint@latest
go install github.com/gostafa/coverlint/cmd/coverlint@latest

The public API lives in github.com/gostafa/coverlint/coverlint.

Run
coverlint

# Check selected packages.
# coverlint ./internal/...

# Require 80% everywhere and 20% under internal.
# coverlint --rule='**':0.80 --rule='**/internal/**':0.2 ./...

# Skip generated packages.
# coverlint --exclude '**/generated/**' ./...

# Open the HTML coverage report.
# coverlint --web ./...

# Bound how long `go test` may run, and pass extra test flags.
# coverlint --timeout=20m --test-arg=-race ./...

Flags must come before package patterns:

coverlint --rule='**':0.80 ./...

Useful flags:

  • --rule=pattern:min (repeatable)
  • --exclude=pattern (repeatable)
  • --timeout=duration
  • --test-arg=flag (repeatable)
  • --web
  • --version

Policy gates package coverage by import-path glob. min is a fraction in [0, 1]. Coverage in messages stays a percentage (coverage 50.00% is below 80.00%). When multiple rules match, the most specific pattern wins: more literal segments, then fewer wildcards, then longer patterns; exact ties use the later rule.

Build from source
git clone https://github.com/gostafa/coverlint.git
cd coverlint

go build -o ./bin/coverlint ./cmd/coverlint
./bin/coverlint

Use as a golangci-lint plugin

The plugin must be included in a custom golangci-lint binary.

Create .custom-gcl.yml:

version: v2.12.2
name: custom-golangci-lint
destination: ./bin
plugins:
  - module: github.com/gostafa/coverlint
    import: github.com/gostafa/coverlint/plugin
    path: .

Enable it in .golangci.yml:

version: "2"

linters:
  default: all
  enable:
    - coverlint

  settings:
    custom:
      coverlint:
        type: module
        settings:
          rules:
            - pattern: '**'
              min: 0.80
            - pattern: '**/*_test'
              min: 0.0

Build and run the custom linter:

golangci-lint custom -v
./bin/custom-golangci-lint run ./...

Always run the generated custom-golangci-lint binary. The standard golangci-lint binary does not include the plugin.

Exit codes

  • 0: success
  • 1: check or write error
  • 2: command usage error

Documentation

Overview

Package main is the coverlint module root entrypoint.

Directories

Path Synopsis
Package analyzer provides the go/analysis adapter for coverlint.
Package analyzer provides the go/analysis adapter for coverlint.
cmd
coverlint command
Package main is the coverlint command-line entrypoint.
Package main is the coverlint command-line entrypoint.
Package coverlint provides the public API for coverage policy checking.
Package coverlint provides the public API for coverage policy checking.
internal
cli
Package cli implements the coverlint command-line interface.
Package cli implements the coverlint command-line interface.
features/coverage
Package coverage re-exports the coverlint facade for feature consumers.
Package coverage re-exports the coverlint facade for feature consumers.
features/coverage/adapters/gotool
Package gotool adapts the Go toolchain for coverage collection and reporting.
Package gotool adapts the Go toolchain for coverage collection and reporting.
features/coverage/adapters/text
Package text formats coverage results as diagnostic lines.
Package text formats coverage results as diagnostic lines.
features/coverage/application
Package application coordinates coverage collection and policy evaluation.
Package application coordinates coverage collection and policy evaluation.
features/coverage/config
Package config validates and resolves coverlint coverage settings.
Package config validates and resolves coverlint coverage settings.
features/coverage/domain
Package domain models coverage packages, profiles, and policy evaluation.
Package domain models coverage packages, profiles, and policy evaluation.
features/coverage/ports
Package ports re-exports coverage outbound port contracts.
Package ports re-exports coverage outbound port contracts.
features/coverage/ports/outbound
Package outbound defines the outbound port interfaces for coverage.
Package outbound defines the outbound port interfaces for coverage.
features/reporting/domain
Package domain provides diagnostic formatting for coverage results.
Package domain provides diagnostic formatting for coverage results.
infrastructure/gotool
Package gotool adapts the Go toolchain for coverage collection and reporting.
Package gotool adapts the Go toolchain for coverage collection and reporting.
Package plugin adapts the coverlint analyzer to golangci-lint.
Package plugin adapts the coverlint analyzer to golangci-lint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL