diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6db0ed46e2..c55223f8d4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,6 +11,7 @@ jobs: - name: Install Requirements run: | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0 + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest make dep chmod +x ./ci_scripts/create-ip-aliases.sh ./ci_scripts/create-ip-aliases.sh @@ -30,6 +31,7 @@ jobs: - name: Install Requirements run: | curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0 + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest make dep chmod +x ./ci_scripts/create-ip-aliases.sh ./ci_scripts/create-ip-aliases.sh @@ -49,6 +51,7 @@ jobs: - name: Install Requirements run: | choco install make + go install github.com/fzipp/gocyclo/cmd/gocyclo@latest go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 make dep - name: Testing diff --git a/Makefile b/Makefile index 132c3e0248..133f9aead0 100644 --- a/Makefile +++ b/Makefile @@ -182,10 +182,12 @@ lint: ## Run linters. Use make install-linters first ${OPTS} golangci-lint run -c .golangci.yml ./cmd/... ${OPTS} golangci-lint run -c .golangci.yml ./pkg/... ${OPTS} golangci-lint run -c .golangci.yml ./... + gocyclo -over 14 . lint-windows: ## Run linters. Use make install-linters-windows first powershell 'golangci-lint --version' powershell 'golangci-lint run -c .golangci.yml ./...' + powershell 'gocyclo -over 14 .' test: ## Run tests -go clean -testcache &>/dev/null @@ -212,6 +214,7 @@ tidy: ## Tidies and vendors dependencies. format: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters). ${OPTS} goimports -w -local ${PROJECT_BASE} ./pkg ./cmd ./internal find . -type f -name '*.go' -not -path "./.git/*" -not -path "./vendor/*" -exec goimports-reviser -project-name ${PROJECT_BASE} {} \; + gocyclo -over 14 . format-windows: tidy ## Formats the code. Must have goimports and goimports-reviser installed (use make install-linters). powershell 'Get-ChildItem -Directory | where Name -NotMatch vendor | % { Get-ChildItem $$_ -Recurse -Include *.go } | % {goimports -w -local ${PROJECT_BASE} $$_ }' diff --git a/cmd/skywire-cli/commands/log/st.go b/cmd/skywire-cli/commands/log/st.go index b75775f683..2fb7dfd82d 100644 --- a/cmd/skywire-cli/commands/log/st.go +++ b/cmd/skywire-cli/commands/log/st.go @@ -43,6 +43,9 @@ var stCmd = &cobra.Command{ }, } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func makeTree() { utFileInfo, utFileInfoErr := os.Stat("/tmp/ut.json") utData, utDataErr := script.File("/tmp/ut.json").String() diff --git a/cmd/skywire-cli/commands/rewards/ui.go b/cmd/skywire-cli/commands/rewards/ui.go index 91ebefbda8..e716322fe2 100644 --- a/cmd/skywire-cli/commands/rewards/ui.go +++ b/cmd/skywire-cli/commands/rewards/ui.go @@ -129,6 +129,9 @@ var htmlRewardPageTemplate = ` var htmlPageTemplateData htmlTemplateData var tmpl *htmpl.Template +// TODO: fix gocyclo error. +// +//gocyclo:ignore func server() { log := logging.MustGetLogger("dmsghttp") diff --git a/cmd/skywire-cli/commands/visor/top.go b/cmd/skywire-cli/commands/visor/top.go index 61ff582d78..dbb021eff1 100644 --- a/cmd/skywire-cli/commands/visor/top.go +++ b/cmd/skywire-cli/commands/visor/top.go @@ -91,6 +91,9 @@ var ( //go:embed "description.txt" var description string +// TODO: fix gocyclo error. +// +//gocyclo:ignore func parseArgs() error { cds := conf.ConfigDir.QueryFolders(configdir.All) cpaths := make([]string, len(cds)) @@ -226,6 +229,9 @@ func setDefaultTermuiColors(c gotop.Config) { ui.Theme.Block.Border = ui.NewStyle(ui.Color(c.Colorscheme.BorderLine), ui.Color(c.Colorscheme.Bg)) } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func eventLoop(c gotop.Config, grid *layout.MyGrid) { drawTicker := time.NewTicker(c.UpdateInterval).C @@ -408,6 +414,9 @@ func eventLoop(c gotop.Config, grid *layout.MyGrid) { } } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func run() int { ling, err := lingo.New("en_US", ".", gotop.Dicts) if err != nil { diff --git a/internal/vpn/client.go b/internal/vpn/client.go index b250f96b7c..b3acddf7e3 100644 --- a/internal/vpn/client.go +++ b/internal/vpn/client.go @@ -342,6 +342,9 @@ func (c *Client) setupTUN(tunIP, tunGateway net.IP) error { return c.SetupTUN(c.tun.Name(), tunIP.String()+TUNNetmaskCIDR, tunGateway.String(), TUNMTU) } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func (c *Client) serveConn(conn net.Conn) error { tunIP, tunGateway, err := c.shakeHands(conn) if err != nil { diff --git a/internal/vpn/subnet_ip_incrementer.go b/internal/vpn/subnet_ip_incrementer.go index f686a3ee13..a940bb0f68 100644 --- a/internal/vpn/subnet_ip_incrementer.go +++ b/internal/vpn/subnet_ip_incrementer.go @@ -29,6 +29,9 @@ func newSubnetIPIncrementer(octetLowerBorders, octetBorders [4]uint8, step uint8 } } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func (inc *subnetIPIncrementer) next() (net.IP, error) { inc.mx.Lock() defer inc.mx.Unlock() diff --git a/pkg/router/router.go b/pkg/router/router.go index 80af42e6ab..8c509ff08b 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -484,6 +484,9 @@ func (r *router) serveSetup() { } } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func (r *router) saveRouteGroupRules(rules routing.EdgeRules, nsConf noise.Config) (*NoiseRouteGroup, error) { r.logger.Debugf("Saving route group rules with desc: %s", &rules.Desc) diff --git a/pkg/util/osutil/privileges_windows.go b/pkg/util/osutil/privileges_windows.go index 32ae6459c3..5c1eb3cd65 100644 --- a/pkg/util/osutil/privileges_windows.go +++ b/pkg/util/osutil/privileges_windows.go @@ -13,6 +13,6 @@ func GainRoot() (int, error) { } // ReleaseRoot releases root privileges, not needed on windows -func ReleaseRoot(oldUID int) error { +func ReleaseRoot(_ int) error { return nil } diff --git a/pkg/visor/cmd.go b/pkg/visor/cmd.go index 9b626b072b..52458d75c1 100644 --- a/pkg/visor/cmd.go +++ b/pkg/visor/cmd.go @@ -57,8 +57,10 @@ var ( isForceColor bool ) +// TODO: fix gocyclo error. +// +//gocyclo:ignore func init() { - root = visorconfig.IsRoot() RootCmd.Flags().SortFlags = false //the default is not set to fix the aesthetic of the help command diff --git a/pkg/visor/hypervisor.go b/pkg/visor/hypervisor.go index 152026e5e0..0df9842888 100644 --- a/pkg/visor/hypervisor.go +++ b/pkg/visor/hypervisor.go @@ -619,8 +619,10 @@ func (hv *Hypervisor) getAppStats() http.HandlerFunc { }) } -// TODO: simplify // nolint: funlen,gocognit,godox +// TODO: fix gocyclo error. +// +//gocyclo:ignore func (hv *Hypervisor) putApp() http.HandlerFunc { return hv.withCtx(hv.appCtx, func(w http.ResponseWriter, r *http.Request, ctx *httpCtx) { type req struct { diff --git a/pkg/visor/init.go b/pkg/visor/init.go index c793712ade..1713dd97a0 100644 --- a/pkg/visor/init.go +++ b/pkg/visor/init.go @@ -887,6 +887,9 @@ func handlePingConn(log *logging.Logger, remoteConn net.Conn, v *Visor) { } // getRouteSetupHooks aka autotransport +// TODO: fix gocyclo error. +// +//gocyclo:ignore func getRouteSetupHooks(ctx context.Context, v *Visor, log *logging.Logger) []router.RouteSetupHook { retrier := netutil.NewRetrier(log, time.Second, time.Second*20, 3, 1.3) return []router.RouteSetupHook{ @@ -1298,6 +1301,9 @@ func initEnsureVisorIsTransportable(ctx context.Context, v *Visor, log *logging. return nil } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func initEnsureTPDConcurrency(ctx context.Context, v *Visor, log *logging.Logger) error { //nolint:all const tickDuration = 5 * time.Minute ticker := time.NewTicker(tickDuration) @@ -1408,6 +1414,9 @@ func initPublicVisor(_ context.Context, v *Visor, log *logging.Logger) error { / return nil } +// TODO: fix gocyclo error. +// +//gocyclo:ignore func initDmsgpty(ctx context.Context, v *Visor, log *logging.Logger) error { conf := v.conf.Dmsgpty diff --git a/pkg/visor/visorconfig/config.go b/pkg/visor/visorconfig/config.go index b598410362..97782459a9 100644 --- a/pkg/visor/visorconfig/config.go +++ b/pkg/visor/visorconfig/config.go @@ -126,6 +126,9 @@ func MakeBaseConfig(common *Common, testEnv bool, dmsgHTTP bool, services *Servi // The config's 'sk' field will be nil if not specified. // Generated config will be saved to 'confPath'. // This function always returns the latest config version. +// TODO: fix gocyclo error. +// +//gocyclo:ignore func MakeDefaultConfig(log *logging.MasterLogger, sk *cipher.SecKey, usrEnv bool, pkgEnv bool, testEnv bool, dmsgHTTP bool, hypervisor bool, confPath, hypervisorPKs string, services *Services) (*V1, error) { if usrEnv && pkgEnv { log.Fatal("usrEnv and pkgEnv are mutually exclusive") diff --git a/pkg/visor/visorconfig/values_windows.go b/pkg/visor/visorconfig/values_windows.go index 9b2edaac90..c6ebc72c36 100644 --- a/pkg/visor/visorconfig/values_windows.go +++ b/pkg/visor/visorconfig/values_windows.go @@ -4,7 +4,6 @@ package visorconfig import ( - "io/ioutil" "log" "net" "os" @@ -121,7 +120,7 @@ func getNodeHypervisor() string { return "docker" } // Check for cgroup indicating Docker or container environment - data, err := ioutil.ReadFile("/proc/self/cgroup") + data, err := os.ReadFile("/proc/self/cgroup") if err == nil && strings.Contains(string(data), "docker") { return "docker" } @@ -171,7 +170,7 @@ func IsRoot() bool { log.Fatalf("SID Error: %s", err) return false } - defer windows.FreeSid(sid) + defer windows.FreeSid(sid) //nolint: errcheck token := windows.Token(0)