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

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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.22.12
- 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.22.12
- 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.22.12
- image: cimg/go:1.23.4
steps:
- checkout
- run:
Expand All @@ -223,7 +223,7 @@ jobs:

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

format-scripts:
docker:
- image: cimg/go:1.22.12
- image: cimg/go:1.23.4
steps:
- run:
name: Install shfmt
Expand Down Expand Up @@ -299,7 +299,7 @@ jobs:
# Test the Go project and run benchmarks
wasmvm_test:
docker:
- image: cimg/go:1.22.12
- image: cimg/go:1.23.4
environment:
GORACE: "halt_on_error=1"
BUILD_VERSION: $(echo ${CIRCLE_SHA1} | cut -c 1-10)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.23.4"
go-version: "1.24"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
Expand Down
103 changes: 84 additions & 19 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,95 @@ version: "2"

run:
tests: true
timeout: 5m

linters:
# Enable specific linters
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- misspell
- testifylint
- thelper
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
- copyloopvar # Detect copy loops
- errcheck # Detect unchecked errors
- govet # Reports suspicious constructs
- ineffassign # Detect unused assignments
- staticcheck # Go static analysis
- 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
- maintidx
- bodyclose # Check HTTP response bodies are closed
- goconst # Find repeated strings that could be constants
- gocyclo # Check function complexity
- gocognit # Check cognitive complexity
- whitespace # Check trailing whitespace
- thelper # Detect test helpers not using t.Helper()
- usetesting # Detect incorrect usage of testing package
- tparallel # Detect incorrect usage of t.Parallel()

settings:
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- dupSubExpr
- paramTypeCombine
- dupImport
- hugeParam
- rangeValCopy
- ptrToRefParam

gocyclo:
min-complexity: 15
gocognit:
min-complexity: 20
dupl:
threshold: 100
goconst:
min-len: 3
min-occurrences: 3
revive:
enable-all-rules: true

rules:
# https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#var-naming
- name: var-naming
severity: warning
disabled: true
exclude: [""]
arguments:
- ["ID"] # AllowList
- ["VM"] # DenyList
- - upperCaseConst: true # Extra parameter (upperCaseConst|skipPackageNameChecks)
- name: line-length-limit
severity: warning
disabled: true
exclude: [""]
arguments: [80]
- name: add-constant
disabled: true
- name: exported
disabled: true
- name: function-length
disabled: true
- name: nested-structs
disabled: true
- name: flag-parameter
disabled: true
- name: max-public-structs
disabled: false
severity: warning
arguments: [100]







issues:
max-issues-per-linter: 0
Expand All @@ -46,12 +116,7 @@ formatters:
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
- alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
# Enable custom order of sections.
# If `true`, make the section order the same as the order of `sections`.
# Default: false
custom-order: true
# Drops lexical ordering for custom sections.
# Default: false
no-lex-order: true
exclusions:
# Skip generated files.
Expand Down
156 changes: 129 additions & 27 deletions cmd/demo/main.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,158 @@
// Package main provides a demo application showcasing the usage of the wasmvm library.
package main

