From 809768cffe77876d93231b5e4a4114d7f4ce8d29 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Sat, 12 Jul 2025 17:32:39 +0300 Subject: [PATCH] chore: enable formatters in golangci-lint config (#1421) --- .github/workflows/lint.yaml | 13 ------------- .golangci.yml | 12 ++++++++++++ Makefile | 5 ++++- cli/main.go | 3 ++- formatter/friendly.go | 1 + formatter/sarif.go | 1 + formatter/stylish.go | 1 + revivelib/core.go | 1 + revivelib/core_test.go | 1 + rule/cognitive_complexity.go | 3 ++- rule/struct_tag.go | 1 + test/redundant_import_alias_test.go | 3 ++- 12 files changed, 28 insertions(+), 17 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 7d732f9..582446c 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -19,19 +19,6 @@ jobs: git diff --exit-code go.mod git diff --exit-code go.sum - gofmt: - name: Check unformatted Go code - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version: stable - - name: Run gofmt - run: | - find . -type f -name '*.go' -not -path './testdata/*' -exec gofmt -w {} + - git diff --exit-code - lint-go: name: Lint Go runs-on: ubuntu-latest diff --git a/.golangci.yml b/.golangci.yml index 09c793c..faec9a2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -90,6 +90,18 @@ linters: - name: var-declaration - name: var-naming +formatters: + enable: + - gci + - gofmt + - goimports + settings: + gci: + sections: + - standard + - default + - prefix(github.com/mgechev/revive) + issues: # Show all issues from a linter. max-issues-per-linter: 0 diff --git a/Makefile b/Makefile index e6d6ad2..446c5c4 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,10 @@ build: lint: revive --config revive.toml ./... + golangci-lint run + +fmt: + golangci-lint fmt test: @go test -v -race ./... - diff --git a/cli/main.go b/cli/main.go index 17f8753..25eaec9 100644 --- a/cli/main.go +++ b/cli/main.go @@ -10,9 +10,10 @@ import ( "strings" "github.com/fatih/color" + "github.com/spf13/afero" + "github.com/mgechev/revive/config" "github.com/mgechev/revive/revivelib" - "github.com/spf13/afero" ) const ( diff --git a/formatter/friendly.go b/formatter/friendly.go index 5b626e1..de24df8 100644 --- a/formatter/friendly.go +++ b/formatter/friendly.go @@ -10,6 +10,7 @@ import ( "text/tabwriter" "github.com/fatih/color" + "github.com/mgechev/revive/lint" ) diff --git a/formatter/sarif.go b/formatter/sarif.go index 158d2c5..c177649 100644 --- a/formatter/sarif.go +++ b/formatter/sarif.go @@ -6,6 +6,7 @@ import ( "strings" "codeberg.org/chavacava/garif" + "github.com/mgechev/revive/lint" ) diff --git a/formatter/stylish.go b/formatter/stylish.go index f1472cc..8185e8b 100644 --- a/formatter/stylish.go +++ b/formatter/stylish.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/fatih/color" + "github.com/mgechev/revive/lint" ) diff --git a/revivelib/core.go b/revivelib/core.go index bf2da86..74639b7 100755 --- a/revivelib/core.go +++ b/revivelib/core.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/mgechev/dots" + "github.com/mgechev/revive/config" "github.com/mgechev/revive/lint" "github.com/mgechev/revive/logging" diff --git a/revivelib/core_test.go b/revivelib/core_test.go index 35d41ce..8b9bc75 100644 --- a/revivelib/core_test.go +++ b/revivelib/core_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/fatih/color" + "github.com/mgechev/revive/config" "github.com/mgechev/revive/lint" "github.com/mgechev/revive/revivelib" diff --git a/rule/cognitive_complexity.go b/rule/cognitive_complexity.go index 53aeae1..901fc60 100644 --- a/rule/cognitive_complexity.go +++ b/rule/cognitive_complexity.go @@ -5,8 +5,9 @@ import ( "go/ast" "go/token" - "github.com/mgechev/revive/lint" "golang.org/x/tools/go/ast/astutil" + + "github.com/mgechev/revive/lint" ) // CognitiveComplexityRule sets restriction for maximum cognitive complexity. diff --git a/rule/struct_tag.go b/rule/struct_tag.go index c3b98ac..ce7aa24 100644 --- a/rule/struct_tag.go +++ b/rule/struct_tag.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/fatih/structtag" + "github.com/mgechev/revive/internal/astutils" "github.com/mgechev/revive/lint" ) diff --git a/test/redundant_import_alias_test.go b/test/redundant_import_alias_test.go index a91e5ca..58473df 100644 --- a/test/redundant_import_alias_test.go +++ b/test/redundant_import_alias_test.go @@ -1,8 +1,9 @@ package test import ( - "github.com/mgechev/revive/rule" "testing" + + "github.com/mgechev/revive/rule" ) func TestRedundantImportAlias(t *testing.T) {