Skip to content

Commit

Permalink
ci(gci/import): improve golangci.yml and add gci linter (#4010)
Browse files Browse the repository at this point in the history
  • Loading branch information
houseme authored Dec 7, 2024
1 parent 2066aa4 commit b0b84a3
Showing 182 changed files with 429 additions and 307 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/doc-build.yml
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ jobs:
- name: Set Up Golang Environment
uses: actions/setup-go@v5
with:
go-version: 1.22.5
go-version: 1.23.4
cache: false
- name: download goframe docs
run: ./download.sh
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ jobs:
golangci:
strategy:
matrix:
go-version: [ '1.20','1.21.4','1.22', '1.23' ]
go-version: [ '1.20','1.21.4','1.22','1.23' ]
name: golangci-lint
runs-on: ubuntu-latest
steps:
@@ -41,5 +41,5 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.60.1
args: --timeout 3m0s
version: v1.62.2
args: --timeout 3m0s
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ jobs:
- name: Set Up Golang Environment
uses: actions/setup-go@v5
with:
go-version: 1.22.5
go-version: 1.23.4

- name: Build CLI Binary
run: |
63 changes: 48 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -40,9 +40,11 @@ linters:
- errcheck # Errcheck is a program for checking for unchecked errors in go programs.
- errchkjson # Checks types passed to the JSON encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
- funlen # Tool for detection of long functions
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- goimports # Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
- gci # Gci controls Go package import order and makes it always deterministic.
- goconst # Finds repeated strings that could be replaced by a constant
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- gosimple # Linter for Go source code that specializes in simplifying code
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- misspell # Finds commonly misspelled English words in comments
@@ -79,7 +81,51 @@ linters-settings:
locale: US
ignore-words:
- cancelled

# https://golangci-lint.run/usage/linters/#gofmt
gofmt:
# Simplify code: gofmt with `-s` option.
# Default: true
simplify: true
# Apply the rewrite rules to the source before reformatting.
# https://pkg.go.dev/cmd/gofmt
# Default: []
rewrite-rules: [ ]
# - pattern: 'interface{}'
# replacement: 'any'
# - pattern: 'a[b:len(a)]'
# replacement: 'a[b:]'
goimports:
# A comma-separated list of prefixes, which, if set, checks import paths
# with the given prefixes are grouped after 3rd-party packages.
# Default: ""
local-prefixes: github.com/gogf/gf/v2
gci:
# Section configuration to compare against.
# Section names are case-insensitive and may contain parameters in ().
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
# If `custom-order` is `true`, it follows the order of `sections` option.
# Default: ["standard", "default"]
sections:
- standard # Standard section: captures all standard packages.
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
- default # Default section: contains all imports that could not be matched to another section type.
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
# - alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
# - localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
- prefix(github.com/gogf/gf) # Custom section: groups all imports with the specified Prefix.
- prefix(github.com/gogf/gf/cmd) # Custom section: groups all imports with the specified Prefix.
- prefix(github.com/gogf/gfcontrib) # Custom section: groups all imports with the specified Prefix.
- prefix(github.com/gogf/gf/example) # Custom section: groups all imports with the specified Prefix.
# Skip generated files.
# Default: true
skip-generated: true
# Enable custom order of sections.
# If `true`, make the section order the same as the order of `sections`.
# Default: false
custom-order: true
# Drops lexical ordering for custom sections.
# Default: false
no-lex-order: true
# https://golangci-lint.run/usage/linters/#revive
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
revive:
@@ -259,16 +305,3 @@ linters-settings:
# Default: ["*"]
checks: [ "all","-SA1019","-SA4015","-SA1029","-SA1016","-SA9003","-SA4006","-SA6003" ]

# https://golangci-lint.run/usage/linters/#gofmt
gofmt:
# Simplify code: gofmt with `-s` option.
# Default: true
simplify: true
# Apply the rewrite rules to the source before reformatting.
# https://pkg.go.dev/cmd/gofmt
# Default: []
rewrite-rules: [ ]
# - pattern: 'interface{}'
# replacement: 'any'
# - pattern: 'a[b:len(a)]'
# replacement: 'a[b:]'
3 changes: 2 additions & 1 deletion cmd/gf/gfcmd/gfcmd.go
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ import (
"context"
"runtime"

_ "github.com/gogf/gf/cmd/gf/v2/internal/packed"

"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
@@ -19,7 +21,6 @@ import (
"github.com/gogf/gf/v2/text/gstr"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd"
_ "github.com/gogf/gf/cmd/gf/v2/internal/packed"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
)
3 changes: 2 additions & 1 deletion cmd/gf/internal/cmd/cmd_doc.go
Original file line number Diff line number Diff line change
@@ -16,10 +16,11 @@ import (
"path/filepath"
"time"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/encoding/gcompress"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
)

const (
8 changes: 4 additions & 4 deletions cmd/gf/internal/cmd/cmd_fix.go
Original file line number Diff line number Diff line change
@@ -9,14 +9,14 @@ package cmd
import (
"context"

"github.com/gogf/gf/v2/os/gproc"
"github.com/gogf/gf/v2/text/gregex"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gproc"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
)

var (
7 changes: 4 additions & 3 deletions cmd/gf/internal/cmd/cmd_init.go
Original file line number Diff line number Diff line change
@@ -12,16 +12,17 @@ import (
"os"
"strings"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gproc"
"github.com/gogf/gf/v2/os/gres"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gtag"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/allyes"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
)

var (
5 changes: 3 additions & 2 deletions cmd/gf/internal/cmd/cmd_up.go
Original file line number Diff line number Diff line change
@@ -13,14 +13,15 @@ import (

"github.com/gogf/selfupdate"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
"github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/os/gproc"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gtag"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
)

var (
3 changes: 2 additions & 1 deletion cmd/gf/internal/cmd/cmd_z_unit_gen_ctrl_test.go
Original file line number Diff line number Diff line change
@@ -10,11 +10,12 @@ import (
"path/filepath"
"testing"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genctrl"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/guid"
"github.com/gogf/gf/v2/util/gutil"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genctrl"
)

func Test_Gen_Ctrl_Default(t *testing.T) {
3 changes: 2 additions & 1 deletion cmd/gf/internal/cmd/cmd_z_unit_gen_dao_test.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import (
"path/filepath"
"testing"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcfg"
@@ -20,6 +19,8 @@ import (
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/guid"
"github.com/gogf/gf/v2/util/gutil"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/gendao"
)

func Test_Gen_Dao_Default(t *testing.T) {
3 changes: 2 additions & 1 deletion cmd/gf/internal/cmd/cmd_z_unit_gen_pb_test.go
Original file line number Diff line number Diff line change
@@ -10,11 +10,12 @@ import (
"path/filepath"
"testing"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genpb"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/guid"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genpb"
)

func TestGenPbIssue3882(t *testing.T) {
3 changes: 2 additions & 1 deletion cmd/gf/internal/cmd/cmd_z_unit_gen_pbentity_test.go
Original file line number Diff line number Diff line change
@@ -11,12 +11,13 @@ import (
"path/filepath"
"testing"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genpbentity"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/guid"
"github.com/gogf/gf/v2/util/gutil"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genpbentity"
)

func Test_Gen_Pbentity_Default(t *testing.T) {
3 changes: 2 additions & 1 deletion cmd/gf/internal/cmd/cmd_z_unit_gen_service_test.go
Original file line number Diff line number Diff line change
@@ -10,11 +10,12 @@ import (
"path/filepath"
"testing"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genservice"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/test/gtest"
"github.com/gogf/gf/v2/util/guid"
"github.com/gogf/gf/v2/util/gutil"

"github.com/gogf/gf/cmd/gf/v2/internal/cmd/genservice"
)

func Test_Gen_Service_Default(t *testing.T) {
3 changes: 2 additions & 1 deletion cmd/gf/internal/cmd/genctrl/genctrl_calculate.go
Original file line number Diff line number Diff line change
@@ -7,10 +7,11 @@
package genctrl

import (
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
)

func (c CGenCtrl) getApiItemsInSrc(apiModuleFolderPath string) (items []apiItem, err error) {
5 changes: 3 additions & 2 deletions cmd/gf/internal/cmd/genctrl/genctrl_generate_ctrl.go
Original file line number Diff line number Diff line change
@@ -11,12 +11,13 @@ import (
"path/filepath"
"strings"

"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"

"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
)

type controllerGenerator struct{}
3 changes: 2 additions & 1 deletion cmd/gf/internal/cmd/genctrl/genctrl_generate_ctrl_clear.go
Original file line number Diff line number Diff line change
@@ -9,9 +9,10 @@ package genctrl
import (
"fmt"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
)

type controllerClearer struct{}
7 changes: 4 additions & 3 deletions cmd/gf/internal/cmd/genctrl/genctrl_generate_interface.go
Original file line number Diff line number Diff line change
@@ -10,15 +10,16 @@ import (
"fmt"
"path/filepath"

"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
"github.com/gogf/gf/v2/container/gmap"
"github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"

"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
)

type apiInterfaceGenerator struct{}
5 changes: 3 additions & 2 deletions cmd/gf/internal/cmd/genctrl/genctrl_generate_sdk.go
Original file line number Diff line number Diff line change
@@ -10,13 +10,14 @@ import (
"fmt"
"path/filepath"

"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/container/gset"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"

"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
)

type apiSdkGenerator struct{}
2 changes: 1 addition & 1 deletion cmd/gf/internal/cmd/gendao/gendao.go
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@ import (

"golang.org/x/mod/modfile"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
"github.com/gogf/gf/v2/container/garray"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
@@ -24,6 +23,7 @@ import (
"github.com/gogf/gf/v2/util/gtag"

"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/utils"
)

const (
5 changes: 3 additions & 2 deletions cmd/gf/internal/cmd/genenums/genenums.go
Original file line number Diff line number Diff line change
@@ -11,12 +11,13 @@ import (

"golang.org/x/tools/go/packages"

"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gtag"

"github.com/gogf/gf/cmd/gf/v2/internal/consts"
"github.com/gogf/gf/cmd/gf/v2/internal/utility/mlog"
)

type (
Loading

0 comments on commit b0b84a3

Please sign in to comment.