import (
"errors"
"fmt"
"math"
"os"
"path/filepath"
"strings"

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

// Constants for VM configuration
const (
PRINT_DEBUG = true
MEMORY_LIMIT = 32 // MiB
CACHE_SIZE = 100 // MiB
// PrintDebug enables debug printing when true
PrintDebug = true
// MemoryLimit defines the memory limit in MiB
MemoryLimit = 32
// CacheSize defines the cache size in MiB
CacheSize = 100
// DefaultDirMode is the default directory permission mode
DefaultDirMode = 0o755
)

var SUPPORTED_CAPABILITIES = []string{"staking"}
// Constants for exit codes
const (
ExitSuccess = 0
ExitError = 1
)

// This is just a demo to ensure we can compile a static go binary
func main() {
file := os.Args[1]
// Constants for array indices and lengths
const (
MinArgsLength = 2
FilePathIndex = 1
)

if file == "version" {
libwasmvmVersion, err := wasmvm.LibwasmvmVersion()
if err != nil {
panic(err)
}
fmt.Printf("libwasmvm: %s\n", libwasmvmVersion)
return
}
// SupportedCapabilities defines the list of supported staking capabilities.
var SupportedCapabilities = []string{"staking"}

// exitCode tracks the code that the program will exit with.
var exitCode = 0

fmt.Printf("Running %s...\n", file)
bz, err := os.ReadFile(file)
// printError prints an error message, sets the exit code, and returns the write error (if any)
func printError(format string, args ...any) error {
_, err := fmt.Fprintf(os.Stderr, format, args...)
exitCode = ExitError
return err // Return potential write error
}

// printInfo prints an informational message and returns the write error (if any)
func printInfo(format string, args ...any) error {
_, err := fmt.Fprintf(os.Stdout, format, args...)
return err // Return potential write error
}

// handleVersion prints the libwasmvm version
func handleVersion() error {
libwasmvmVersion, err := wasmvm.LibwasmvmVersion()
if err != nil {
panic(err)
return printError("Error getting libwasmvm version: %v\n", err) // Propagate error
}
return printInfo("libwasmvm: %s\n", libwasmvmVersion) // Propagate error
}

// validateFilePath checks if the file path is valid
func validateFilePath(file string) (string, error) {
cleanPath := filepath.Clean(file)
if filepath.IsAbs(cleanPath) || strings.Contains(cleanPath, "..") {
err := errors.New("invalid file path")
return "", printError("Error: %v\n", err) // Propagate error
}
fmt.Println("Loaded!")
return cleanPath, nil
}

err = os.MkdirAll("tmp", 0o755)
// setupVM creates and initializes the VM
func setupVM() (*wasmvm.VM, error) {
if err := os.MkdirAll("tmp", DefaultDirMode); err != nil {
return nil, printError("Error creating tmp directory: %v\n", err) // Propagate error
}

vm, err := wasmvm.NewVM("tmp", SupportedCapabilities, MemoryLimit, PrintDebug, CacheSize)
if err != nil {
panic(err)
return nil, printError("Error creating VM: %v\n", err) // Propagate error
}
vm, err := wasmvm.NewVM("tmp", SUPPORTED_CAPABILITIES, MEMORY_LIMIT, PRINT_DEBUG, CACHE_SIZE)
return vm, nil
}

// loadAndStoreWasm loads wasm bytecode from a file and stores it in the VM
func loadAndStoreWasm(vm *wasmvm.VM, filePath string) error {
// Use the validated filePath (cleanPath from main)
bz, err := os.ReadFile(filePath) //nolint:gosec // Path validated before calling this function
if err != nil {
panic(err)
return printError("Error reading file: %v\n", err) // Propagate error
}
if err := printInfo("Loaded!\n"); err != nil {
return err // Handle printInfo error
}

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

vm.Cleanup()
fmt.Println("finished")
func run() error {
if len(os.Args) < MinArgsLength {
return printError("Usage: %s <path-to-wasm-file>\n", os.Args[0])
}

file := os.Args[FilePathIndex]

if file == "version" {
return handleVersion()
}

if err := printInfo("Running %s...\n", file); err != nil {
return err
}

cleanPath, err := validateFilePath(file)
if err != nil {
return err
}

vm, err := setupVM()
if err != nil {
return err
}
defer vm.Cleanup()

if err := loadAndStoreWasm(vm, cleanPath); err != nil {
return err
}

return printInfo("finished\n")
}

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

// Run the main application logic
if err := run(); err != nil {
// If run() returned an error not already printed by printError,
// print it now. This handles potential fmt.Fprintf errors.
if exitCode == ExitSuccess { // Check if printError was already called
_, _ = fmt.Fprintf(os.Stderr, "Unhandled error: %v\n", err)
exitCode = ExitError
}
// No return needed here, defer will handle exit
}
}
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.22
go 1.24

require (
github.com/google/btree v1.0.0
Expand Down
Loading