From 26accba6b1734da3ddeb4610c4fedf1ec79df3cf Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Mon, 18 Aug 2025 14:20:56 +0200 Subject: [PATCH] ci: update linter Signed-off-by: Mark Sagi-Kazar --- .editorconfig | 3 + .golangci.yaml | 124 ++++++++++++++++++ .golangci.yml | 97 -------------- Makefile | 6 +- .../atlassiancrowd/atlassiancrowd_test.go | 2 +- flake.nix | 5 +- storage/ent/mysql.go | 2 +- storage/sql/config.go | 2 +- 8 files changed, 137 insertions(+), 104 deletions(-) create mode 100644 .golangci.yaml delete mode 100644 .golangci.yml diff --git a/.editorconfig b/.editorconfig index 27917441..085f9d0e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,3 +19,6 @@ indent_style = tab [{config.yaml.dist,config.dev.yaml}] indent_size = 2 + +[.golangci.yaml] +indent_size = 2 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..9fa31418 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,124 @@ +version: "2" + +run: + timeout: 5m + +linters: + disable: + - staticcheck + - errcheck + enable: + - depguard + - dogsled + - exhaustive + - gochecknoinits + # - gocritic + - goprintffuncname + - govet + - ineffassign + - misspell + - nakedret + - nolintlint + - prealloc + # - revive + # - sqlclosecheck + # - staticcheck + - unconvert + - unused + - whitespace + + # Disable temporarily until everything works with Go 1.20 + # - bodyclose + # - rowserrcheck + # - tparallel + # - unparam + + # Disable temporarily until the following issue is resolved: https://github.com/golangci/golangci-lint/issues/3086 + # - sqlclosecheck + + # TODO: fix linter errors before enabling + # - exhaustivestruct + # - gochecknoglobals + # - errorlint + # - gocognit + # - godot + # - nlreturn + # - noctx + # - revive + # - wrapcheck + + # TODO: fix linter errors before enabling (from original config) + # - dupl + # - errcheck + # - goconst + # - gocyclo + # - gosec + # - lll + # - scopelint + + # unused + # - goheader + # - gomodguard + + # don't enable: + # - asciicheck + # - funlen + # - godox + # - goerr113 + # - gomnd + # - interfacer + # - maligned + # - nestif + # - testpackage + # - wsl + + exclusions: + rules: + - linters: + - errcheck + - noctx + path: _test.go + presets: + - comments + - std-error-handling + + settings: + misspell: + locale: US + nolintlint: + allow-unused: false # report any unused nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + gocritic: + # Enable multiple checks by tags. See "Tags" section in https://github.com/go-critic/go-critic#usage. + enabled-tags: + - diagnostic + - experimental + - opinionated + - style + disabled-checks: + - importShadow + - unnamedResult + depguard: + rules: + deprecated: + deny: + - pkg: "io/ioutil" + desc: "The 'io/ioutil' package is deprecated. Use corresponding 'os' or 'io' functions instead." + +formatters: + enable: + - gci + - gofmt + - gofumpt + - goimports + # - golines + + settings: + gci: + sections: + - standard + - default + - localmodule +# issues: +# exclude-dirs: +# - storage/ent/db # generated ent code diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index d54dcb18..00000000 --- a/.golangci.yml +++ /dev/null @@ -1,97 +0,0 @@ -run: - timeout: 4m - -linters-settings: - depguard: - rules: - deprecated: - deny: - - pkg: "io/ioutil" - desc: "The 'io/ioutil' package is deprecated. Use corresponding 'os' or 'io' functions instead." - gci: - sections: - - standard - - default - - prefix(github.com/dexidp/dex) - goimports: - local-prefixes: github.com/dexidp/dex - -linters: - disable-all: true - enable: - - depguard - - dogsled - - exhaustive - - gci - - gochecknoinits - - gocritic - - gofmt - - gofumpt - - goimports - - goprintffuncname - - gosimple - - govet - - ineffassign - - misspell - - nakedret - - nolintlint - - prealloc - # - revive - # - sqlclosecheck - - staticcheck - - stylecheck - - unconvert - - unused - - whitespace - - # Disable temporarily until everything works with Go 1.20 - # - bodyclose - # - rowserrcheck - # - tparallel - # - unparam - - # Disable temporarily until everything works with Go 1.18 - - typecheck - - # Disable temporarily until the following issue is resolved: https://github.com/golangci/golangci-lint/issues/3086 - # - sqlclosecheck - - # TODO: fix linter errors before enabling - # - exhaustivestruct - # - gochecknoglobals - # - errorlint - # - gocognit - # - godot - # - nlreturn - # - noctx - # - revive - # - wrapcheck - - # TODO: fix linter errors before enabling (from original config) - # - dupl - # - errcheck - # - goconst - # - gocyclo - # - gosec - # - lll - # - scopelint - - # unused - # - goheader - # - gomodguard - - # don't enable: - # - asciicheck - # - funlen - # - godox - # - goerr113 - # - gomnd - # - interfacer - # - maligned - # - nestif - # - testpackage - # - wsl - -issues: - exclude-dirs: - - storage/ent/db # generated ent code diff --git a/Makefile b/Makefile index 349dbc57..c9a568cb 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ export GOBIN=$(PWD)/bin LD_FLAGS="-w -X main.version=$(VERSION)" # Dependency versions -GOLANGCI_VERSION = 1.64.5 +GOLANGCI_VERSION = 2.4.0 GOTESTSUM_VERSION ?= 1.12.0 PROTOC_VERSION = 29.3 @@ -132,7 +132,7 @@ testrace: ## Test go code and check for possible race conditions. testall: testrace ## Run all tests for go code. -.PHONY: lint lint-fix +.PHONY: lint lint: ## Run linter. @golangci-lint version @golangci-lint run @@ -140,7 +140,7 @@ lint: ## Run linter. .PHONY: fix fix: ## Fix lint violations. @golangci-lint version - @golangci-lint run --fix + @golangci-lint fmt docker-compose.override.yaml: cp docker-compose.override.yaml.dist docker-compose.override.yaml diff --git a/connector/atlassiancrowd/atlassiancrowd_test.go b/connector/atlassiancrowd/atlassiancrowd_test.go index 9471fb80..17d0422a 100644 --- a/connector/atlassiancrowd/atlassiancrowd_test.go +++ b/connector/atlassiancrowd/atlassiancrowd_test.go @@ -113,7 +113,7 @@ func TestIdentityFromCrowdUser(t *testing.T) { expectEquals(t, user.Name, "testuser") expectEquals(t, user.Email, "testuser@example.com") - // Test unconfigured behaviour + // Test unconfigured behavior i := c.identityFromCrowdUser(user) expectEquals(t, i.UserID, "12345") expectEquals(t, i.Username, "testuser") diff --git a/flake.nix b/flake.nix index a2c0ab4a..214bf233 100644 --- a/flake.nix +++ b/flake.nix @@ -34,7 +34,10 @@ packages = with pkgs; [ gnumake - golangci-lint + # golangci-lint + (golangci-lint.override (o: { + buildGoModule = pkgs.buildGo125Module; + })) gotestsum protobuf protoc-gen-go diff --git a/storage/ent/mysql.go b/storage/ent/mysql.go index 008f7bad..bca6eba5 100644 --- a/storage/ent/mysql.go +++ b/storage/ent/mysql.go @@ -81,7 +81,7 @@ func (m *MySQL) driver() (*entSQL.Driver, error) { } if m.MaxIdleConns == 0 { - /* Override default behaviour to fix https://github.com/dexidp/dex/issues/1608 */ + /* Override default behavior to fix https://github.com/dexidp/dex/issues/1608 */ drv.DB().SetMaxIdleConns(0) } else { drv.DB().SetMaxIdleConns(m.MaxIdleConns) diff --git a/storage/sql/config.go b/storage/sql/config.go index 5379aeb6..222b263a 100644 --- a/storage/sql/config.go +++ b/storage/sql/config.go @@ -272,7 +272,7 @@ func (s *MySQL) open(logger *slog.Logger) (*conn, error) { } if s.MaxIdleConns == 0 { - /*Override default behaviour to fix https://github.com/dexidp/dex/issues/1608*/ + /*Override default behavior to fix https://github.com/dexidp/dex/issues/1608*/ db.SetMaxIdleConns(0) } else { db.SetMaxIdleConns(s.MaxIdleConns)