diff --git a/conf/.golangci.yml b/conf/.golangci.yml new file mode 100644 index 0000000000..968130e887 --- /dev/null +++ b/conf/.golangci.yml @@ -0,0 +1,41 @@ +# .golangci.yml +run: + # timeout for the whole golangci-lint run, including linters loading, analyzing source code, etc + timeout: 10m + +issues: + # Code is grouped by package for the application. If you have multiple projects inside a repository, this value can be `folder` + # You can also have issues grouped by default "none" + # Valid values are: package, folder, file + # Default is "package" + grouping: package + + exclude-rules: + # Exclude some linters from all packages + - linters: + - errcheck + text: "SA4006" # exclude `SA4006` from `errcheck` + +linters-settings: + govet: + check-shadowing: true + + # configuration for `golint` + golint: + min-confidence: 0.8 + + gocyclo: + min-complexity: 10 + + misspell: + locale: US + +linters: + disable-all: true + enable: + - govet + - golint + - gocyclo + - misspell + + diff --git a/lisp/init-golang-local.el b/lisp/init-golang-local.el index 4b9d2db651..502b261ca3 100644 --- a/lisp/init-golang-local.el +++ b/lisp/init-golang-local.el @@ -44,6 +44,7 @@ (eval-after-load 'flycheck '(add-hook 'go-mode-hook #'flycheck-golangci-lint-setup)) + (setq flycheck-gometalinter-vendor t) (setq flycheck-gometalinter-enable-linters '("golangci-lint")) (setq flycheck-gometalinter-deadline "10s") @@ -58,8 +59,18 @@ (local-set-key (kbd "C-c s") #'alison-go-tag-add) (local-set-key (kbd "C-c T") #'go-tag-remove))) +(defun restart-golangci-lint () + "Restart golangci-lint." + (interactive) + (flycheck-stop) + (flycheck-buffer)) + +(add-hook 'go-mode-hook + (lambda () + (local-set-key (kbd "C-c l") #'restart-golangci-lint))) + (setq gofmt-command "goimports") -(setq gofmt-args '("-local" "git.code.oa.com")) +;; (setq gofmt-args '("-local" "git.code.oa.com")) (add-hook 'before-save-hook 'gofmt-before-save) (setq go-test-args "-gcflags=all=-l") @@ -115,6 +126,8 @@ (lsp-treemacs-sync-mode 1) +(setq lsp-log-io t) + (setq lsp-auto-guess-root t) (setq lsp-enable-text-document-color t) @@ -127,6 +140,20 @@ (advice-add #'company-yasnippet :around #'company-yasnippet/disable-after-dot) +(defun my-go-mode-hook () + (add-hook 'after-save-hook 'go-mod-tidy nil 'make-it-local)) + +(defun go-mod-tidy () + "Run 'go mod tidy' in the project root." + (interactive) + (when (and (string-equal major-mode 'go-mode) + (projectile-project-p)) + (let ((default-directory (projectile-project-root))) + (shell-command "go mod tidy")))) + +(add-hook 'go-mode-hook 'my-go-mode-hook) + + (provide 'init-golang-local) (provide 'init-lsp-mode-local) ;;; init-golang-local.el ends here