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

Automatically format imports #151

Merged
merged 3 commits into from
Dec 4, 2018

Conversation

pavolloffay
Copy link
Member

Following the same approach as in /jaeger repo

Signed-off-by: Pavol Loffay [email protected]

Signed-off-by: Pavol Loffay <[email protected]>
@jpkrohling
Copy link
Contributor

This change is Reviewable

@codecov
Copy link

codecov bot commented Dec 3, 2018

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #151   +/-   ##
=======================================
  Coverage   96.21%   96.21%           
=======================================
  Files          28       28           
  Lines        1267     1267           
=======================================
  Hits         1219     1219           
  Misses         37       37           
  Partials       11       11
Impacted Files Coverage Δ
pkg/util/util.go 100% <ø> (ø) ⬆️
pkg/service/query.go 100% <ø> (ø) ⬆️
pkg/strategy/controller.go 100% <ø> (ø) ⬆️
pkg/configmap/ui.go
pkg/config/ui/ui.go 96.42% <0%> (ø)

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 a738c3a...5e83c53. Read the comment docs.

@pavolloffay pavolloffay mentioned this pull request Dec 3, 2018
Copy link
Contributor

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

Reviewed 14 of 14 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @pavolloffay)


scripts/import-order-cleanup.py, line 3 at r1 (raw file):

import argparse

def cleanup_imports_and_return(imports):

Isn't goimports sufficient? That's what my IDE is configured to use. Probably something like this would work:

$ goimports -w $(go list ./cmd/... ./pkg/...)

In the Makefile, the list of packages is stored in a var already.


scripts/import-order-cleanup.sh, line 5 at r1 (raw file):

set -e

python scripts/import-order-cleanup.py -o $1 -t $(git ls-files "*\.go" | grep -v -e vendor)

If we do end up needing the script, it would probably be better suited for the .travis directory, as we don't have a scripts yet. The check target should also be changed, to call this instead of go fmt.

@pavolloffay
Copy link
Member Author

If we do end up needing the script, it would probably be better suited for the .travis directory, as we don't have a scripts yet.

I will put it wherever you think it's the best. Seems odd to put things into .travis which are not related to travis...

Isn't goimports sufficient?

From https://godoc.org/golang.org/x/tools/cmd/goimports

In addition to fixing imports, goimports also formats your code in the same style as gofmt so it can be used as a replacement for your editor's gofmt-on-save hook.

goimports -w $(go list ./cmd/... ./pkg/...)                                                                                                              4:52 
stat github.com/jaegertracing/jaeger-operator/cmd: no such file or directory
stat github.com/jaegertracing/jaeger-operator/cmd/manager: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/account: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/apis: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/cmd/start: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/cmd/version: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/config/sampling: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/configmap: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/controller: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/controller/deployment: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/controller/jaeger: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/deployment: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/ingress: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/inject: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/route: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/service: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/storage: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/strategy: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/util: no such file or directory
stat github.com/jaegertracing/jaeger-operator/pkg/version: no such file or directory

Signed-off-by: Pavol Loffay <[email protected]>
Copy link
Contributor

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r2.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @pavolloffay)

a discussion (no related file):

I will put it wherever you think it's the best. Seems odd to put things into .travis which are not related to travis...

If the script is called as part of make check, then it's checked by Travis ;-)

I ran the script locally and compared with goimports ..., and it does look like it does more things.


@pavolloffay
Copy link
Member Author

@jpkrohling is there anything missing in this PR?

I would like to be consistent with jaeger repo to provide the same source code structure. Enforcing style at build time is the only way how to check the code is properly formatted. As you can see the imports are mismatched in the current master.

Copy link
Contributor

@jpkrohling jpkrohling left a comment

Choose a reason for hiding this comment

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

The only thing missing is to fail the build if a call to import-order-cleanup.sh yields changes.

Currently, the check target relies on the output of go fmt (not make format) to check if formatting changes need to be done and fail the CI build accordingly. With the changes from this PR, we need to add this script to the check as well, to also fail the build if changes were detected. You can take a look at the ensure-generate-is-noop for a way to check if the git clone isn't clean.

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @pavolloffay)

@pavolloffay
Copy link
Member Author

Check added

@objectiser objectiser merged commit 610d415 into jaegertracing:master Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants