Skip to content

Commit ef734e5

Browse files
authored
Merge pull request #178 from chaosi-zju/staticcheck
format code about goimports and gci
2 parents c08f8a0 + fa4f12a commit ef734e5

File tree

113 files changed

+569
-295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+569
-295
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
go-version-file: go.mod
3030
- name: verify license
3131
run: hack/verify-license.sh
32+
- name: lint
33+
run: hack/verify-staticcheck.sh
3234
build-frontend:
3335
runs-on: ubuntu-22.04
3436
steps:

.golangci.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# This files contains all configuration options for analysis running.
2+
# More details please refer to: https://golangci-lint.run/usage/configuration/
3+
4+
run:
5+
# timeout for analysis, e.g. 30s, 5m, default is 1m
6+
timeout: 10m
7+
8+
# One of 'readonly' and 'vendor'.
9+
# - readonly: the go command is disallowed from the implicit automatic updating of go.mod described above.
10+
# Instead, it fails when any changes to go.mod are needed. This setting is most useful to check
11+
# that go.mod does not need updates, such as in a continuous integration and testing system.
12+
# - vendor: the go command assumes that the vendor directory holds the correct copies of dependencies and ignores
13+
# the dependency descriptions in go.mod.
14+
modules-download-mode: readonly
15+
linters:
16+
enable:
17+
# linters maintained by golang.org
18+
- gofmt
19+
- goimports
20+
- govet
21+
# linters default enabled by golangci-lint .
22+
- errcheck
23+
- gosimple
24+
- ineffassign
25+
- staticcheck
26+
- typecheck
27+
- unused
28+
# other linters supported by golangci-lint.
29+
- gci
30+
- gocyclo
31+
- gosec
32+
- misspell
33+
- whitespace
34+
- revive
35+
- depguard
36+
37+
linters-settings:
38+
depguard:
39+
rules:
40+
main:
41+
deny:
42+
- pkg: "io/ioutil"
43+
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
44+
goimports:
45+
local-prefixes: github.com/karmada-io/dashboard
46+
gocyclo:
47+
# minimal cyclomatic complexity to report
48+
min-complexity: 15
49+
gci:
50+
sections:
51+
- Standard
52+
- Default
53+
- Prefix(github.com/karmada-io/dashboard)
54+
revive:
55+
rules:
56+
# Disable if-return as it is too strict and not always useful.
57+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return
58+
- name: if-return
59+
disabled: true
60+
- name: package-comments
61+
- name: superfluous-else
62+
arguments:
63+
- preserveScope
64+
- name: error-strings
65+
- name: error-return
66+
- name: receiver-naming
67+
- name: increment-decrement
68+
- name: range
69+
- name: error-naming
70+
- name: dot-imports
71+
- name: errorf
72+
- name: exported
73+
- name: var-declaration
74+
- name: blank-imports
75+
- name: indent-error-flow
76+
- name: unreachable-code
77+
- name: var-naming
78+
- name: redefines-builtin-id
79+
- name: unused-parameter
80+
- name: context-as-argument
81+
- name: context-keys-type
82+
- name: unexported-return
83+
- name: time-naming
84+
- name: empty-block
85+
86+
issues:
87+
# The list of ids of default excludes to include or disable. By default it's empty.
88+
include:
89+
# disable excluding of issues about comments from revive
90+
# see https://golangci-lint.run/usage/configuration/#command-line-options for more info
91+
- EXC0012
92+
- EXC0013
93+
- EXC0014
94+
# Which dirs to exclude: issues from them won't be reported.
95+
# Can use regexp here: `generated.*`, regexp is applied on full path,
96+
# including the path prefix if one is set.
97+
# Default dirs are skipped independently of this option's value (see exclude-dirs-use-default).
98+
# "/" will be replaced by current OS file path separator to properly work on Windows.
99+
# Default: []
100+
exclude-dirs:
101+
- hack/tools/preferredimports # This code is directly lifted from the Kubernetes codebase, skip checking
102+
- (^|/)vendor($|/)
103+
- (^|/)third_party($|/)
104+
- pkg/util/lifted # This code is lifted from other projects(Kubernetes, Kubefed, and so on), skip checking.
105+
# Enables exclude of directories:
106+
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
107+
# Default: true
108+
exclude-dirs-use-default: false

