Skip to content

godox: report print absolute path #5976

@stanhu

Description

@stanhu

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

How did you install golangci-lint?

Official binary

Description of the problem

The godox linter includes absolute file paths in its error messages on macOS, ignoring the run.relative-path-mode setting, while it works correctly on Linux.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 2.3.1 built with go1.24.5 from 5256574b on 2025-08-02T21:24:45Z

Configuration

# paste configuration file or CLI flags here

Go environment

$ go version && go env
go version go1.24.5 linux/amd64
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN='/home/stanhu/.local/share/mise/installs/go/1.23.4/bin'
GOCACHE='/home/stanhu/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/stanhu/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build647045498=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/tmp/test/go.mod'
GOMODCACHE='/home/stanhu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/stanhu/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/stanhu/go/pkg/mod/golang.org/[email protected]'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/stanhu/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/stanhu/go/pkg/mod/golang.org/[email protected]/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.5'
GOWORK=''
PKG_CONFIG='pkg-config'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
# paste output here

A minimal reproducible example or link to a public repository

Steps to Reproduce

  1. Create a minimal Go project:
mkdir godox-path-issue
cd godox-path-issue
go mod init example.com/godox-test
  1. Create main.go:
package main

import "fmt"

func main() {
	// TODO: This is a test comment to trigger godox
	fmt.Println("Hello, World!")
}
  1. Create .golangci.yml:
version: "2"

output:
  formats:
    text:
      path: stdout

linters:
  default: none
  enable:
    - godox
  settings:
    godox:
      keywords:
        - TODO
        - FIXME
        - BUG
  1. Run golangci-lint:
golangci-lint run

Expected Behavior

Output should show relative paths consistently across platforms:

main.go:6:2: main.go:6: Line contains TODO: "TODO: This is a test comment to trigger godox" (godox)

Actual Behavior

On Linux (correct):

main.go:6:2: main.go:6: Line contains TODO: "TODO: This is a test comment to trigger godox" (godox)

On macOS (incorrect):

main.go:6:2: /full/absolute/path/to/godox-path-issue/main.go:6: Line contains TODO: "TODO: This is a test comment to trigger godox" (godox)

Analysis

The issue is in the godox linter implementation where it directly uses pos.Filename from Go's token.FileSet:

https://github.com/matoous/godox/blob/1d6ac9d899726279072e1c4d2b10f1eb52f22878/godox.go#L55-L61

// In matoous/godox package
Message: fmt.Sprintf(
    "%s:%d: Line contains %s: %q",
    filepath.Clean(pos.Filename),  // ← Uses absolute path from token.FileSet
    pos.Line+lineNum,
    strings.Join(keywords, "/"),
    sComment,
)

This bypasses golangci-lint's relative-path-mode setting because the godox linter constructs its own message string instead of letting golangci-lint format the file path.

Proposed Solution

The godox linter should either:

  1. Not include file paths in its message (let golangci-lint handle path formatting), or
  2. Respect golangci-lint's path formatting preferences

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions