Skip to content

Travis: Check for gofmt issues.#241

Merged
shazow merged 2 commits intoshazow:masterfrom
dmitshur:patch-1
Jul 17, 2017
Merged

Travis: Check for gofmt issues.#241
shazow merged 2 commits intoshazow:masterfrom
dmitshur:patch-1

Conversation

@dmitshur
Copy link
Copy Markdown
Contributor

This will help catch issues like #240 (comment) in CI.

If you want to be even more strict and require all Go code to be simplified, then you can add -s option to gofmt, like I've done here. Since it's not my repository, I went with the more permissive option by default.

This will help catch issues like #240 (comment)
in CI.
@shazow
Copy link
Copy Markdown
Owner

shazow commented Jul 17, 2017

Nice, love it! I'm happy to make it more strict.

Want to do that, and also make the minor changes in the codebase to make it pass? :D

@dmitshur
Copy link
Copy Markdown
Contributor Author

Nice, love it! I'm happy to make it more strict.

Glad to hear that.

Want to do that, and also make the minor changes in the codebase to make it pass? :D

Sure, I'll expand the scope of the PR to include that as well.

@dmitshur
Copy link
Copy Markdown
Contributor Author

dmitshur commented Jul 17, 2017

The reason CI fails is because some of the vendored dependencies are not compatible with gofmt -s (luckily, they are compatible with plain gofmt).

I've discussed the options for a resolution with @shazow, which are:

  1. See if a newer version already fixes it, update to it if so.
  2. Otherwise, try to send a PR upstream to fix it myself, and if/once it's merged, update the vendored copy.
  3. Find a way to ignore /vendor/ from gofmt -s check.

He told me he prefers option 3, and it's consistent with some of the CI checks already skipping /vendor/.

I've never had to skip /vendor/ from gofmt checks in my experience, because I use a different solution to vendoring. So I looked into this now, and it's not easy.

  • gofmt itself takes a path (not import paths), and as soon as you give it a directory, you have no way of stopping it from recursively descending all further directories, including /vendor/.
  • gofmt can take individual .go files, but then I'd need to write a bash loop that iterates over all directories, but doesn't descend into /vendor/, and calls gofmt -s on all .go files it finds.
  • go fmt, a higher level command available in go binary, takes import paths, so go fmt (go list ./... | grep -v /vendor/) could be done to skip /vendor/. But it's not configurable, and defaults to writing to disk, listing files that were affected, and not actually displaying the diff, which makes it hard to see in failed CI output what the gofmt problem was.

I don't want to spend time writing that custom loop logic in bash, so the best long term solution I think is to create a small custom Go command that performs the needed logic (skipping vendor directories). (Or find an existing command that does what's needed, if that's faster/easier.) But, I don't have a budget to work on that for this PR, so that leaves me with these 2 options:

  1. Avoid -s flag and use plain gofmt. It will run on vendored directories, which will make tests pass for now, but might cause a failure in the future if a vendored dependency is added that is not compatible with gofmt.
  2. Close this PR because I don't have the resources to implement all the work needed to get it to merge-able state.

@shazow How would you like to proceed?

@shazow
Copy link
Copy Markdown
Owner

shazow commented Jul 17, 2017

@shurcooL Wow thanks for all your effort writing up the situation.

Let's just move forward with plain go fmt without the -s since it seems Everything Works with it for now and I'll investigate ignoring vendor later.

@dmitshur
Copy link
Copy Markdown
Contributor Author

SGTM, I'll do that.

@dmitshur
Copy link
Copy Markdown
Contributor Author

Updated, tests are passing, PTAL.

@shazow
Copy link
Copy Markdown
Owner

shazow commented Jul 17, 2017

Excellent, huge thanks @shurcooL! 🍮

@shazow shazow merged commit 50001bf into shazow:master Jul 17, 2017
@dmitshur dmitshur deleted the patch-1 branch July 17, 2017 19:04
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.

2 participants