Skip to content

Commit

Permalink
Merge pull request #178 from chaosi-zju/staticcheck
Browse files Browse the repository at this point in the history
format code about goimports and gci
  • Loading branch information
karmada-bot authored Jan 23, 2025
2 parents c08f8a0 + fa4f12a commit ef734e5
Show file tree
Hide file tree
Showing 113 changed files with 569 additions and 295 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
go-version-file: go.mod
- name: verify license
run: hack/verify-license.sh
- name: lint
run: hack/verify-staticcheck.sh
build-frontend:
runs-on: ubuntu-22.04
steps:
Expand Down
108 changes: 108 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# This files contains all configuration options for analysis running.
# More details please refer to: https://golangci-lint.run/usage/configuration/

run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 10m

# One of 'readonly' and 'vendor'.
# - readonly: the go command is disallowed from the implicit automatic updating of go.mod described above.
# Instead, it fails when any changes to go.mod are needed. This setting is most useful to check
# that go.mod does not need updates, such as in a continuous integration and testing system.
# - vendor: the go command assumes that the vendor directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
modules-download-mode: readonly
linters:
enable:
# linters maintained by golang.org
- gofmt
- goimports
- govet
# linters default enabled by golangci-lint .
- errcheck
- gosimple
- ineffassign
- staticcheck
- typecheck
- unused
# other linters supported by golangci-lint.
- gci
- gocyclo
- gosec
- misspell
- whitespace
- revive
- depguard

linters-settings:
depguard:
rules:
main:
deny:
- pkg: "io/ioutil"
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
goimports:
local-prefixes: github.com/karmada-io/dashboard
gocyclo:
# minimal cyclomatic complexity to report
min-complexity: 15
gci:
sections:
- Standard
- Default
- Prefix(github.com/karmada-io/dashboard)
revive:
rules:
# Disable if-return as it is too strict and not always useful.
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return
- name: if-return
disabled: true
- name: package-comments
- name: superfluous-else
arguments:
- preserveScope
- name: error-strings
- name: error-return
- name: receiver-naming
- name: increment-decrement
- name: range
- name: error-naming
- name: dot-imports
- name: errorf
- name: exported
- name: var-declaration
- name: blank-imports
- name: indent-error-flow
- name: unreachable-code
- name: var-naming
- name: redefines-builtin-id
- name: unused-parameter
- name: context-as-argument
- name: context-keys-type
- name: unexported-return
- name: time-naming
- name: empty-block

issues:
# The list of ids of default excludes to include or disable. By default it's empty.
include:
# disable excluding of issues about comments from revive
# see https://golangci-lint.run/usage/configuration/#command-line-options for more info
- EXC0012
- EXC0013
- EXC0014
# Which dirs to exclude: issues from them won't be reported.
# Can use regexp here: `generated.*`, regexp is applied on full path,
# including the path prefix if one is set.
# Default dirs are skipped independently of this option's value (see exclude-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work on Windows.
# Default: []
exclude-dirs:
- hack/tools/preferredimports # This code is directly lifted from the Kubernetes codebase, skip checking
- (^|/)vendor($|/)
- (^|/)third_party($|/)
- pkg/util/lifted # This code is lifted from other projects(Kubernetes, Kubefed, and so on), skip checking.
# Enables exclude of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
# Default: true
exclude-dirs-use-default: false
54 changes: 27 additions & 27 deletions cmd/api/app/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ package app
import (
"context"
"fmt"
"github.com/karmada-io/dashboard/cmd/api/app/options"
"github.com/karmada-io/dashboard/cmd/api/app/router"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/config"
"github.com/karmada-io/dashboard/pkg/environment"
"os"

"github.com/karmada-io/karmada/pkg/sharedcli/klogflag"
"github.com/spf13/cobra"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog/v2"
"os"

// Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/auth"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/cluster"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/clusteroverridepolicy"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/clusterpropagationpolicy"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/config"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/configmap"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/cronjob"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/daemonset"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/deployment"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/ingress"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/job"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/namespace"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overridepolicy"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overview"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/propagationpolicy"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/secret"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/service"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/statefulset"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/unstructured"
"github.com/karmada-io/dashboard/cmd/api/app/options"
"github.com/karmada-io/dashboard/cmd/api/app/router"
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/auth" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/cluster" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/clusteroverridepolicy" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/clusterpropagationpolicy" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/config" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/configmap" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/cronjob" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/daemonset" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/deployment" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/ingress" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/job" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/member" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/namespace" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overridepolicy" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/overview" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/propagationpolicy" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/secret" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/service" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/statefulset" // Importing route packages forces route registration
_ "github.com/karmada-io/dashboard/cmd/api/app/routes/unstructured" // Importing route packages forces route registration
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/config"
"github.com/karmada-io/dashboard/pkg/environment"
)

// NewApiCommand creates a *cobra.Command object with default parameters
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ limitations under the License.
package options

import (
"github.com/spf13/pflag"
"net"

"github.com/spf13/pflag"
)

// Options contains everything necessary to create and run api.
Expand Down
6 changes: 4 additions & 2 deletions cmd/api/app/router/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ package router

import (
"context"
"net/http"

"github.com/gin-gonic/gin"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"net/http"
)

func EnsureMemberClusterMiddleware() gin.HandlerFunc {
Expand Down
1 change: 1 addition & 0 deletions cmd/api/app/router/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package router

import (
"github.com/gin-gonic/gin"

"github.com/karmada-io/dashboard/pkg/environment"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/api/app/routes/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package auth

import (
"github.com/gin-gonic/gin"
"k8s.io/klog/v2"

"github.com/karmada-io/dashboard/cmd/api/app/router"
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"k8s.io/klog/v2"
)

func handleLogin(c *gin.Context) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/app/routes/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ limitations under the License.
package auth

import (
"net/http"

v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/common/errors"
"net/http"
)

func login(spec *v1.LoginRequest, request *http.Request) (*v1.LoginResponse, int, error) {
Expand Down
4 changes: 3 additions & 1 deletion cmd/api/app/routes/auth/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ package auth
import (
"bytes"
"encoding/json"
"net/http"

"github.com/golang-jwt/jwt/v5"

v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/common/errors"
"net/http"
)

const (
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/app/routes/cluster/accesscluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package cluster
import (
"context"
"fmt"
"time"

clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
karmadaclientset "github.com/karmada-io/karmada/pkg/generated/clientset/versioned"
cmdutil "github.com/karmada-io/karmada/pkg/karmadactl/util"
Expand All @@ -32,7 +34,6 @@ import (
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/klog/v2"
"time"
)

const (
Expand Down
14 changes: 8 additions & 6 deletions cmd/api/app/routes/cluster/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ package cluster
import (
"context"
"fmt"
"time"

"github.com/gin-gonic/gin"
"github.com/karmada-io/dashboard/cmd/api/app/router"
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/resource/cluster"
"github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"time"

"github.com/karmada-io/dashboard/cmd/api/app/router"
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/resource/cluster"
)

func handleGetClusterList(c *gin.Context) {
Expand Down
12 changes: 7 additions & 5 deletions cmd/api/app/routes/clusteroverridepolicy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ package propagationpolicy

import (
"context"

"github.com/gin-gonic/gin"
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
"sigs.k8s.io/yaml"

"github.com/karmada-io/dashboard/cmd/api/app/router"
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/common/errors"
"github.com/karmada-io/dashboard/pkg/resource/clusteroverridepolicy"
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
"sigs.k8s.io/yaml"
)

func handleGetClusterOverridePolicyList(c *gin.Context) {
Expand Down
12 changes: 7 additions & 5 deletions cmd/api/app/routes/clusterpropagationpolicy/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ package propagationpolicy

import (
"context"

"github.com/gin-gonic/gin"
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
"sigs.k8s.io/yaml"

"github.com/karmada-io/dashboard/cmd/api/app/router"
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/common/errors"
"github.com/karmada-io/dashboard/pkg/resource/clusterpropagationpolicy"
"github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
"k8s.io/klog/v2"
"sigs.k8s.io/yaml"
)

func handleGetClusterPropagationPolicyList(c *gin.Context) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/app/routes/config/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ package config

import (
"github.com/gin-gonic/gin"
"k8s.io/klog/v2"

"github.com/karmada-io/dashboard/cmd/api/app/router"
v1 "github.com/karmada-io/dashboard/cmd/api/app/types/api/v1"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
"github.com/karmada-io/dashboard/pkg/config"
"k8s.io/klog/v2"
)

func GetDashboardConfig(c *gin.Context) {
Expand Down
1 change: 1 addition & 0 deletions cmd/api/app/routes/configmap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package service

import (
"github.com/gin-gonic/gin"

"github.com/karmada-io/dashboard/cmd/api/app/router"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
Expand Down
1 change: 1 addition & 0 deletions cmd/api/app/routes/cronjob/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package deployment

import (
"github.com/gin-gonic/gin"

"github.com/karmada-io/dashboard/cmd/api/app/router"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
Expand Down
1 change: 1 addition & 0 deletions cmd/api/app/routes/daemonset/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package deployment

import (
"github.com/gin-gonic/gin"

"github.com/karmada-io/dashboard/cmd/api/app/router"
"github.com/karmada-io/dashboard/cmd/api/app/types/common"
"github.com/karmada-io/dashboard/pkg/client"
Expand Down
Loading

0 comments on commit ef734e5

Please sign in to comment.