Skip to content

chore/linter #467

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

Merged
merged 30 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c0b600f
update database schema diagram
Sep 19, 2024
4f1f3d7
Merge branch 'main' of github.com:data-preservation-programs/singularity
Feb 27, 2025
d4ab4e9
devcontainers ignore
Mar 25, 2025
932668c
update settings for 2.x linter
Mar 25, 2025
6015fff
fix linting with golangci v2
parkan Apr 30, 2025
f04d3c8
use modern `go install` instead of GO111MODULE
parkan Apr 30, 2025
c38e511
modernize toolchain
parkan Apr 30, 2025
1e8cba5
fix linter errors
parkan Apr 30, 2025
cfbcab9
make linter work on github actions
parkan May 1, 2025
108afab
try alternate migration strategy
parkan May 1, 2025
b4accae
unused import, formatting
parkan May 1, 2025
a0ab4b1
disable linters added since 1.55.2, suppress errcheck
parkan May 1, 2025
f31e212
lint autofixes
parkan May 1, 2025
7f88f1a
int32 for epoch is safe, auto-fixes
parkan May 1, 2025
e0f460d
update linter name for (go)err113
parkan May 1, 2025
bae794f
use core slices instead of exp/slices
parkan May 1, 2025
ce2d30e
disable lint for remaining epoch and cid/block length sites
parkan May 1, 2025
f465731
thelper fix, autofix
parkan May 1, 2025
515c52c
suppress predeclared since that's what the param is called
parkan May 1, 2025
c522d7c
suppress recvcheck for Value() methods
parkan May 1, 2025
9f35caa
better suppression for revcheck for Value
parkan May 1, 2025
5d73bbe
exclude marshalling functions from recvcheck
parkan May 1, 2025
1c4a325
always pass server by pointer, clear last recvcheck
parkan May 1, 2025
25ca84b
add nil check
parkan May 1, 2025
7ed4aa2
suppress file perms errors for docs
parkan May 1, 2025
398367d
warn on and handle unknown/-1 file size in assembler
parkan May 1, 2025
ea47335
suppress remaining overflow warnings :(
parkan May 1, 2025
5472869
tidy
parkan May 1, 2025
66575a8
infer go version from go.mod for sake of sanity
parkan May 1, 2025
cc18ff4
generate
parkan May 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/actions/go-check-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ runs:
restore-keys: |
${{ matrix.os }}-golang-${{ matrix.go }}-

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v7
with:
version: v1.55.2
version: v2.1.5
args: --timeout=10m
4 changes: 2 additions & 2 deletions .github/workflows/auto-generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
ref: ${{ github.head_ref }}

- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.20.x'
go-version-file: 'go.mod'

- name: Run go generate
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/go-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ concurrency:

jobs:
go-check:
uses: ipdxco/unified-github-workflows/.github/workflows/[email protected].17
uses: ipdxco/unified-github-workflows/.github/workflows/[email protected].22
4 changes: 2 additions & 2 deletions .github/workflows/release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: "1.20.x"
go-version-file: 'go.mod'
- name: Release Binaries
uses: goreleaser/goreleaser-action@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
/baga*
singularity.db*

# Devcontainer
.devcontainer/

node_modules
/.pnp
Expand Down
163 changes: 87 additions & 76 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,87 @@
run:
tests: false
skip-dirs:
- replication/internal
- cmd/embed
- docs
- dashboard/model2ts
- handler/datasource/generate
- handler/storage/gen
skip-files:
- cmd/testutil.go

linters:
enable-all: true
disable:
- typecheck
- interfacer
- structcheck
- golint
- ifshort
- scopelint
- varcheck
- varnamelen
- maligned
- deadcode
- structcheck
- gci
- goimports
- gofumpt
- nolintlint
- ireturn
- nosnakecase
- nlreturn
- godox
- gomoddirectives
- rowserrcheck
- sqlclosecheck
- wastedassign
- gocognit
- wsl
- musttag
- exhaustivestruct
- cyclop
- gomnd
- gochecknoglobals
- funlen
- gocyclo
- exhaustruct
- wrapcheck
- nestif
- containedctx
- maintidx
- nonamedreturns
- nilnil
- prealloc
- gochecknoinits
- dupl
- forbidigo
- godot
- depguard
- nakedret
- tagalign
- lll
- dupword
- interfacebloat
- goconst

linters-settings:
errcheck:
exclude-functions:
- (github.com/libp2p/go-libp2p/network.MuxedStream).SetDeadline
- (github.com/data-preservation-programs/singularity/service.DatasetWorker).cleanup
revive:
rules:
- name: var-naming
disabled: true
version: "2"
run:
tests: false
linters:
default: all
disable:
- containedctx
- cyclop
- depguard
- dupl
- dupword
- exhaustruct
- forbidigo
- funlen
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocyclo
- godot
- godox
- gomoddirectives
- interfacebloat
- ireturn
- lll
- maintidx
- mnd
- musttag
- nakedret
- nestif
- nilnil
- nlreturn
- nolintlint
- nonamedreturns
- prealloc
- rowserrcheck
- sqlclosecheck
- tagalign
- varnamelen
- wastedassign
- wrapcheck
- wsl
- contextcheck
- forcetypeassert
- funcorder
- exhaustive
- intrange
settings:
gosec:
excludes:
- G115 # we do a lot of uint64 conversions unfortunately
errcheck:
exclude-functions:
- path/filepath.Walk
- (github.com/libp2p/go-libp2p/network.MuxedStream).SetDeadline
- (github.com/data-preservation-programs/singularity/service.DatasetWorker).cleanup
revive:
rules:
- name: var-naming
disabled: true
recvcheck:
disable-builtin: true
exclusions:
- "*.Value"
- "*.String"
- "*.MarshalBinary"
- "*.MarshalJSON"
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ check-go:
@which go > /dev/null || (echo "Go is not installed. Please install Go." && exit 1)

install-lint-deps:
@which golangci-lint > /dev/null || (echo "Required golangci-lint not found. Installing it..." && GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
@which staticcheck > /dev/null || (echo "Required staticcheck not found. Installing it..." && GO111MODULE=on go get honnef.co/go/tools/cmd/staticcheck)
@which golangci-lint > /dev/null || (echo "Required golangci-lint not found. Installing it..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
@which staticcheck > /dev/null || (echo "Required staticcheck not found. Installing it..." && go install honnef.co/go/tools/cmd/staticcheck@latest)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we might want to lock this but keeping the local version on latest does make it a bit more likely that we'll keep up with upstream changes


install-test-deps:
@which gotestsum > /dev/null || (echo "Installing gotestsum..." && GO111MODULE=on go get gotest.tools/gotestsum@latest)
Expand All @@ -29,8 +29,10 @@ generate: check-go
go generate ./...

lint: check-go install-lint-deps
@echo "Verifying golangci-lint configuration..."
golangci-lint config verify
gofmt -s -w .
golangci-lint run --no-config --fix --disable-all -E tagalign --timeout 10m
golangci-lint run --no-config --fix --default=none -E tagalign --timeout 10m
golangci-lint run --fix --timeout 10m
staticcheck ./...

Expand Down
6 changes: 4 additions & 2 deletions analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ func Init(ctx context.Context, db *gorm.DB) error {
return nil
}

var Instance string
var Identity string
var (
Instance string
Identity string
)

type Collector struct {
mu sync.Mutex
Expand Down
31 changes: 15 additions & 16 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
"strconv"
"time"

"github.com/cockroachdb/errors"
"github.com/data-preservation-programs/singularity/analytics"
"github.com/data-preservation-programs/singularity/database"
_ "github.com/data-preservation-programs/singularity/docs/swagger"
"github.com/data-preservation-programs/singularity/handler/admin"
"github.com/data-preservation-programs/singularity/handler/dataprep"
"github.com/data-preservation-programs/singularity/handler/deal"
Expand All @@ -29,17 +32,13 @@ import (
"github.com/data-preservation-programs/singularity/service/contentprovider"
"github.com/data-preservation-programs/singularity/util"
"github.com/filecoin-project/lassie/pkg/lassie"
"github.com/libp2p/go-libp2p/core/host"
"github.com/ybbus/jsonrpc/v3"

"github.com/cockroachdb/errors"
"github.com/data-preservation-programs/singularity/database"
_ "github.com/data-preservation-programs/singularity/docs/swagger"
logging "github.com/ipfs/go-log/v2"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/libp2p/go-libp2p/core/host"
echoSwagger "github.com/swaggo/echo-swagger"
"github.com/urfave/cli/v2"
"github.com/ybbus/jsonrpc/v3"
"gorm.io/gorm"
)

Expand All @@ -61,7 +60,7 @@ type Server struct {
scheduleHandler schedule.Handler
}

func (s Server) Name() string {
func (s *Server) Name() string {
return "api"
}

Expand All @@ -75,7 +74,7 @@ func (s Server) Name() string {
// @Failure 404 {string} string "Not Found"
// @Failure 500 {string} string "Internal Server Error"
// @Router /piece/{id}/metadata [get]
func (s Server) getMetadataHandler(c echo.Context) error {
func (s *Server) getMetadataHandler(c echo.Context) error {
return contentprovider.GetMetadataHandler(c, s.db)
}

Expand Down Expand Up @@ -112,18 +111,18 @@ type APIParams struct {
ConnString string
}

func InitServer(ctx context.Context, params APIParams) (Server, error) {
func InitServer(ctx context.Context, params APIParams) (*Server, error) {
db, closer, err := database.OpenWithLogger(params.ConnString)
if err != nil {
return Server{}, errors.WithStack(err)
return nil, errors.WithStack(err)
}
h, err := util.InitHost(nil)
if err != nil {
return Server{}, errors.Wrap(err, "failed to init host")
return nil, errors.Wrap(err, "failed to init host")
}
lassie, err := lassie.NewLassie(ctx, lassie.WithHost(h))
if err != nil {
return Server{}, errors.Wrap(err, "failed to init lassie")
return nil, errors.Wrap(err, "failed to init lassie")
}
infoFetcher := replication.MinerInfoFetcher{
Client: util.NewLotusClient(params.LotusAPI, params.LotusToken),
Expand All @@ -136,7 +135,7 @@ func InitServer(ctx context.Context, params APIParams) (Server, error) {
endpointfinder.WithErrorLruSize(128),
endpointfinder.WithErrorLruTimeout(time.Minute*5),
)
return Server{
return &Server{
db: db,
host: h,
listener: params.Listener,
Expand Down Expand Up @@ -184,7 +183,7 @@ func InitServer(ctx context.Context, params APIParams) (Server, error) {
// This method assumes a specific ordering and kind of parameters in the handler functions.
// It is designed to simplify the process of defining Echo handlers but has limitations
// in terms of the variety of supported handler function signatures.
func (s Server) toEchoHandler(handlerFunc any) echo.HandlerFunc {
func (s *Server) toEchoHandler(handlerFunc any) echo.HandlerFunc {
return func(c echo.Context) error {
handlerFuncValue := reflect.ValueOf(handlerFunc)
handlerFuncType := handlerFuncValue.Type()
Expand Down Expand Up @@ -295,7 +294,7 @@ func (s Server) toEchoHandler(handlerFunc any) echo.HandlerFunc {
}
}

func (s Server) setupRoutes(e *echo.Echo) {
func (s *Server) setupRoutes(e *echo.Echo) {
// Admin
e.POST("/api/identity", s.toEchoHandler(s.adminHandler.SetIdentityHandler))
// Storage
Expand Down Expand Up @@ -402,7 +401,7 @@ var logger = logging.Logger("api")
// 3. Completion of analytics event flushing.
// - A channel (service.Fail) that reports errors that occur while the server is running.
// - An error if there is an issue during the initialization phase, otherwise nil.
func (s Server) Start(ctx context.Context, exitErr chan<- error) error {
func (s *Server) Start(ctx context.Context, exitErr chan<- error) error {
err := analytics.Init(ctx, s.db)
if err != nil {
return errors.WithStack(err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/download.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"slices"

"github.com/cockroachdb/errors"
"github.com/data-preservation-programs/singularity/cmd/cliutil"
"github.com/data-preservation-programs/singularity/cmd/storage"
Expand All @@ -9,7 +11,6 @@ import (
"github.com/data-preservation-programs/singularity/storagesystem"
"github.com/ipfs/go-log"
"github.com/urfave/cli/v2"
"golang.org/x/exp/slices"
)

var DownloadCmd = &cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/ez/prep.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var PrepCmd = &cli.Command{
outputDir := c.String("output-dir")
var outputStorages []string
if outputDir != "" {
err = os.MkdirAll(outputDir, 0755)
err = os.MkdirAll(outputDir, 0o755)
if err != nil {
return errors.Wrap(err, "failed to create output directory")
}
Expand Down
Loading
Loading