cmd/api/app/api.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,38 @@ package app
1919
import (
2020
"context"
2121
"fmt"
22-
"github.com/karmada-io/dashboard/cmd/api/app/options"
23-
"github.com/karmada-io/dashboard/cmd/api/app/router"
24-
"github.com/karmada-io/dashboard/pkg/client"
25-
"github.com/karmada-io/dashboard/pkg/config"
26-
"github.com/karmada-io/dashboard/pkg/environment"
22+
"os"
23+
2724
"github.com/karmada-io/karmada/pkg/sharedcli/klogflag"
2825
"github.com/spf13/cobra"
2926
cliflag "k8s.io/component-base/cli/flag"
3027
"k8s.io/klog/v2"
31-
"os"
3228

33-
// Importing route packages forces route registration
34-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/auth"
35-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/cluster"
36-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/clusteroverridepolicy"
37-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/clusterpropagationpolicy"
38-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/config"
39-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/configmap"
40-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/cronjob"
41-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/daemonset"
42-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/deployment"
43-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/ingress"
44-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/job"
45-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member"
46-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/namespace"
47-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overridepolicy"
48-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overview"
49-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/propagationpolicy"
50-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/secret"
51-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/service"
52-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/statefulset"
53-
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/unstructured"
29+
"github.com/karmada-io/dashboard/cmd/api/app/options"
30+
"github.com/karmada-io/dashboard/cmd/api/app/router"
31+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/auth" // Importing route packages forces route registration
32+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/cluster" // Importing route packages forces route registration
33+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/clusteroverridepolicy" // Importing route packages forces route registration
34+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/clusterpropagationpolicy" // Importing route packages forces route registration
35+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/config" // Importing route packages forces route registration
36+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/configmap" // Importing route packages forces route registration
37+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/cronjob" // Importing route packages forces route registration
38+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/daemonset" // Importing route packages forces route registration
39+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/deployment" // Importing route packages forces route registration
40+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/ingress" // Importing route packages forces route registration
41+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/job" // Importing route packages forces route registration
42+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member" // Importing route packages forces route registration
43+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/namespace" // Importing route packages forces route registration
44+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overridepolicy" // Importing route packages forces route registration
45+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overview" // Importing route packages forces route registration
46+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/propagationpolicy" // Importing route packages forces route registration
47+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/secret" // Importing route packages forces route registration
48+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/service" // Importing route packages forces route registration
49+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/statefulset" // Importing route packages forces route registration
50+
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/unstructured" // Importing route packages forces route registration
51+
"github.com/karmada-io/dashboard/pkg/client"
52+
"github.com/karmada-io/dashboard/pkg/config"
53+
"github.com/karmada-io/dashboard/pkg/environment"
5454
)
5555

5656
// NewApiCommand creates a *cobra.Command object with default parameters

cmd/api/app/options/options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ limitations under the License.
1717
package options
1818

1919
import (
20-
"github.com/spf13/pflag"
2120
"net"
21+
22+
"github.com/spf13/pflag"
2223
)
2324

2425
// Options contains everything necessary to create and run api.

cmd/api/app/router/middleware.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ package router
1818

1919
import (
2020
"context"
21+
"net/http"
22+
2123
"github.com/gin-gonic/gin"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
2226
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
2327
"github.com/karmada-io/dashboard/pkg/client"
24-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
"net/http"
2628
)
2729

2830
func EnsureMemberClusterMiddleware() gin.HandlerFunc {

cmd/api/app/router/setup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package router
1818

1919
import (
2020
"github.com/gin-gonic/gin"
21+
2122
"github.com/karmada-io/dashboard/pkg/environment"
2223
)
2324

cmd/api/app/routes/auth/handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package auth
1818

1919
import (
2020
"github.com/gin-gonic/gin"
21+
"k8s.io/klog/v2"
22+
2123
"github.com/karmada-io/dashboard/cmd/api/app/router"
2224
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
2325
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
24-
"k8s.io/klog/v2"
2526
)
2627

2728
func handleLogin(c *gin.Context) {

cmd/api/app/routes/auth/login.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ limitations under the License.
1717
package auth
1818

1919
import (
20+
"net/http"
21+
2022
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
2123
"github.com/karmada-io/dashboard/pkg/client"
2224
"github.com/karmada-io/dashboard/pkg/common/errors"
23-
"net/http"
2425
)
2526

2627
func login(spec *v1.LoginRequest, request *http.Request) (*v1.LoginResponse, int, error) {

cmd/api/app/routes/auth/me.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ package auth
1919
import (
2020
"bytes"
2121
"encoding/json"
22+
"net/http"
23+
2224
"github.com/golang-jwt/jwt/v5"
25+
2326
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
2427
"github.com/karmada-io/dashboard/pkg/client"
2528
"github.com/karmada-io/dashboard/pkg/common/errors"
26-
"net/http"
2729
)
2830

2931
const (

cmd/api/app/routes/cluster/accesscluster.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ package cluster
1919
import (
2020
"context"
2121
"fmt"
22+
"time"
23+
2224
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
2325
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
2426
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
@@ -32,7 +34,6 @@ import (
3234
"k8s.io/client-go/tools/clientcmd"
3335
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
3436
"k8s.io/klog/v2"
35-
"time"
3637
)
3738

3839
const (

0 commit comments

Comments
 (0)