Skip to content

Commit

Permalink
chore: update golanci-lint to 1.38.0
Browse files Browse the repository at this point in the history
Fix all discovered issues.
Detected couple bugs, fixed them as well.

Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.com>
  • Loading branch information
Unix4ever authored and talos-bot committed Mar 12, 2021
1 parent 83b4e7f commit 22f3753
Show file tree
Hide file tree
Showing 88 changed files with 180 additions and 359 deletions.
10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ linters-settings:
for-loops: false # Report preallocation suggestions on for loops, false by default
gci:
local-prefixes: github.com/talos-systems/talos
cyclop:
# the maximal code complexity to report
max-complexity: 20

linters:
enable-all: true
Expand All @@ -118,6 +121,8 @@ linters:
- typecheck
- gochecknoglobals
- gochecknoinits
- ifshort
- forbidigo
- funlen
- godox
- gocognit
Expand All @@ -126,7 +131,12 @@ linters:
- nestif
- exhaustivestruct
- errorlint
- paralleltest
- thelper
- wrapcheck
# abandoned linters for which golangci shows the warning that the repo is archived by the owner
- interfacer
- maligned
disable-all: false
fast: false

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ENV PATH /toolchain/bin:/toolchain/go/bin
RUN ["/toolchain/bin/mkdir", "/bin", "/tmp"]
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/bin/bash", "/bin/sh"]
RUN ["/toolchain/bin/ln", "-svf", "/toolchain/etc/ssl", "/etc/ssl"]
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /toolchain/bin v1.32.2
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /toolchain/bin v1.38.0
ARG GOFUMPT_VERSION
RUN cd $(mktemp -d) \
&& go mod init tmp \
Expand Down
6 changes: 1 addition & 5 deletions cmd/installer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,5 @@ func runInstallCmd() (err error) {
return err
}

if err = install.Install(p, seq, options); err != nil {
return err
}

return nil
return install.Install(p, seq, options)
}
4 changes: 1 addition & 3 deletions cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ type Installer struct {
}

