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

Fix linting issues (v7) #2939

Merged
merged 1 commit into from
May 24, 2024
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
56 changes: 56 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: golangci-lint

on:
push:
tags:
- "v9.*"
- "v8.*"
- "v7.*"
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- main
- v9
- v8
- v7
paths-ignore:
- "doc/**"
- ".gitpod.yml"
- "README.md"

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.58
args: -v --exclude-dirs cf --exclude-dirs fixtures --exclude-dirs plugin --exclude-dirs command/plugin
format:
name: Run go fmt
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Set Up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- name: Run go fmt
run: go fmt && git diff --exit-code
17 changes: 0 additions & 17 deletions .github/workflows/tests-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,6 @@ defaults:
shell: bash

jobs:
lint:
name: Lint code
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Set Up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true

- name: Run go fmt
run: go fmt && git diff --exit-code

units:
name: Units
strategy:
Expand Down
14 changes: 6 additions & 8 deletions .golangci.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"run": {
"concurrency": 4,
"timeout": "20m",
"skip-files": [
"integration/helpers/fake_server.go"
]
"timeout": "20m"
},
"linters": {
"disable-all": true,
Expand All @@ -14,15 +11,16 @@
"errcheck",
"staticcheck",
"unused",
"structcheck",
"varcheck",
"ineffassign",
"deadcode"
"ineffassign"
]
},
"linters-settings": {},
"issues": {
"max-same-issue": 0,
"exclude-files": [
"integration/helpers/fake_server.go",
"command/plugin/*.go$"
],
"exclude": [
"Error return value of `client.GetApplicationTasks` is not checked",
"Error return value of `logger.output.Stop` is not checked",
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ integration-tests-full-ci: install-test-deps integration-cleanup
integration/shared/isolated integration/v7/isolated integration/shared/plugin integration/shared/experimental integration/v7/experimental integration/v7/push
$(ginkgo_int) -flake-attempts $(FLAKE_ATTEMPTS) integration/shared/global integration/v7/global

lint: ## Runs all linters and formatters
lint: format ## Runs all linters and formatters
@echo "Running linters..."
go list -f "{{.Dir}}" ./... \
| grep -v -e "/cf/" -e "/fixtures/" -e "/assets/" -e "/plugin/" -e "/command/plugin" -e "fakes" \
| xargs golangci-lint run
golangci-lint run --exclude-dirs cf --exclude-dirs fixtures --exclude-dirs plugin --exclude-dirs command/plugin
@echo "No lint errors!"

# TODO: version specific tagging for all these builds
Expand Down
5 changes: 2 additions & 3 deletions actor/pluginaction/checksum_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pluginaction_test

import (
"io/ioutil"
"os"

. "code.cloudfoundry.org/cli/actor/pluginaction"
Expand All @@ -25,11 +24,11 @@ var _ = Describe("Checksums", func() {
var file *os.File
BeforeEach(func() {
var err error
file, err = ioutil.TempFile("", "")
file, err = os.CreateTemp("", "")
Expect(err).NotTo(HaveOccurred())
defer file.Close()

err = ioutil.WriteFile(file.Name(), []byte("foo"), 0600)
err = os.WriteFile(file.Name(), []byte("foo"), 0600)
Expect(err).NotTo(HaveOccurred())
})

Expand Down
3 changes: 1 addition & 2 deletions actor/pluginaction/install.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pluginaction

import (
"io/ioutil"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -189,7 +188,7 @@ func (actor Actor) InstallPluginFromPath(path string, plugin configv3.Plugin) er
}

func makeTempFile(tempDir string) (*os.File, error) {
tempFile, err := ioutil.TempFile(tempDir, "")
tempFile, err := os.CreateTemp(tempDir, "")
if err != nil {
return nil, err
}
Expand Down
17 changes: 8 additions & 9 deletions actor/pluginaction/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pluginaction_test

import (
"errors"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -32,7 +31,7 @@ var _ = Describe("install actions", func() {
actor = NewActor(fakeConfig, fakeClient)

var err error
tempPluginDir, err = ioutil.TempDir("", "")
tempPluginDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
})

Expand All @@ -46,7 +45,7 @@ var _ = Describe("install actions", func() {
var pluginPath string

BeforeEach(func() {
tempFile, err := ioutil.TempFile("", "")
tempFile, err := os.CreateTemp("", "")
Expect(err).ToNot(HaveOccurred())

_, err = tempFile.WriteString("cthulhu")
Expand All @@ -66,7 +65,7 @@ var _ = Describe("install actions", func() {
copyPath, err := actor.CreateExecutableCopy(pluginPath, tempPluginDir)
Expect(err).ToNot(HaveOccurred())

contents, err := ioutil.ReadFile(copyPath)
contents, err := os.ReadFile(copyPath)
Expect(err).ToNot(HaveOccurred())
Expect(contents).To(BeEquivalentTo("cthulhu"))
})
Expand Down Expand Up @@ -101,14 +100,14 @@ var _ = Describe("install actions", func() {
BeforeEach(func() {
data = []byte("some test data")
fakeClient.DownloadPluginStub = func(_ string, path string, _ plugin.ProxyReader) error {
err := ioutil.WriteFile(path, data, 0700)
err := os.WriteFile(path, data, 0700)
Expect(err).ToNot(HaveOccurred())
return nil
}
})
It("returns the path to the file and the size", func() {
Expect(downloadErr).ToNot(HaveOccurred())
fileData, err := ioutil.ReadFile(path)
fileData, err := os.ReadFile(path)
Expect(err).ToNot(HaveOccurred())
Expect(fileData).To(Equal(data))

Expand Down Expand Up @@ -139,7 +138,7 @@ var _ = Describe("install actions", func() {

When("the file exists", func() {
BeforeEach(func() {
pluginFile, err := ioutil.TempFile("", "")
pluginFile, err := os.CreateTemp("", "")
Expect(err).NotTo(HaveOccurred())
err = pluginFile.Close()
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -620,14 +619,14 @@ var _ = Describe("install actions", func() {
},
}

pluginFile, err := ioutil.TempFile("", "")
pluginFile, err := os.CreateTemp("", "")
Expect(err).NotTo(HaveOccurred())
err = pluginFile.Close()
Expect(err).NotTo(HaveOccurred())

pluginPath = pluginFile.Name()

tempDir, err = ioutil.TempDir("", "")
tempDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

pluginHomeDir = filepath.Join(tempDir, ".cf", "plugin")
Expand Down
9 changes: 4 additions & 5 deletions actor/pluginaction/install_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package pluginaction_test

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -26,7 +25,7 @@ var _ = Describe("install actions", func() {
BeforeEach(func() {
fakeConfig = new(pluginactionfakes.FakeConfig)
var err error
tempPluginDir, err = ioutil.TempDir("", "")
tempPluginDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
actor = NewActor(fakeConfig, nil)
})
Expand All @@ -41,7 +40,7 @@ var _ = Describe("install actions", func() {
var pluginPath string

BeforeEach(func() {
tempFile, err := ioutil.TempFile("", "")
tempFile, err := os.CreateTemp("", "")
Expect(err).ToNot(HaveOccurred())

_, err = tempFile.WriteString("cthulhu")
Expand Down Expand Up @@ -86,14 +85,14 @@ var _ = Describe("install actions", func() {
},
}

pluginFile, err := ioutil.TempFile("", "")
pluginFile, err := os.CreateTemp("", "")
Expect(err).NotTo(HaveOccurred())
err = pluginFile.Close()
Expect(err).NotTo(HaveOccurred())

pluginPath = pluginFile.Name()

tempDir, err = ioutil.TempDir("", "")
tempDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

pluginHomeDir = filepath.Join(tempDir, ".cf", "plugin")
Expand Down
5 changes: 2 additions & 3 deletions actor/pluginaction/install_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package pluginaction_test

import (
"io/ioutil"
"os"

. "code.cloudfoundry.org/cli/actor/pluginaction"
Expand All @@ -23,7 +22,7 @@ var _ = Describe("install actions", func() {
BeforeEach(func() {
fakeConfig = new(pluginactionfakes.FakeConfig)
var err error
tempPluginDir, err = ioutil.TempDir("", "")
tempPluginDir, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())
actor = NewActor(fakeConfig, nil)
})
Expand All @@ -38,7 +37,7 @@ var _ = Describe("install actions", func() {
var pluginPath string

BeforeEach(func() {
tempFile, err := ioutil.TempFile("", "")
tempFile, err := os.CreateTemp("", "")
Expect(err).ToNot(HaveOccurred())

_, err = tempFile.WriteString("cthulhu")
Expand Down
7 changes: 3 additions & 4 deletions actor/pluginaction/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package pluginaction_test

import (
"errors"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -35,11 +34,11 @@ var _ = Describe("Plugin actor", func() {

BeforeEach(func() {
var err error
pluginHome, err = ioutil.TempDir("", "")
pluginHome, err = os.MkdirTemp("", "")
Expect(err).ToNot(HaveOccurred())

binaryPath = filepath.Join(pluginHome, "banana-faceman")
err = ioutil.WriteFile(binaryPath, nil, 0600)
err = os.WriteFile(binaryPath, nil, 0600)
Expect(err).ToNot(HaveOccurred())

fakePluginUninstaller = new(pluginactionfakes.FakePluginUninstaller)
Expand Down Expand Up @@ -188,7 +187,7 @@ var _ = Describe("Plugin actor", func() {
Expect(err).ToNot(HaveOccurred())
err = os.Mkdir(binaryPath, 0700)
Expect(err).ToNot(HaveOccurred())
err = ioutil.WriteFile(filepath.Join(binaryPath, "foooooo"), nil, 0500)
err = os.WriteFile(filepath.Join(binaryPath, "foooooo"), nil, 0500)
Expect(err).ToNot(HaveOccurred())
})

Expand Down
5 changes: 2 additions & 3 deletions actor/pushaction/application_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pushaction_test
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -97,7 +96,7 @@ var _ = Describe("Application Config", func() {
noStart = false

var err error
filesPath, err = ioutil.TempDir("", "convert-to-application-configs")
filesPath, err = os.MkdirTemp("", "convert-to-application-configs")
Expect(err).ToNot(HaveOccurred())

// The temp directory created on OSX contains a symlink and needs to be evaluated.
Expand Down Expand Up @@ -1165,7 +1164,7 @@ var _ = Describe("Application Config", func() {
var archive string

BeforeEach(func() {
f, err := ioutil.TempFile("", "convert-to-application-configs-archive")
f, err := os.CreateTemp("", "convert-to-application-configs-archive")
Expect(err).ToNot(HaveOccurred())
archive = f.Name()
Expect(f.Close()).ToNot(HaveOccurred())
Expand Down
Loading
Loading