Skip to content

Commit

Permalink
chore: fix //nolint directives
Browse files Browse the repository at this point in the history
That's the recommended syntax:
https://golangci-lint.run/usage/false-positives/

Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
  • Loading branch information
AlekSi authored and talos-bot committed Mar 5, 2021
1 parent f3a32ff commit df52c13
Show file tree
Hide file tree
Showing 254 changed files with 680 additions and 680 deletions.
4 changes: 2 additions & 2 deletions cmd/installer/cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
rootCmd.AddCommand(imageCmd)
}

//nolint: gocyclo
//nolint:gocyclo
func runImageCmd() (err error) {
p, err := platform.NewPlatform(options.Platform)
if err != nil {
Expand Down Expand Up @@ -110,7 +110,7 @@ func runImageCmd() (err error) {
return nil
}

//nolint: gocyclo
//nolint:gocyclo
func finalize(platform runtime.Platform, img string) (err error) {
dir := filepath.Dir(img)

Expand Down
10 changes: 5 additions & 5 deletions cmd/installer/cmd/iso.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func init() {
rootCmd.AddCommand(isoCmd)
}

// nolint: gocyclo
//nolint:gocyclo
func runISOCmd() error {
if err := os.MkdirAll(outputArg, 0o777); err != nil {
return err
Expand All @@ -73,14 +73,14 @@ func runISOCmd() error {
if err != nil {
return err
}
// nolint: errcheck
//nolint:errcheck
defer from.Close()

to, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, 0o666)
if err != nil {
return err
}
// nolint: errcheck
//nolint:errcheck
defer to.Close()

_, err = io.Copy(to, from)
Expand Down Expand Up @@ -113,14 +113,14 @@ func runISOCmd() error {
if err != nil {
return err
}
// nolint: errcheck
//nolint:errcheck
defer from.Close()

to, err := os.OpenFile(filepath.Join(outputArg, filepath.Base(out)), os.O_RDWR|os.O_CREATE, 0o666)
if err != nil {
return err
}
// nolint: errcheck
//nolint:errcheck
defer to.Close()

_, err = io.Copy(to, from)
Expand Down
10 changes: 5 additions & 5 deletions cmd/installer/pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type Installer struct {

// NewInstaller initializes and returns an Installer.
//
// nolint: gocyclo
//nolint:gocyclo
func NewInstaller(cmdline *procfs.Cmdline, seq runtime.Sequence, opts *Options) (i *Installer, err error) {
i = &Installer{
cmdline: cmdline,
Expand Down Expand Up @@ -120,7 +120,7 @@ func (i *Installer) probeBootPartition() error {
return err
}

defer dev.Close() // nolint:errcheck
defer dev.Close() //nolint:errcheck

if part, err := dev.GetPartition(constants.BootPartitionLabel); err != nil {
i.bootPartitionFound = false
Expand All @@ -146,7 +146,7 @@ func (i *Installer) probeBootPartition() error {
if err := mount.Mount(mountpoints); err != nil {
log.Printf("warning: failed to mount boot partition %q: %s", partPath, err)
} else {
defer mount.Unmount(mountpoints) //nolint: errcheck
defer mount.Unmount(mountpoints) //nolint:errcheck
}
}
}
Expand All @@ -162,7 +162,7 @@ func (i *Installer) probeBootPartition() error {
// Install fetches the necessary data locations and copies or extracts
// to the target locations.
//
// nolint: gocyclo
//nolint:gocyclo
func (i *Installer) Install(seq runtime.Sequence) (err error) {
if i.options.Board != constants.BoardNone {
var b runtime.Board
Expand Down Expand Up @@ -308,7 +308,7 @@ func (i *Installer) Install(seq runtime.Sequence) (err error) {
return err
}

//nolint: errcheck
//nolint:errcheck
defer meta.Close()

if ok := meta.LegacyADV.SetTag(adv.Upgrade, i.Current); !ok {
Expand Down
18 changes: 9 additions & 9 deletions cmd/installer/pkg/install/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Device struct {

// NewManifest initializes and returns a Manifest.
//
//nolint: gocyclo
//nolint:gocyclo
func NewManifest(label string, sequence runtime.Sequence, bootPartitionFound bool, opts *Options) (manifest *Manifest, err error) {
if label == "" {
return nil, fmt.Errorf("a label is required, got \"\"")
Expand Down Expand Up @@ -189,7 +189,7 @@ func (m *Manifest) checkMounts(device Device) error {
return nil
}

defer f.Close() //nolint: errcheck
defer f.Close() //nolint:errcheck

scanner := bufio.NewScanner(f)
for scanner.Scan() {
Expand All @@ -213,7 +213,7 @@ func (m *Manifest) checkMounts(device Device) error {
return nil
}

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

// nolint: errcheck
//nolint:errcheck
defer bd.Close()

var pt *gpt.GPT
Expand Down Expand Up @@ -273,7 +273,7 @@ func (m *Manifest) executeOnDevice(device Device, targets []*Target) (err error)
return err
}

defer bd.Close() //nolint: errcheck
defer bd.Close() //nolint:errcheck

created = true
}
Expand Down Expand Up @@ -372,7 +372,7 @@ func (m *Manifest) executeOnDevice(device Device, targets []*Target) (err error)
return nil
}

//nolint: gocyclo
//nolint:gocyclo
func (m *Manifest) preserveContents(device Device, targets []*Target) (err error) {
anyPreserveContents := false

Expand All @@ -398,7 +398,7 @@ func (m *Manifest) preserveContents(device Device, targets []*Target) (err error
return nil
}

// nolint: errcheck
//nolint:errcheck
defer bd.Close()

pt, err := bd.PartitionTable()
Expand Down Expand Up @@ -492,7 +492,7 @@ func (m *Manifest) zeroDevice(device Device) (err error) {
return err
}

defer bd.Close() //nolint: errcheck
defer bd.Close() //nolint:errcheck

var method string

Expand All @@ -506,7 +506,7 @@ func (m *Manifest) zeroDevice(device Device) (err error) {
}

// Partition creates a new partition on the specified device.
// nolint: dupl, gocyclo
//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
8 changes: 4 additions & 4 deletions cmd/installer/pkg/install/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (suite *manifestSuite) TearDownTest() {
}

func (suite *manifestSuite) skipUnderBuildkit() {
hostname, _ := os.Hostname() //nolint: errcheck
hostname, _ := os.Hostname() //nolint:errcheck

if hostname == "buildkitsandbox" {
suite.T().Skip("test not supported under buildkit as partition devices are not propagated from /dev")
Expand All @@ -103,7 +103,7 @@ func (suite *manifestSuite) verifyBlockdevice(manifest *install.Manifest, curren
bd, err := blockdevice.Open(suite.loopbackDevice.Name())
suite.Require().NoError(err)

defer bd.Close() //nolint: errcheck
defer bd.Close() //nolint:errcheck

table, err := bd.PartitionTable()
suite.Require().NoError(err)
Expand Down Expand Up @@ -360,7 +360,7 @@ func (suite *manifestSuite) TestTargetInstall() {
dir, err := ioutil.TempDir("", "talostest")
suite.Require().NoError(err)

// nolint: errcheck
//nolint:errcheck
defer os.RemoveAll(dir)

// Create a tempfile for local copy
Expand Down Expand Up @@ -394,7 +394,7 @@ func (suite *manifestSuite) createTalosLegacyLayout() {
bd, err := blockdevice.Open(suite.loopbackDevice.Name())
suite.Require().NoError(err)

defer bd.Close() //nolint: errcheck
defer bd.Close() //nolint:errcheck

// create Talos 0.6 partitions
table, err := gpt.New(bd.Device())
Expand Down
14 changes: 7 additions & 7 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:golint,maligned
type Target struct {
*partition.FormatOptions
Device string
Expand Down Expand Up @@ -175,7 +175,7 @@ func (t *Target) Locate(pt *gpt.GPT) (*gpt.Partition, error) {

// Format creates a filesystem on the device/partition.
//
//nolint: gocyclo
//nolint:gocyclo
func (t *Target) Format() error {
if t.Skip {
return nil
Expand All @@ -198,7 +198,7 @@ func (t *Target) Save() (err error) {
if sourceFile, err = os.Open(asset.Source); err != nil {
return err
}
// nolint: errcheck
//nolint:errcheck
defer sourceFile.Close()

if err = os.MkdirAll(filepath.Dir(asset.Destination), os.ModeDir); err != nil {
Expand All @@ -209,7 +209,7 @@ func (t *Target) Save() (err error) {
return err
}

// nolint: errcheck
//nolint:errcheck
defer destFile.Close()

log.Printf("copying %s to %s\n", sourceFile.Name(), destFile.Name())
Expand Down Expand Up @@ -294,12 +294,12 @@ func (t *Target) saveRawContents(partPath string) error {
return fmt.Errorf("error opening source partition: %q", err)
}

defer src.Close() //nolint: errcheck
defer src.Close() //nolint:errcheck

t.Contents = bytes.NewBuffer(nil)

zw := gzip.NewWriter(t.Contents)
defer zw.Close() //nolint: errcheck
defer zw.Close() //nolint:errcheck

_, err = io.Copy(zw, src)
if err != nil {
Expand Down Expand Up @@ -348,7 +348,7 @@ func (t *Target) restoreRawContents() error {
return fmt.Errorf("error opening source partition: %q", err)
}

defer dst.Close() //nolint: errcheck
defer dst.Close() //nolint:errcheck

zr, err := gzip.NewReader(t.Contents)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/installer/pkg/install/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func VerifyDiskAvailability(devpath, label string) (err error) {
return nil
}

// nolint: errcheck
//nolint:errcheck
defer dev.Close()

part, err := dev.GetPartition(label)
Expand Down
6 changes: 3 additions & 3 deletions cmd/installer/pkg/ova/ova.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SHA256({{ .OVF }})= {{ .OVFSHA }}
`

// OVF format reference: https://www.dmtf.org/standards/ovf.
//nolint: lll
//nolint:lll
const ovfTpl = `<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by VMware ovftool 4.3.0 (build-7948156), UTC time: 2019-10-31T01:41:10.540841Z-->
<!-- Edited by Talos -->
Expand Down Expand Up @@ -131,7 +131,7 @@ const ovfTpl = `<?xml version="1.0" encoding="UTF-8"?>
`

// CreateOVAFromRAW creates an OVA from a RAW disk.
//nolint: gocyclo
//nolint:gocyclo
func CreateOVAFromRAW(name, src, out string) (err error) {
dir, err := ioutil.TempDir("/tmp", "talos")
if err != nil {
Expand Down Expand Up @@ -176,7 +176,7 @@ func CreateOVAFromRAW(name, src, out string) (err error) {
return err
}

// nolint: errcheck
//nolint:errcheck
defer os.RemoveAll(dir)

if err = ioutil.WriteFile(filepath.Join(dir, name+".mf"), []byte(mf), 0o666); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var docsCmd = &cobra.Command{
if err != nil {
return err
}
// nolint: errcheck
//nolint:errcheck
defer f.Close()

if _, err := io.WriteString(f, frontmatter("CLI", cliDescription)); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/talosctl/cmd/mgmt/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var createCmd = &cobra.Command{
},
}

//nolint: gocyclo
//nolint:gocyclo
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 @@ -209,7 +209,7 @@ func create(ctx context.Context) (err error) {
return err
}

defer provisioner.Close() //nolint: errcheck
defer provisioner.Close() //nolint:errcheck

// Craft cluster and node requests
request := provision.ClusterRequest{
Expand Down Expand Up @@ -522,7 +522,7 @@ func create(ctx context.Context) (err error) {
}

clusterAccess := access.NewAdapter(cluster, provisionOptions...)
defer clusterAccess.Close() //nolint: errcheck
defer clusterAccess.Close() //nolint:errcheck

if applyConfigEnabled {
err = clusterAccess.ApplyConfig(ctx, request.Nodes, os.Stdout)
Expand Down
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/mgmt/cluster/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func destroy(ctx context.Context) error {
return err
}

defer provisioner.Close() //nolint: errcheck
defer provisioner.Close() //nolint:errcheck

cluster, err := provisioner.Reflect(ctx, clusterName, stateDir)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/talosctl/cmd/mgmt/cluster/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func show(ctx context.Context) error {
return err
}

defer provisioner.Close() //nolint: errcheck
defer provisioner.Close() //nolint:errcheck

cluster, err := provisioner.Reflect(ctx, clusterName, stateDir)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/talosctl/cmd/mgmt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func fixControlPlaneEndpoint(u *url.URL) *url.URL {
return u
}

//nolint: gocyclo
//nolint:gocyclo
func genV1Alpha1Config(args []string) error {
// If output dir isn't specified, set to the current working dir
var err error
Expand All @@ -118,7 +118,7 @@ func genV1Alpha1Config(args []string) error {
return fmt.Errorf("failed to create output dir: %w", err)
}

var genOptions []generate.GenOption //nolint: prealloc
var genOptions []generate.GenOption //nolint:prealloc

for _, registryMirror := range registryMirrors {
components := strings.SplitN(registryMirror, "=", 2)
Expand Down

0 comments on commit df52c13

Please sign in to comment.