// NewInstaller initializes and returns an Installer.
//
//nolint:gocyclo
func NewInstaller(cmdline *procfs.Cmdline, seq runtime.Sequence, opts *Options) (i *Installer, err error) {
i = &Installer{
cmdline: cmdline,
Expand Down Expand Up @@ -162,7 +160,7 @@ func (i *Installer) probeBootPartition() error {
// Install fetches the necessary data locations and copies or extracts
// to the target locations.
//
//nolint:gocyclo
//nolint:gocyclo,cyclop
func (i *Installer) Install(seq runtime.Sequence) (err error) {
if i.options.Board != constants.BoardNone {
var b runtime.Board
Expand Down
11 changes: 3 additions & 8 deletions cmd/installer/pkg/install/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (m *Manifest) checkMounts(device Device) error {
f, err = os.Open(path)
if err != nil {
// ignore error in case process got removed
return nil
return nil //nolint:nilerr
}

defer f.Close() //nolint:errcheck
Expand All @@ -213,7 +213,7 @@ func (m *Manifest) checkMounts(device Device) error {
return nil
}

//nolint:gocyclo
//nolint:gocyclo,cyclop
func (m *Manifest) executeOnDevice(device Device, targets []*Target) (err error) {
if err = m.checkMounts(device); err != nil {
return err
Expand Down Expand Up @@ -365,11 +365,7 @@ func (m *Manifest) executeOnDevice(device Device, targets []*Target) (err error)
}
}

if err = m.restoreContents(targets); err != nil {
return err
}

return nil
return m.restoreContents(targets)
}

//nolint:gocyclo
Expand Down Expand Up @@ -506,7 +502,6 @@ func (m *Manifest) zeroDevice(device Device) (err error) {
}

// Partition creates a new partition on the specified device.
//nolint:dupl,gocyclo
func (t *Target) Partition(pt *gpt.GPT, pos int, bd *blockdevice.BlockDevice) (err error) {
if t.Skip {
part := pt.Partitions().FindByName(t.Label)
Expand Down
4 changes: 1 addition & 3 deletions cmd/installer/pkg/install/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// Target represents an installation partition.
//
//nolint:golint,maligned
//nolint:maligned
type Target struct {
*partition.FormatOptions
Device string
Expand Down Expand Up @@ -174,8 +174,6 @@ func (t *Target) Locate(pt *gpt.GPT) (*gpt.Partition, error) {
}

// Format creates a filesystem on the device/partition.
//
//nolint:gocyclo
func (t *Target) Format() error {
if t.Skip {
return nil
Expand Down
6 changes: 1 addition & 5 deletions cmd/talosctl/cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ func GenMarkdownReference(cmd *cobra.Command, w io.Writer, linkHandler func(stri
}
}

if err := doc.GenMarkdownCustom(cmd, w, linkHandler); err != nil {
return err
}

return nil
return doc.GenMarkdownCustom(cmd, w, linkHandler)
}

func init() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/talosctl/cmd/mgmt/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var createCmd = &cobra.Command{
},
}

//nolint:gocyclo
//nolint:gocyclo,cyclop
func create(ctx context.Context) (err error) {
if masters < 1 {
return fmt.Errorf("number of masters can't be less than 1")
Expand Down Expand Up @@ -707,7 +707,7 @@ func getDisks() ([]*provision.Disk, error) {
DiskMountPoint: partitionPath,
}
diskSize += partitionSize
partitionIndex++
partitionIndex++ //nolint:wastedassign
}

disks = append(disks, &provision.Disk{
Expand Down
92 changes: 46 additions & 46 deletions cmd/talosctl/cmd/talos/dashboard/data/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,80 +6,80 @@ package data

import "github.com/talos-systems/talos/pkg/machinery/api/machine"

func cpuInfoDiff(old, new *machine.CPUStat) *machine.CPUStat {
if old == nil || new == nil {
func cpuInfoDiff(old, next *machine.CPUStat) *machine.CPUStat {
if old == nil || next == nil {
return &machine.CPUStat{}
}

// TODO: support wraparound
return &machine.CPUStat{
User: new.User - old.User,
Nice: new.Nice - old.Nice,
System: new.System - old.System,
Idle: new.Idle - old.Idle,
Iowait: new.Iowait - old.Iowait,
Irq: new.Irq - old.Irq,
SoftIrq: new.SoftIrq - old.SoftIrq,
Steal: new.Steal - old.Steal,
Guest: new.Guest - old.Guest,
GuestNice: new.GuestNice - old.GuestNice,
User: next.User - old.User,
Nice: next.Nice - old.Nice,
System: next.System - old.System,
Idle: next.Idle - old.Idle,
Iowait: next.Iowait - old.Iowait,
Irq: next.Irq - old.Irq,
SoftIrq: next.SoftIrq - old.SoftIrq,
Steal: next.Steal - old.Steal,
Guest: next.Guest - old.Guest,
GuestNice: next.GuestNice - old.GuestNice,
}
}

func netDevDiff(old, new *machine.NetDev) *machine.NetDev {
if old == nil || new == nil {
func netDevDiff(old, next *machine.NetDev) *machine.NetDev {
if old == nil || next == nil {
return &machine.NetDev{}
}

// TODO: support wraparound
return &machine.NetDev{
Name: new.Name,
RxBytes: new.RxBytes - old.RxBytes,
RxPackets: new.RxPackets - old.RxPackets,
RxErrors: new.RxErrors - old.RxErrors,
RxDropped: new.RxDropped - old.RxDropped,
RxFifo: new.RxFifo - old.RxFifo,
RxFrame: new.RxFrame - old.RxFrame,
RxCompressed: new.RxCompressed - old.RxCompressed,
RxMulticast: new.RxMulticast - old.RxMulticast,
TxBytes: new.TxBytes - old.TxBytes,
TxPackets: new.TxPackets - old.TxPackets,
TxErrors: new.TxErrors - old.TxErrors,
TxDropped: new.TxDropped - old.TxDropped,
TxFifo: new.TxFifo - old.TxFifo,
TxCollisions: new.TxCollisions - old.TxCollisions,
TxCarrier: new.TxCarrier - old.TxCarrier,
TxCompressed: new.TxCompressed - old.TxCompressed,
Name: next.Name,
RxBytes: next.RxBytes - old.RxBytes,
RxPackets: next.RxPackets - old.RxPackets,
RxErrors: next.RxErrors - old.RxErrors,
RxDropped: next.RxDropped - old.RxDropped,
RxFifo: next.RxFifo - old.RxFifo,
RxFrame: next.RxFrame - old.RxFrame,
RxCompressed: next.RxCompressed - old.RxCompressed,
RxMulticast: next.RxMulticast - old.RxMulticast,
TxBytes: next.TxBytes - old.TxBytes,
TxPackets: next.TxPackets - old.TxPackets,
TxErrors: next.TxErrors - old.TxErrors,
TxDropped: next.TxDropped - old.TxDropped,
TxFifo: next.TxFifo - old.TxFifo,
TxCollisions: next.TxCollisions - old.TxCollisions,
TxCarrier: next.TxCarrier - old.TxCarrier,
TxCompressed: next.TxCompressed - old.TxCompressed,
}
}

func diskStatDiff(old, new *machine.DiskStat) *machine.DiskStat {
if old == nil || new == nil {
func diskStatDiff(old, next *machine.DiskStat) *machine.DiskStat {
if old == nil || next == nil {
return &machine.DiskStat{}
}

// TODO: support wraparound
return &machine.DiskStat{
Name: new.Name,
ReadCompleted: new.ReadCompleted - old.ReadCompleted,
ReadMerged: new.ReadMerged - old.ReadMerged,
ReadSectors: new.ReadSectors - old.ReadSectors,
WriteCompleted: new.WriteCompleted - old.WriteCompleted,
WriteMerged: new.WriteMerged - old.WriteMerged,
WriteSectors: new.WriteSectors - old.WriteSectors,
DiscardCompleted: new.DiscardCompleted - old.DiscardCompleted,
DiscardMerged: new.DiscardMerged - old.DiscardMerged,
DiscardSectors: new.DiscardSectors - old.DiscardSectors,
Name: next.Name,
ReadCompleted: next.ReadCompleted - old.ReadCompleted,
ReadMerged: next.ReadMerged - old.ReadMerged,
ReadSectors: next.ReadSectors - old.ReadSectors,
WriteCompleted: next.WriteCompleted - old.WriteCompleted,
WriteMerged: next.WriteMerged - old.WriteMerged,
WriteSectors: next.WriteSectors - old.WriteSectors,
DiscardCompleted: next.DiscardCompleted - old.DiscardCompleted,
DiscardMerged: next.DiscardMerged - old.DiscardMerged,
DiscardSectors: next.DiscardSectors - old.DiscardSectors,
}
}

func procDiff(old, new *machine.ProcessInfo) *machine.ProcessInfo {
if old == nil || new == nil {
func procDiff(old, next *machine.ProcessInfo) *machine.ProcessInfo {
if old == nil || next == nil {
return &machine.ProcessInfo{}
}

// TODO: support wraparound
return &machine.ProcessInfo{
CpuTime: new.CpuTime - old.CpuTime,
CpuTime: next.CpuTime - old.CpuTime,
}
}
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/talos/dashboard/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (source *APISource) run(dataCh chan<- *data.Data) {
}
}

//nolint:gocyclo
//nolint:gocyclo,cyclop
func (source *APISource) gather() *data.Data {
result := &data.Data{
Timestamp: time.Now(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/talos/dashboard/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (u *UI) Main(ctx context.Context, dataCh <-chan *data.Data) error {
case "q", "<C-c>":
return nil
case "<Resize>":
payload := e.Payload.(ui.Resize) //nolint:errcheck
payload := e.Payload.(ui.Resize) //nolint:errcheck,forcetypeassert

u.Resize(payload.Width, payload.Height)
ui.Clear()
Expand Down
8 changes: 4 additions & 4 deletions cmd/talosctl/cmd/talos/output/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func (table *Table) WriteHeader(definition resource.Resource, withEvents bool) e
fields = append([]string{"*"}, fields...)
}

resourceDefinitionSpec := definition.(*resource.Any).Value().(map[string]interface{}) //nolint:errcheck
resourceDefinitionSpec := definition.(*resource.Any).Value().(map[string]interface{}) //nolint:errcheck,forcetypeassert

table.displayType = resourceDefinitionSpec["displayType"].(string) //nolint:errcheck
table.displayType = resourceDefinitionSpec["displayType"].(string) //nolint:errcheck,forcetypeassert

for _, col := range resourceDefinitionSpec["printColumns"].([]interface{}) {
column := col.(map[string]interface{}) //nolint:errcheck
name := column["name"].(string) //nolint:errcheck
column := col.(map[string]interface{}) //nolint:errcheck,forcetypeassert
name := column["name"].(string) //nolint:errcheck,forcetypeassert

fields = append(fields, strings.ToUpper(name))

Expand Down
3 changes: 1 addition & 2 deletions cmd/talosctl/cmd/talos/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ var cpu = func(p1, p2 *machineapi.ProcessInfo) bool {
return p1.CpuTime > p2.CpuTime
}

//nolint:gocyclo
func processesOutput(ctx context.Context, c *client.Client) (output string, err error) {
var remotePeer peer.Peer

Expand All @@ -179,7 +178,7 @@ func processesOutput(ctx context.Context, c *client.Client) (output string, err
// up display
// TODO: Update server side code to not throw an error when process
// no longer exists ( /proc/1234/comm no such file or directory )
return output, nil
return output, nil //nolint:nilerr
}

defaultNode := client.AddrFromPeer(&remotePeer)
Expand Down
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/talos/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func serviceInfo(ctx context.Context, c *client.Client, id string) error {
//nolint:errcheck
ts, _ := ptypes.Timestamp(event.Ts)
fmt.Fprintf(w, "%s\t[%s]: %s (%s ago)\n", label, event.State, event.Msg, time.Since(ts).Round(time.Second))
label = ""
label = "" //nolint:wastedassign
}
}

Expand Down
6 changes: 1 addition & 5 deletions internal/app/init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ func run() (err error) {
// Switch into the new rootfs.
log.Println("entering the rootfs")

if err = switchroot.Switch(constants.NewRoot, pseudo); err != nil {
return err
}

return nil
return switchroot.Switch(constants.NewRoot, pseudo)
}

func recovery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (s *Server) NetworkDeviceStats(ctx context.Context, in *empty.Empty) (*mach

for _, line := range info {
resp.Devices[i] = translateNetDevLine(line)
i++
i++ //nolint:wastedassign
}

reply := &machine.NetworkDeviceStatsResponse{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *ResourceServer) resolveResourceKind(ctx context.Context, kind *resource
continue
}

spec := resourceDefinition.Spec().(meta.ResourceDefinitionSpec) //nolint:errcheck
spec := resourceDefinition.Spec().(meta.ResourceDefinitionSpec) //nolint:errcheck,forcetypeassert

for _, alias := range spec.Aliases {
if strings.EqualFold(alias, kind.Type) {
Expand Down
Loading

0 comments on commit 22f3753

Please sign in to comment.