Skip to content

golangci-lint v2 flags have changed #4781

Open
@offbyone

Description

@offbyone

Thank you for the bug report

  • I am using the latest version of lsp-mode related packages.
    I checked FAQ and Troubleshooting sections
    You may also try reproduce the issue using clean environment using the following command: M-x lsp-start-plain

Bug description

The flags defined in clients/lsp-golangci-lint.el are not compatible with v2 of golangci-lint:

(defun lsp-golangci-lint--get-initialization-options ()
  "Return initialization options for golangci-lint-langserver."
  (let ((opts (make-hash-table :test 'equal))
        (command (vconcat `(,lsp-golangci-lint-path)
                          ["run" "--out-format=json" "--issues-exit-code=1"]
                          (lsp-golangci-lint--run-args))))
    (puthash "command" command opts)
    opts))

The flag to output json has changed to --output.json.path=stdout: golangci/golangci-lint#5612

Steps to reproduce

  1. upgrade golangcli-lint to v2
  2. enable the LSP

Expected behavior

It should work

Which Language Server did you use?

golangci-lint

OS

MacOS

Error callstack

There's no error, it reports as a flycheck error

Anything else?

No response

Activity

Z01d-b3rg

Z01d-b3rg commented on May 23, 2025

@Z01d-b3rg

Had the same issue and was able to fix it by changing the initialization options to the following:

(defun lsp-golangci-lint--get-initialization-options ()
  "Return initialization options for golangci-lint-langserver."
  (let ((opts (make-hash-table :test 'equal))
        (command (vconcat `(,lsp-golangci-lint-path)
                          ["run" "--output.json.path" "stdout" "--show-stats=false" "--issues-exit-code=1"]
                          (lsp-golangci-lint--run-args))))
    (puthash "command" command opts)
    opts))

And when using golangci configuration files not located in the repository root, I had to also configure the relative-path-mode

# file: .golangci.yaml
run:
  # The mode used to evaluate relative paths.
  # It's used by exclusions, Go plugins, and some linters.
  # The value can be:
  # - `gomod`: the paths will be relative to the directory of the `go.mod` file.
  # - `gitroot`: the paths will be relative to the git root (the parent directory of `.git`).
  # - `cfg`: the paths will be relative to the configuration file.
  # - `wd` (NOT recommended): the paths will be relative to the place where golangci-lint is run.
  # Default: cfg
  relative-path-mode: gitroot
hiroxy

hiroxy commented on Jun 17, 2025

@hiroxy
Contributor

This issue has probably been fixed in #4810.

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @offbyone@Z01d-b3rg@hiroxy

        Issue actions

          golangci-lint v2 flags have changed · Issue #4781 · emacs-lsp/lsp-mode