How can I set up golangci-lint as the linter with my config? I've tried using flycheck-golangci-lint but it doesn't seem to be working. I'm testing my config by opening a .go file with an ineffectual assignment that trips golangci-lint when run from the CLI tool. My Go and LSP configs are:

;; lsp-mode configs
(use-package lsp-mode
  :delight lsp-lens-mode "🔍"
  :ensure t
  ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
  (setq lsp-keymap-prefix "C-c l")
  (lsp-auto-guess-root +1)
  (setq lsp-prefer-flymake nil)
  (setq lsp-headerline-breadcrumb-enable t)
  :hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
         (python-mode . lsp-deferred)
     (scala-mode . lsp-deferred)
     (sh-mode . lsp-deferred)
         (go-mode . lsp-deferred)
         ;; if you want which-key integration
         (lsp-mode . lsp-enable-which-key-integration)
     (lsp-mode . lsp-lens-mode)
     (lsp-after-open . 'lsp-enable-imenu)
  :commands (lsp lsp-deferred))

;; go-mode
(use-package go-mode
  :delight ""
  (before-save . lsp-format-buffer)
  (before-save . lsp-organize-imports)

;; flycheck-golang-ci-lint
(use-package flycheck-golangci-lint
  :ensure t
  (go-mode . flycheck-golangci-lint-setup)

Apologies for the wall of code - I want to make sure I don't miss anything that might be causing flycheck-golang-ci-lint to fail.

1 Answer 1


It seems you want to chain golangci-lint after lsp, is it? The following snippet allows you to chain other linters after lsp. I have included the link where the original solution was posted for other linters. You can see that I use the snippet to chain linters for Python and Shell.

;; https://github.com/flycheck/flycheck/issues/1762
  (with-eval-after-load 'flycheck
    (defvar-local flycheck-local-checkers nil)

    (defun flycheck-checker-get (fn checker property)
      (or (alist-get property (alist-get checker flycheck-local-checkers))
          (funcall fn checker property)))

    (advice-add 'flycheck-checker-get :around 'flycheck-checker-get)

    (add-hook 'lsp-managed-mode-hook
              (lambda ()
                (when (derived-mode-p 'python-mode)
                  (setq flycheck-local-checkers '((lsp . ((next-checkers . (python-pylint)))))))

                (when (derived-mode-p 'sh-mode)
                  (setq flycheck-local-checkers '((lsp . ((next-checkers . (sh-shellcheck)))))))
                (when (derived-mode-p 'go-mode)
                  (setq flycheck-local-checkers '((lsp . ((next-checkers . (golangci-lint)))))))

I do not use go, so unfortunately I cannot test the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.