8000 [CI] Migrate to v2 of golangci by rokatyy · Pull Request #3679 · nuclio/nuclio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[CI] Migrate to v2 of golangci #3679

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

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
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
133 changes: 64 additions & 69 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
linters:
disable-all: true
enable:
- goconst
- gofmt
- revive
- gosimple
- ineffassign
- misspell
- staticcheck
- unconvert
- errcheck
- govet
- typecheck
- gocritic
- unused
- gci
version: "2"

# timeout for analysis
timeout: 5m
run:

# timeout for analysis
timeout: 5m
Comment on lines -35 to -36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the timeout removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem to be issue with auto migration, will revert it

build-tags:
- test_unit
- test_integration
Expand All @@ -43,53 +26,65 @@ run:
- test_iguazio
- test_broken
- test_benchmark

linters-settings:
revive:
linters:
default: none
enable:
- errcheck
- goconst
- gocritic
- govet
- ineffassign
- misspell
- revive
- staticcheck
- unconvert
- unused
settings:
gocritic:
disabled-checks:
- commentFormatting
revive:
rules:
- name: errorf
disabled: true
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:

# avoid errorf: should replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) messages
- name: errorf
disabled: true

gocritic:
disabled-checks:
# we don't want to enforce space before the comment text
- commentFormatting

gci:
sections:
- standard
- prefix(github.com/nuclio/nuclio/)
- default
- blank
- dot

custom-order: true

issues:

# List of regexps of issue texts to exclude
exclude:
- "comment on"
- "error should be the last"

exclude-dirs:
- docs
- vendor

exclude-rules:

# Auto generated files for kubernetes
- path: pkg/platform/kube/client
linters:
- errcheck

# list of excluded linters applied on test files
- path: _test\.go
linters:
- goconst

# false positive
- path: pkg/common/k8s.go
text: "deprecatedComment: the proper format is `Deprecated: <text>`"
- linters:
- errcheck
path: pkg/platform/kube/client
- linters:
- goconst
path: _test\.go
- path: pkg/common/k8s.go
text: 'deprecatedComment: the proper format is `Deprecated: <text>`'
- path: (.+)\.go$
text: comment on
- path: (.+)\.go$
text: error should be the last
paths:
- docs
- hack
formatters:
enable:
- gci
- gofmt
settings:
gci:
sections:
- standard
- prefix(github.com/nuclio/nuclio/)
- default
- blank
- dot
custom-order: true
exclusions:
generated: lax
paths:
- docs
- hack
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -695,17 +695,17 @@ ensure-test-files-annotated:
@echo "All go test files have //go:build test_X annotation"
@exit $(.SHELLSTATUS)

GOLANGCI_LINT_VERSION := v1.64.6
GOLANGCI_LINT_VERSION := 2.2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed some issues with this v.
I suggest also removing it in the the awk command (Line 705):

installed_version=$$($(GOLANGCI_LINT_BIN) version | awk '/version/ {print $$4}' | sed 's/^v//'); \

GOLANGCI_LINT_BIN := $(GOPATH)/bin/golangci-lint
GOLANGCI_LINT_INSTALL_COMMAND := GOBIN=$(GOPATH)/bin go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
GOLANGCI_LINT_INSTALL_COMMAND := GOBIN=$(GOPATH)/bin go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION)

.PHONY: ensure-golangci-linter
ensure-golangci-linter:
@if ! command -v $(GOLANGCI_LINT_BIN) >/dev/null 2>&1; then \
echo "golangci-lint not found. Installing..."; \
$(GOLANGCI_LINT_INSTALL_COMMAND); \
else \
installed_version=$$($(GOLANGCI_LINT_BIN) version | awk '/version/ {print $$4}'); \
installed_version=$$($(GOLANGCI_LINT_BIN) version | awk '/version/ {gsub(/^v/, "", $$4); print $$4}'); \
if [ "$$installed_version" != "$(GOLANGCI_LINT_VERSION)" ]; then \
echo "golangci-lint version mismatch ($$installed_version != $(GOLANGCI_LINT_VERSION)). Reinstalling..."; \
$(GOLANGCI_LINT_INSTALL_COMMAND); \
Expand Down
5 changes: 3 additions & 2 deletions hack/examples/golang/image/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ func Handler(context *nuclio.Context, event nuclio.Event) (interface{}, error) {
var img image.Image
var err error
if strings.HasPrefix(event.GetContentType(), "text/plain") {
var response *http.Response
// if the body is text assume its a URL and read the image from the URL (in the text)
response, err := http.Get(string(event.GetBody()))
response, err = http.Get(string(event.GetBody()))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -92,6 +93,6 @@ func Handler(context *nuclio.Context, event nuclio.Event) (interface{}, error) {
StatusCode: 200,
ContentType: respType,
Body: buf.Bytes(),
}, nil
}, err

}
8 changes: 4 additions & 4 deletions hack/scripts/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,17 @@ func (r *Release) saveReleaseInfo() error {
defer file.Close()

// Write the version information with specific labels to the file
_, err = file.WriteString(fmt.Sprintf("CURRENT_VERSION: %s\n", r.currentVersion.String()))
_, err = fmt.Fprintf(file, "CURRENT_VERSION: %s\n", r.currentVersion.String())
if err != nil {
return errors.Wrap(err, "Failed to write current version")
}

_, err = file.WriteString(fmt.Sprintf("TARGET_VERSION: %s\n", r.targetVersion.String()))
_, err = fmt.Fprintf(file, "TARGET_VERSION: %s\n", r.targetVersion.String())
if err != nil {
return errors.Wrap(err, "Failed to write target version")
}

_, err = file.WriteString(fmt.Sprintf("HELM_CHARTS_TARGET_VERSION: %s\n", r.helmChartsTargetVersion.String()))
_, err = fmt.Fprintf(file, "HELM_CHARTS_TARGET_VERSION: %s\n", r.helmChartsTargetVersion.String())
if err != nil {
return errors.Wrap(err, "Failed to write helm charts target version")
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (r *Release) bumpHelmChartVersion() error {
}

func (r *Release) populateBumpedVersions() error {
if !(r.bumpPatch || r.bumpMinor || r.bumpMajor) {
if !r.bumpPatch && !r.bumpMinor && !r.bumpMajor {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/iguazio/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (a *Auth) Authenticate(request *http.Request, options *authpkg.Options) (au
}

// not within range of 200
if !(response.StatusCode >= http.StatusOK && response.StatusCode < 300) {
if response.StatusCode < http.StatusOK || response.StatusCode >= 300 {
a.logger.WarnWithCtx(ctx,
"Unexpected authentication status code",
"authorizationHeaderLength", len(authHeaders["authorization"]),
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmdrunner/shellrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (sr *ShellRunner) runAndCaptureOutput(cmd *exec.Cmd,
return err
}

return fmt.Errorf("Invalid output capture mode: %d", runOptions.CaptureOutputMode)
return errors.Errorf("Invalid output capture mode: %d", runOptions.CaptureOutputMode)
}

func Redact(redactions []string, runOutput string) string {
Expand Down
5 changes: 3 additions & 2 deletions pkg/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ func FixEscapeChars(s string) string {

func GetEnvOrDefaultString(key string, defaultValue string) string {
value := os.Getenv(key)
if value == "" {
switch value {
case "":
return defaultValue
} else if value == "nil" || value == "none" {
case "nil", "none":
return ""
}
return value
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func DownloadFile(url string, out *os.File, headers http.Header) error {
}

if response.StatusCode != http.StatusOK {
return fmt.Errorf(
return errors.Errorf(
"Failed to download file. Received an unexpected status code: %d",
response.StatusCode)
}
Expand All @@ -72,7 +72,7 @@ func DownloadFile(url string, out *os.File, headers http.Header) error {
}

if response.ContentLength != -1 && written != response.ContentLength {
return fmt.Errorf(
return errors.Errorf(
"Downloaded file length (%d) is different than URL content length (%d)",
written,
response.ContentLength)
Expand Down
8 changes: 4 additions & 4 deletions pkg/containerimagebuilderpusher/kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func (k *Kaniko) waitForJobCompletion(ctx context.Context,
"Failed to get job logs", "err", err.Error())
return errors.Wrap(err, "Failed to retrieve kaniko job logs")
}
return fmt.Errorf("Job failed. Job logs:\n%s", jobLogs)
return errors.Errorf("Job failed. Job logs:\n%s", jobLogs)
}

k.logger.DebugWithCtx(ctx,
Expand Down Expand Up @@ -606,7 +606,7 @@ func (k *Kaniko) waitForJobCompletion(ctx context.Context,
if err != nil {
return errors.Wrap(err, "Job failed and was unable to retrieve job logs")
}
return fmt.Errorf("Job has timed out. Job logs:\n%s", jobLogs)
return errors.Errorf("Job has timed out. Job logs:\n%s", jobLogs)
}

func (k *Kaniko) resolveFailFast(ctx context.Context,
Expand All @@ -632,10 +632,10 @@ func (k *Kaniko) resolveFailFast(ctx context.Context,
"failFastTimeoutDuration", readinessTimout.String())

if lastError != "" {
return fmt.Errorf("Job was not completed in time, job name: %s. Error: %s ", jobName,
return errors.Errorf("Job was not completed in time, job name: %s. Error: %s ", jobName,
lastError)
} else {
return fmt.Errorf("Job was not completed in time, job name: %s", jobName)
return errors.Errorf("Job was not completed in time, job name: %s", jobName)
}
default:
jobPod, err := k.getJobPod(ctx, jobName, namespace, true)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/resource/apigateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type apiGatewayInfo struct {
}

func (agr *apiGatewayResource) ExtendMiddlewares() error {
agr.resource.addAuthMiddleware(nil)
agr.addAuthMiddleware(nil)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/dashboard/resource/externalipaddresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type externalIPAddressesResource struct {
}

func (eiar *externalIPAddressesResource) ExtendMiddlewares() error {
eiar.resource.addAuthMiddleware(nil)
eiar.addAuthMiddleware(nil)
return nil
}

Expand Down
Loading
0