Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gocyclo to local and CI lint #1904

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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} $$_ }'
Expand Down
3 changes: 3 additions & 0 deletions cmd/skywire-cli/commands/log/st.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions cmd/skywire-cli/commands/rewards/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions cmd/skywire-cli/commands/visor/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions internal/vpn/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions internal/vpn/subnet_ip_incrementer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pkg/util/osutil/privileges_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 3 additions & 1 deletion pkg/visor/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/visor/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions pkg/visor/visorconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 2 additions & 3 deletions pkg/visor/visorconfig/values_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package visorconfig

import (
"io/ioutil"
"log"
"net"
"os"
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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)

Expand Down
Loading