Skip to content

Check we have goimports#453

Merged
Waldz merged 4 commits intomysteriumnetwork:masterfrom
tcharding:functions
Oct 18, 2018
Merged

Check we have goimports#453
Waldz merged 4 commits intomysteriumnetwork:masterfrom
tcharding:functions

Conversation

@tcharding
Copy link
Copy Markdown
Contributor

@tcharding tcharding commented Oct 17, 2018

bin/check_goimports succeeds even when goimports is not installed. This is because a shell variable gets set to the shell error for 'command not found'. Subsequent check on that variable is logically incorrect because of this. We can fix this by asserting we have the command goimports before calling it.

This is a reasonably common thing to do so lets add a function to bin/helpers/ to do the check. Also test the new function.

Patch 1: Adds the helper function need_cmd.
Patch 2: Adds extendable test script bin/helpers/test.sh and tests need_cmd
Patch 3: Adds statement to check_goimports: need_cmd goimports

Fixes: #450

Please note: This is untested since I don't have access to the CI infrastructure. Applying this patch will cause check_goimports to fail if goimports is not installed on the CI infrastructure (by design).

Signed-off-by: Tobin C. Harding me@tobin.cc

Comment thread bin/check_goimports

print_success "All files are compliant to goimports."
exit 0 No newline at end of file
exit 0
Copy link
Copy Markdown
Contributor Author

@tcharding tcharding Oct 17, 2018

Choose a reason for hiding this comment

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

I couldn't seem to get an editor to edit this file without adding these 'exit 0' lines to the diff. I tried emacs and vim?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's ok, it's even better to have a new line at the end of the file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

+1 that is my opinion also. I'll add the newline in a separate patch and force push.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added newline.

Comment thread bin/check_goimports Outdated
@@ -13,6 +13,9 @@
#> bin/check_goimports ./communication/...

source bin/helpers/output.sh
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
source bin/helpers/output.sh
set -e
source bin/helpers/output.sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

missing set -e in header, so that script would fail with missing goimports or any other error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

set -e seems to be shunned by some people [1] but I see it is use widely here. Whats the ruling on this? If you guys want set -e I'll close this and do a patch adding set -e to check_goimports.

[1] http://mywiki.wooledge.org/BashFAQ/105

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Used this solution as advised. PR has been updated.

thanks

zolia
zolia previously approved these changes Oct 17, 2018
Copy link
Copy Markdown
Contributor

@zolia zolia left a comment

Choose a reason for hiding this comment

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

lgtm

Currently bin/check_goimports does not end with a newline.  In keeping
with UNIX folklore we should have a newline on the end of a shell script
file.

Add newline to end of shell script file.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
Currently bin/check_goimports is missing `set -e` line.

Add `set -e`

Fixes: Issue #450

Signed-off-by: Tobin C. Harding <me@tobin.cc>
@Waldz Waldz merged commit a4927a1 into mysteriumnetwork:master Oct 18, 2018
@tcharding tcharding deleted the functions branch October 19, 2018 03:07
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.

Goimports check do nothing since goimport is not installed for CI

5 participants