Skip to content

ldez/gomoddirectives

Repository files navigation

gomoddirectives

A linter that handle directives into go.mod.

Sponsor Build Status

Usage

Inside golangci-lint

Recommended.

linters:
  enable:
    - gomoddirectives

  settings:
    gomoddirectives:
      # Allow local `replace` directives.
      # Default: false
      replace-local: true
      
      # List of allowed `replace` directives.
      # Default: []
      replace-allow-list:
        - launchpad.net/gocheck
      
      # Allow to not explain why the version has been retracted in the `retract` directives.
      # Default: false
      retract-allow-no-explanation: true
      
      # Forbid the use of the `exclude` directives.
      # Default: false
      exclude-forbidden: true
  
      # Forbid the use of the `ignore` directives (go >= 1.25).
      # Default: false
      ignore-forbidden: true
  
      # Forbid the use of the `toolchain` directive.
      # Default: false
      toolchain-forbidden: true
  
      # Defines a pattern to validate `toolchain` directive.
      # Default: '' (no match)
      toolchain-pattern: 'go1\.22\.\d+$'
  
      # Forbid the use of the `tool` directives.
      # Default: false
      tool-forbidden: true
  
      # Forbid the use of the `godebug` directive.
      # Default: false
      go-debug-forbidden: true
  
      # Defines a pattern to validate `go` minimum version directive.
      # Default: '' (no match)
      go-version-pattern: '1\.\d+(\.0)?$'

As a CLI

gomoddirectives [flags]

Flags:
  -exclude
        Forbid the use of exclude directives
  -godebug
        Forbid the use of godebug directives
  -goversion string
        Pattern to validate go min version directive
  -h    Show this help.
  -ignore
        Forbid the use of ignore directives
  -list value
        List of allowed replace directives
  -local
        Allow local replace directives
  -retract-no-explanation
        Allow to use retract directives without explanation
  -tool
        Forbid the use of tool directives
  -toolchain
        Forbid the use of toolchain directive
  -toolchain-pattern string
        Pattern to validate toolchain directive

Details

retract directives

  • Force explanation for retract directives.
module example.com/foo

go 1.22

require (
	github.com/ldez/grignotin v0.4.1
)

retract (
    v1.0.0 // Explanation
)

replace directives

  • Ban all replace directives.
  • Allow only local replace directives.
  • Allow only some replace directives.
  • Detect duplicated replace directives.
  • Detect identical replace directives.
module example.com/foo

go 1.22

require (
	github.com/ldez/grignotin v0.4.1
)

replace github.com/ldez/grignotin => ../grignotin/

exclude directives

  • Ban all exclude directives.
module example.com/foo

go 1.22

require (
	github.com/ldez/grignotin v0.4.1
)

exclude (
    golang.org/x/crypto v1.4.5
    golang.org/x/text v1.6.7
)

ignore directives

  • Ban all ignore directives.
module example.com/foo

go 1.25

require (
	github.com/ldez/grignotin v0.4.1
)

ignore (
    ./foo/bar/path
    foo/bar
)

tool directives

  • Ban all tool directives.
module example.com/foo

go 1.24

tool (
    example.com/module/cmd/a
    example.com/module/cmd/b
)

toolchain directive

  • Ban toolchain directive.
  • Use a regular expression to constraint the Go minimum version.
module example.com/foo

go 1.22

toolchain go1.23.3

godebug directives

  • Ban godebug directive.
module example.com/foo

go 1.22

godebug default=go1.21
godebug (
    panicnil=1
    asynctimerchan=0
)

go directive

  • Use a regular expression to constraint the Go minimum version.
module example.com/foo

go 1.22.0

About

A linter that handle directives into `go.mod`.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •