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

Run gofmt via golangci-lint #425

Merged
merged 1 commit into from
Dec 7, 2019

Conversation

ferhatelmas
Copy link
Contributor

Drop custom script since golangci-lint can already do it.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 4, 2019
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 4, 2019
@codecov-io
Copy link

codecov-io commented Dec 4, 2019

Codecov Report

Merging #425 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #425   +/-   ##
=======================================
  Coverage   56.41%   56.41%           
=======================================
  Files          19       19           
  Lines         927      927           
=======================================
  Hits          523      523           
  Misses        349      349           
  Partials       55       55

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab1c7f7...6d99b6e. Read the comment docs.

Copy link
Contributor

@corneliusweig corneliusweig left a comment

Choose a reason for hiding this comment

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

I think we can just drop the extra script. There is no need to enable gofmt, because we already do goimports.

A notable difference between the original setup and the suggested one is that the script gives a little more context. For example:

  • goimports via golangci-lint:
cmd/krew/cmd/search.go:92: File is not `goimports`-ed with -local sigs.k8s.io/krew (goimports)
                  rows = sortByFirstColumn(rows)
  • gofmt via script
Gofmt errors in files:
./cmd/krew/cmd/search.go
diff -u ./cmd/krew/cmd/search.go.orig ./cmd/krew/cmd/search.go
--- ./cmd/krew/cmd/search.go.orig       2019-12-04 20:42:47.010461167 +0100
+++ ./cmd/krew/cmd/search.go    2019-12-04 20:42:47.010461167 +0100
@@ -89,7 +89,7 @@
                        }
                        rows = append(rows, []string{name, limitString(plugin.Spec.ShortDescription, 50), status})
                }
-                 rows = sortByFirstColumn(rows)
+               rows = sortByFirstColumn(rows)
                return printTable(os.Stdout, cols, rows)
        },
        PreRunE: checkIndex,

I find the latter a little easier to understand, but it's not a big deal.

@@ -24,6 +26,7 @@ run:

linters:
enable:
- gofmt
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't even need this. Looking at golangci-lint linters | grep goimports:

goimports: Goimports does everything that gofmt does. Additionally it checks unused imports [fast: true, auto-fix: true]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not exactly correct.

goimports version of golangci doesn't do simplification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

here is the configuration: https://github.com/golangci/golangci-lint/blob/master/pkg/config/config.go#L139

maybe we should suggest adding it then goimports can be used solely.

Copy link
Contributor

@corneliusweig corneliusweig Dec 4, 2019

Choose a reason for hiding this comment

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

Mm.. looks like goimports doesn't do simplifications: golang/go#21476

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was a long standing demand, I thought it was already added but it seems it's still missing.

@ahmetb
Copy link
Member

ahmetb commented Dec 4, 2019

I find the latter a little easier to understand, but it's not a big deal.

Agreed.

@corneliusweig
Copy link
Contributor

So I guess this is indeed the best simplification for gofmt. From my side
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 4, 2019
@ferhatelmas
Copy link
Contributor Author

@ahmetb I believe this is waiting for your review/approval.

@ahmetb
Copy link
Member

ahmetb commented Dec 7, 2019

/lgtm
/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, ferhatelmas

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 7, 2019
@k8s-ci-robot k8s-ci-robot merged commit e37ee1d into kubernetes-sigs:master Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants