Skip to content

Linter PR 3: enable additional linters #589

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

Closed
wants to merge 59 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
fdaf809
enable additional linters
faddat Dec 22, 2024
016154b
Merge branch 'faddat/testifylint' into faddat/bump-go
faddat Dec 22, 2024
71b2d1e
adjust golang version in circleci
faddat Dec 22, 2024
f371399
bump go...
faddat Dec 22, 2024
cbde717
remove dupl
faddat Dec 22, 2024
08ea4c4
lint main.go
faddat Jan 2, 2025
7a812f5
lints...
faddat Jan 2, 2025
65039a5
complete
faddat Jan 2, 2025
ada59f4
Merge branch 'main' into faddat/bump-go
faddat Jan 16, 2025
a06cd0d
remove mutext lock in lib_test.go
faddat Jan 17, 2025
1118f26
remove unused variable
faddat Jan 17, 2025
d6c14e6
restore comments
faddat Jan 17, 2025
d943802
fix lint in .golangci.yml
faddat Jan 17, 2025
f9e29a6
Merge branch 'faddat/errcheck' into faddat/bump-go
faddat Feb 1, 2025
ce052d6
lint
faddat Feb 1, 2025
59fa5a4
Refactor test helper function for creating message binary
faddat Feb 14, 2025
20aaea0
revert unnecessary change
faddat Feb 18, 2025
19d75a5
resolve merge conflict and reduce required go version
faddat Feb 19, 2025
f74e259
adjust loop to go 1.21
faddat Feb 19, 2025
4b11854
Merge branch 'main' into faddat/bump-go
faddat Mar 14, 2025
27e6cf1
merge in main and update lints`
faddat Mar 14, 2025
911008b
match local lint version
faddat Mar 14, 2025
2ebfdeb
bumps
faddat Mar 22, 2025
4d60b62
Merge remote-tracking branch 'origin/main' into faddat/bump-go
faddat Apr 16, 2025
c6229a8
lint...
faddat Apr 16, 2025
f79f7b4
cleanup
faddat Apr 16, 2025
6c21a8d
add docs
faddat Apr 16, 2025
e8af78d
variable names
faddat Apr 16, 2025
c0fde34
hand out bumps to the cosmwasm crew
faddat Apr 17, 2025
7d87acb
bumps
faddat Apr 18, 2025
d5fc267
Merge branch 'faddat/bumps' into faddat/bump-go
faddat Apr 18, 2025
00a598d
fix test
faddat Apr 18, 2025
61f2fdd
fix ibc_test.go
faddat Apr 18, 2025
f0c9656
modernize
faddat Apr 18, 2025
ab26cd4
run modernize and reduce linter config
faddat Apr 18, 2025
93b7037
modernize
faddat Apr 18, 2025
796529c
fix tests and lint
faddat Apr 18, 2025
d62722c
BuiltInShadow
faddat Apr 18, 2025
b4a77fc
resolve cpuloop issues
faddat Apr 18, 2025
4cd1937
revive
faddat Apr 18, 2025
3eda296
add uniffi
faddat Apr 18, 2025
1ef0e24
fix additional tests
faddat Apr 18, 2025
322ed5e
fix all tests
faddat Apr 18, 2025
b93a7a5
use constants
faddat Apr 18, 2025
56ad1fa
more constants...
faddat Apr 18, 2025
6a191ff
add a no-cgo liblib file
faddat Apr 18, 2025
d7c0edf
update linter fixes
faddat Apr 18, 2025
1334555
fix golangci-lint config
faddat Apr 18, 2025
eaeaf7d
refactor: update function signatures to use ContractCallParams struct…
faddat Apr 18, 2025
e3315f7
localtestexecute
faddat Apr 18, 2025
485020c
assignment mismatches
faddat Apr 18, 2025
8ec232e
finish implementing revive
faddat Apr 18, 2025
d8e56bd
Merge remote-tracking branch 'origin/main' into faddat/bump-go
faddat Apr 21, 2025
6a99a76
restore missing ibc tests
faddat Apr 21, 2025
dc7da81
lint
faddat Apr 21, 2025
e99c796
update tests
faddat Apr 21, 2025
de8ae56
Merge remote-tracking branch 'origin/main' into faddat/bump-go
faddat Apr 22, 2025
d41ec14
lint json size
faddat Apr 22, 2025
be73d7d
Merge remote-tracking branch 'origin/main' into faddat/bump-go
faddat Apr 23, 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
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:

format-go:
docker:
- image: cimg/go:1.21.4
- image: cimg/go:1.23.4
steps:
- run:
name: Install gofumpt
Expand All @@ -186,7 +186,7 @@ jobs:
# Build types and cosmwam package without cgo
wasmvm_no_cgo:
docker:
- image: cimg/go:1.21.4
- image: cimg/go:1.23.4
steps:
- checkout
- run:
Expand All @@ -205,7 +205,7 @@ jobs:
# Build types and cosmwasm with libwasmvm linking disabled
nolink_libwasmvm:
docker:
- image: cimg/go:1.21.4
- image: cimg/go:1.23.4
steps:
- checkout
- run:
Expand All @@ -223,7 +223,7 @@ jobs:

tidy-go:
docker:
- image: cimg/go:1.21.4
- image: cimg/go:1.23.4
steps:
- checkout
- run:
Expand All @@ -241,7 +241,7 @@ jobs:

format-scripts:
docker:
- image: cimg/go:1.21.4
- image: cimg/go:1.23.4
steps:
- run:
name: Install shfmt
Expand Down Expand Up @@ -298,7 +298,7 @@ jobs:
# Test the Go project and run benchmarks
wasmvm_test:
docker:
- image: cimg/go:1.21.4
- image: cimg/go:1.23.4
environment:
GORACE: "halt_on_error=1"
BUILD_VERSION: $(echo ${CIRCLE_SHA1} | cut -c 1-10)
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
<<<<<<< HEAD


=======
>>>>>>> faddat/errcheck
go-version: "1.23.4"
cache: false
- name: golangci-lint
Expand Down
51 changes: 46 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
run:
tests: true
timeout: 5m

linters:
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- gofumpt
- gci
- testifylint
- errcheck
- thelper
- copyloopvar # Detect copy loops
- errcheck # Detect unchecked errors
- gosimple # Simplify code
- govet # Reports suspicious constructs
- ineffassign # Detect unused assignments
- staticcheck # Go static analysis
- typecheck # Go type checker
- unused # Detect unused constants, variables, functions and types

# Additional recommended linters
- gocritic # A more opinionated linter
- gosec # Security checker
- misspell # Find commonly misspelled words
- revive # a metalinter with more checks
- bodyclose # Check HTTP response bodies are closed
- goconst # Find repeated strings that could be constants
# - gocyclo # Check function complexity
- godot # Check comment endings
- gocognit # Check cognitive complexity
- whitespace # Check trailing whitespace
- thelper # Detect test helpers not using t.Helper()
- tparallel # Detect incorrect usage of t.Parallel()

linters-settings:
gci:
Expand Down Expand Up @@ -37,7 +55,30 @@ linters-settings:
# Drops lexical ordering for custom sections.
# Default: false
no-lex-order: true
gocritic:
# Enable all gocritic checks.
disabled-checks:
- dupSubExpr
gocyclo:
min-complexity: 15
gocognit:
min-complexity: 20
dupl:
threshold: 100
goconst:
min-len: 3
min-occurrences: 3
revive:
rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming
- name: var-naming
severity: warning
disabled: true

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude-dirs:
- vendor/
- third_party/
66 changes: 52 additions & 14 deletions cmd/demo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,91 @@ import (
"fmt"
"math"
"os"
"path/filepath"
"strings"

wasmvm "github.com/CosmWasm/wasmvm/v2"
)

// PrintDebug enables debug printing when true.
const (
PRINT_DEBUG = true
MEMORY_LIMIT = 32 // MiB
CACHE_SIZE = 100 // MiB
PrintDebug = true
// MemoryLimit defines the memory limit in MiB.
MemoryLimit = 32
// CacheSize defines the cache size in MiB.
CacheSize = 100
)

var SUPPORTED_CAPABILITIES = []string{"staking"}
// SupportedCapabilities defines the list of supported staking capabilities.
var SupportedCapabilities = []string{"staking"}

// This is just a demo to ensure we can compile a static go binary
// exitCode tracks the code that the program will exit with.
var exitCode = 0

// main is the entry point for the demo application that tests wasmvm functionality.
func main() {
defer func() {
os.Exit(exitCode)
}()

if len(os.Args) < 2 {
fmt.Println("Usage: demo <file|version>")
exitCode = 1
return
}

file := os.Args[1]

if file == "version" {
libwasmvmVersion, err := wasmvm.LibwasmvmVersion()
if err != nil {
panic(err)
fmt.Printf("Error getting libwasmvm version: %v\n", err)
exitCode = 1
return
}
fmt.Printf("libwasmvm: %s\n", libwasmvmVersion)
return
}

fmt.Printf("Running %s...\n", file)
bz, err := os.ReadFile(file)

// Validate file path
cleanPath := filepath.Clean(file)
if filepath.IsAbs(cleanPath) || strings.Contains(cleanPath, "..") {
fmt.Println("Error: invalid file path")
exitCode = 1
return
}

bz, err := os.ReadFile(cleanPath)
if err != nil {
panic(err)
fmt.Printf("Error reading file: %v\n", err)
exitCode = 1
return
}
fmt.Println("Loaded!")

err = os.MkdirAll("tmp", 0o755)
err = os.MkdirAll("tmp", 0o750)
if err != nil {
panic(err)
fmt.Printf("Error creating tmp directory: %v\n", err)
exitCode = 1
return
}
vm, err := wasmvm.NewVM("tmp", SUPPORTED_CAPABILITIES, MEMORY_LIMIT, PRINT_DEBUG, CACHE_SIZE)
vm, err := wasmvm.NewVM("tmp", SupportedCapabilities, MemoryLimit, PrintDebug, CacheSize)
if err != nil {
panic(err)
fmt.Printf("Error creating VM: %v\n", err)
exitCode = 1
return
}
defer vm.Cleanup()

checksum, _, err := vm.StoreCode(bz, math.MaxUint64)
if err != nil {
panic(err)
fmt.Printf("Error storing code: %v\n", err)
exitCode = 1
return
}
fmt.Printf("Stored code with checksum: %X\n", checksum)

vm.Cleanup()
fmt.Println("finished")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/CosmWasm/wasmvm/v2

go 1.21
go 1.23

require (
github.com/google/btree v1.0.0
Expand Down
2 changes: 1 addition & 1 deletion ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type AccountInfo struct {
ChannelID string `json:"channel_id"`
}

// We just check if an error is returned or not
// We just check if an error is returned or not.
type AcknowledgeDispatch struct {
Err string `json:"error"`
}
Expand Down
22 changes: 8 additions & 14 deletions internal/api/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func cGet(ptr *C.db_t, gasMeter *C.gas_meter_t, usedGas *cu64, key C.U8SliceView
return C.GoError_BadArgument
}
// errOut is unused and we don't check `is_none` because of https://github.com/CosmWasm/wasmvm/issues/536
if !(*val).is_none {
if !val.is_none {
panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.")
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func cScan(ptr *C.db_t, gasMeter *C.gas_meter_t, usedGas *cu64, start C.U8SliceV
// we received an invalid pointer
return C.GoError_BadArgument
}
if !(*errOut).is_none {
if !errOut.is_none {
panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.")
}

Expand Down Expand Up @@ -272,19 +272,13 @@ func cScan(ptr *C.db_t, gasMeter *C.gas_meter_t, usedGas *cu64, start C.U8SliceV

//export cNext
func cNext(ref C.IteratorReference, gasMeter *C.gas_meter_t, usedGas *cu64, key *C.UnmanagedVector, val *C.UnmanagedVector, errOut *C.UnmanagedVector) (ret C.GoError) {
// typical usage of iterator
// for ; itr.Valid(); itr.Next() {
// k, v := itr.Key(); itr.Value()
// ...
// }

defer recoverPanic(&ret)
if ref.call_id == 0 || gasMeter == nil || usedGas == nil || key == nil || val == nil || errOut == nil {
// we received an invalid pointer
return C.GoError_BadArgument
}
// errOut is unused and we don't check `is_none` because of https://github.com/CosmWasm/wasmvm/issues/536
if !(*key).is_none || !(*val).is_none {
if !key.is_none || !val.is_none {
panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.")
}

Expand Down Expand Up @@ -336,7 +330,7 @@ func nextPart(ref C.IteratorReference, gasMeter *C.gas_meter_t, usedGas *cu64, o
return C.GoError_BadArgument
}
// errOut is unused and we don't check `is_none` because of https://github.com/CosmWasm/wasmvm/issues/536
if !(*output).is_none {
if !output.is_none {
panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.")
}

Expand Down Expand Up @@ -384,7 +378,7 @@ func cHumanizeAddress(ptr *C.api_t, src C.U8SliceView, dest *C.UnmanagedVector,
if dest == nil || errOut == nil {
return C.GoError_BadArgument
}
if !(*dest).is_none || !(*errOut).is_none {
if !dest.is_none || !errOut.is_none {
panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.")
}

Expand Down Expand Up @@ -412,7 +406,7 @@ func cCanonicalizeAddress(ptr *C.api_t, src C.U8SliceView, dest *C.UnmanagedVect
if dest == nil || errOut == nil {
return C.GoError_BadArgument
}
if !(*dest).is_none || !(*errOut).is_none {
if !dest.is_none || !errOut.is_none {
panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.")
}

Expand All @@ -439,7 +433,7 @@ func cValidateAddress(ptr *C.api_t, src C.U8SliceView, errOut *C.UnmanagedVector
if errOut == nil {
return C.GoError_BadArgument
}
if !(*errOut).is_none {
if !errOut.is_none {
panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.")
}

Expand Down Expand Up @@ -479,7 +473,7 @@ func cQueryExternal(ptr *C.querier_t, gasLimit cu64, usedGas *cu64, request C.U8
// we received an invalid pointer
return C.GoError_BadArgument
}
if !(*result).is_none || !(*errOut).is_none {
if !result.is_none || !errOut.is_none {
panic("Got a non-none UnmanagedVector we're about to override. This is a bug because someone has to drop the old one.")
}

Expand Down
13 changes: 9 additions & 4 deletions internal/api/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package api
import (
"fmt"
"math"
"os"
"sync"

"github.com/CosmWasm/wasmvm/v2/types"
)

// frame stores all Iterators for one contract call
// frame stores all Iterators for one contract call.
type frame []types.Iterator

// iteratorFrames contains one frame for each contract call, indexed by contract call ID.
Expand All @@ -17,7 +18,7 @@ var (
iteratorFramesMutex sync.Mutex
)

// this is a global counter for creating call IDs
// this is a global counter for creating call IDs.
var (
latestCallID uint64
latestCallIDMutex sync.Mutex
Expand All @@ -44,13 +45,17 @@ func removeFrame(callID uint64) frame {
return remove
}

// endCall is called at the end of a contract call to remove one item the iteratorFrames
// endCall is called at the end of a contract call to remove one item the iteratorFrames.
func endCall(callID uint64) {
// we pull removeFrame in another function so we don't hold the mutex while cleaning up the removed frame
remove := removeFrame(callID)
// free all iterators in the frame when we release it
for _, iter := range remove {
iter.Close()
if err := iter.Close(); err != nil {
// In this cleanup code, we can't do much with the error
// Log it to stderr since that's better than silently ignoring it
fmt.Fprintf(os.Stderr, "failed to close iterator: %v\n", err)
}
}
}

Expand Down
Loading