Skip to content

ci: use gofumpt because gofmt and goimports conflicted#9738

Closed
faddat wants to merge 6 commits intotendermint:mainfrom
faddat:linting
Closed

ci: use gofumpt because gofmt and goimports conflicted#9738
faddat wants to merge 6 commits intotendermint:mainfrom
faddat:linting

Conversation

@faddat
Copy link
Contributor

@faddat faddat commented Nov 22, 2022

This PR changes away from gofmt and goimports to gofumpt. This allows the use of the
latest version of golangci-lint and makes the code much easier to read overall.

Since there are clearly issues in linting, a second PR will ensure that CI fails when the
linter fails.

A serious observation is that we should improve on the boring items.

Total changes:

solve conflict when running golangci-lint locally

  • remove from .golangci.yml:
    • goimports
    • gofmt
  • add to .golangci.yml
    • gofumpt

ensure that golangci-lint runs every time files are changed and matches a local dev env

  • don't specify a version of go in .github/workflows/lint.yml
    • it will use latest
  • set .github/workflows/lint.yml to use latest golangci-lint
    • linters change over time but we don't think about this file too much. This will make CI fail if linters have changed so that we can keep up with upstream changes.

adhere to PHILOSOPHY.md

  • ensure readability and standardization by using gofumpt, a code formatting tool.
  • Tests written/updated, or no tests needed
  • CHANGELOG_PENDING.md updated, or no changelog entry needed
  • Updated relevant documentation (docs/) and code comments, or no
    documentation updates needed

@faddat faddat requested a review from ebuchman as a code owner November 22, 2022 06:37
@faddat faddat requested a review from a team November 22, 2022 06:37
@faddat faddat changed the title use gofumpt, it is far more consistent ci: use gofumpt, it is far more consistent Nov 22, 2022
@faddat faddat changed the title ci: use gofumpt, it is far more consistent ci: use gofumpt because gofmt and goimports conflicted Nov 22, 2022
@faddat
Copy link
Contributor Author

faddat commented Nov 22, 2022

I think that this is affected by the "flaky tests"

@faddat faddat mentioned this pull request Nov 22, 2022
3 tasks
@thanethomson
Copy link
Contributor

@faddat could you please share more context on the problem(s) you're trying to solve in more detail for us?

@faddat
Copy link
Contributor Author

faddat commented Nov 22, 2022

@thanethomson sure! So, basically this PR changes just code formatting and the Makefile.

this PR:

  • makes it possible to run golangci-lint run ./... --fix to do the same work that was previously done with several commands in the makefile
  • gofmt and goimports will no longer conflict one another when running golangci-lint run ./... --fix
    • they're replaced entirely with gofumpt, which is does what goimports and gofmt do, but better.
  • the code will be easier to read & write because it will be very consistently formatted
  • makes maintaining a repository easier, due to strict formatting
  • fixes an issue that's experienced when running golangci-lint with go 1.19 and golangci-lint v1.50.1

@thanethomson
Copy link
Contributor

thanethomson commented Nov 24, 2022

When I run golangci-lint run ./... --fix on main with golangci-lint v1.50.1 and Go 1.19.3 it works just fine, and doesn't result in any changes to the existing code.

While I understand that you may find this to be an improvement @faddat, our team still does not, as per #8478 (comment).

mergify bot pushed a commit that referenced this pull request Nov 24, 2022
## NOTE: this pr exclusively runs commands from the makefile found here


This PR ONLY runs `make format` ... then `make mockery`



Its purpose is to ensure that the review scope of other PR's, which changed .go files and thus triggered the linter that only runs conditionally, have smaller review 
scopes, and should be merged before:

#9738
#9739
#9742






---

#### PR checklist

- [x] Tests written/updated, or no tests needed
- [x] `CHANGELOG_PENDING.md` updated, or no changelog entry needed
- [x] Updated relevant documentation (`docs/`) and code comments, or no
      documentation updates needed
@sergio-mena
Copy link
Contributor

sergio-mena commented Nov 25, 2022

@faddat , as discussed yesterday during Tendermint's community call, here is a git command I just ran to gauge the changes between main and v0.36.x:

 % git fetch; for d in $(echo */); do echo "$d:\t\t$(git diff origin/main..origin/v0.36.x --shortstat -- $d)"; done
DOCKER/:		 9 files changed, 18 insertions(+), 123 deletions(-)
abci/:		 39 files changed, 6897 insertions(+), 7404 deletions(-)
blocksync/:		 8 files changed, 1885 deletions(-)
cmd/:		 29 files changed, 1834 insertions(+), 1365 deletions(-)
config/:		 5 files changed, 1017 insertions(+), 916 deletions(-)
consensus/:		 26 files changed, 14283 deletions(-)
crypto/:		 36 files changed, 252 insertions(+), 1012 deletions(-)
docs/:		 238 files changed, 4814 insertions(+), 23093 deletions(-)
evidence/:		 9 files changed, 2759 deletions(-)
internal/:		 305 files changed, 78124 insertions(+), 247 deletions(-)
libs/:		 96 files changed, 1085 insertions(+), 11204 deletions(-)
light/:		 38 files changed, 6628 insertions(+), 2588 deletions(-)
mempool/:		 23 files changed, 4999 deletions(-)
networks/:		 26 files changed, 207 insertions(+), 133 deletions(-)
node/:		 6 files changed, 1709 insertions(+), 1502 deletions(-)
p2p/:		 45 files changed, 13750 deletions(-)
privval/:		 25 files changed, 2042 insertions(+), 741 deletions(-)
proto/:		 53 files changed, 6839 insertions(+), 3626 deletions(-)
proxy/:		 13 files changed, 1496 deletions(-)
rpc/:		 73 files changed, 5429 insertions(+), 7491 deletions(-)
scripts/:		 20 files changed, 1822 insertions(+), 268 deletions(-)
spec/:		 82 files changed, 4500 insertions(+), 2957 deletions(-)
state/:		 43 files changed, 9532 deletions(-)
statesync/:		 14 files changed, 3634 deletions(-)
store/:		 2 files changed, 1234 deletions(-)
test/:		 69 files changed, 2303 insertions(+), 2523 deletions(-)
third_party/:		 1 file changed, 3 deletions(-)
tools/:		 10 files changed, 2 insertions(+), 895 deletions(-)
types/:		 53 files changed, 5465 insertions(+), 2396 deletions(-)
version/:		 1 file changed, 25 insertions(+), 8 deletions(-)
%

This should give a rough idea on where the changes we are likely to cherry-pick concentrate.

I propose to draw the line at top-level directories where the sum of insertions + deletions is less than 2000. So the directories that should not apply gofumpt for the moment are:

  • abci, cmd, consensus, evidence, internal, libs, light, mempool, node, p2p, privval, proto, rpc, state, statesync, test, types

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