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

style: cleanup code by golangci-lint #797

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Dreamacro
Copy link
Contributor

@Dreamacro Dreamacro commented Jan 19, 2025

As described in #775, boxo requires a better static code analysis tool since the currently used ipdxco/unified-github-workflows has limitation capabilities.

Therefore, I am attempting to use golangci-lint here (while retaining the original ipdxco/unified-github-workflows). I have disabled all golangci-lint default configurations and enabled some checks that I find particularly valuable.

golangci-lint config

linters:
  disable-all: true
  enable:
    - gci
    - gofumpt
    - gosimple
    - govet
    - ineffassign
    - misspell
    - staticcheck
    - unconvert
    - unused
    - usestdlibvars

issue:
  exclude-files:
    - ".*\\.pb\\.go"

After performing the lint fixes, boxo generally has the following issues:

  1. Some files have imported package names divided into groups without any discernible pattern (if there is one, please let me know), and gci can fix this.
    for example:
    import (
    "bytes"
    "io"
    "strings"
    "testing"
    mdag "github.com/ipfs/boxo/ipld/merkledag"
    "github.com/ipfs/boxo/ipld/unixfs"
    context "context"
    testu "github.com/ipfs/boxo/ipld/unixfs/test"
    )
  2. many unnecessary type conversions can be detected and fixed using unconvert.
  3. Other minor issues, such as unnecessary blank lines, octal notation, statements that will never be executed, etc.

There might be some other valuable plugins, such as unused, and I would like to hear your opinions on them.

@Dreamacro Dreamacro requested review from lidel and a team as code owners January 19, 2025 11:57
Copy link

codecov bot commented Jan 19, 2025

Codecov Report

Attention: Patch coverage is 77.14286% with 8 lines in your changes missing coverage. Please review.

Project coverage is 60.49%. Comparing base (9d04741) to head (c591403).

Files with missing lines Patch % Lines
gateway/serve_http_content.go 25.00% 1 Missing and 2 partials ⚠️
files/util.go 66.66% 1 Missing ⚠️
filestore/fsrefstore.go 0.00% 1 Missing ⚠️
gateway/backend_car_files.go 0.00% 1 Missing ⚠️
ipld/unixfs/unixfs.go 0.00% 1 Missing ⚠️
routing/http/types/json/responses.go 50.00% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #797      +/-   ##
==========================================
+ Coverage   60.47%   60.49%   +0.02%     
==========================================
  Files         244      244              
  Lines       31102    31101       -1     
==========================================
+ Hits        18809    18816       +7     
+ Misses      10616    10610       -6     
+ Partials     1677     1675       -2     
Files with missing lines Coverage Δ
bitswap/bitswap.go 69.13% <ø> (ø)
bitswap/client/internal/getter/getter.go 81.81% <ø> (ø)
bitswap/client/internal/peermanager/peermanager.go 91.85% <ø> (ø)
...wap/client/internal/peermanager/peerwantmanager.go 88.50% <ø> (-0.04%) ⬇️
...tswap/client/internal/session/sessionwantsender.go 96.83% <ø> (+0.24%) ⬆️
...l/sessioninterestmanager/sessioninterestmanager.go 100.00% <ø> (ø)
...p/client/internal/sessionmanager/sessionmanager.go 100.00% <ø> (ø)
.../internal/sessionpeermanager/sessionpeermanager.go 100.00% <ø> (ø)
bitswap/client/wantlist/wantlist.go 90.47% <ø> (ø)
bitswap/message/message.go 83.15% <100.00%> (-0.72%) ⬇️
... and 64 more

... and 5 files with indirect coverage changes

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

Triage notes

  • thank you @Dreamacro – parking for now as we are unsure if we want to manually add this to every go repo
  • @galargh thoughts if this could/should be part of Unified CI for GO instead?

@hsanjuan
Copy link
Contributor

We could merge the fixes without the CI changes for now?

@Dreamacro
Copy link
Contributor Author

@hsanjuan I'll revert the CI changes later.

@Dreamacro Dreamacro changed the title feat: use golangci-lint for code static analysis style: cleanup code by golangci-lint Jan 22, 2025
@Dreamacro
Copy link
Contributor Author

done

@galargh
Copy link
Contributor

galargh commented Jan 23, 2025

go-check from uci uses govet and staticcheck. I think the addition of extra linters listed here to the common workflow should be evaluated individually:

- gci
- gofumpt
- gosimple
- ineffassign
- misspell
- unconvert
- unused
- usestdlibvars

It might be also worth considering making golangci-lint workflow part of the go-check, and exposing the linter selection to the workflow users.

One thing that I think we should keep in mind during that process is the quality of the local development iteration. We definitely want some level of static checking of the code, but we also don't want the checks to negatively impact the contribution experience.

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.

4 participants