Skip to content

golangci-lint reports "undefined" for variables declared in other files within the same package #900

Description

@juniorsaldanha

Behavior
When using nvim-lint with the golangci-lint linter, I receive "undefined" errors for types or variables that are defined in different files but belong to the same Go package.

For example, if main.go uses a struct Resolution defined in models.go (both in package main), the linter marks Resolution as undefined.

Steps to Reproduce
Create two files in the same directory: file_a.go and file_b.go.

Set both to package example.

Define a variable in file_a.go.

Reference that variable in file_b.go.

Open file_b.go in Neovim with nvim-lint active.

Actual Result
The diagnostic shows: undefined: [VariableName]

Expected Result
The linter should recognize the package context and not report an error for symbols defined within the same package.

Environment
nvim-lint version: commit hash ca6ea12

golangci-lint version: 2.7.2 (Note: please verify if this is 1.27.2 or similar)

Neovim version: v0.11.5

Go version: go1.25.4 darwin/arm64

Additional Context
This usually occurs when the linter is called on a single file (e.g., golangci-lint run path/to/file.go) instead of the package directory (e.g., golangci-lint run ./...). I am looking for the best way to configure nvim-lint to pass the directory context instead of just the buffer file path.

Image Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions