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 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
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
82 changes: 68 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,81 @@ 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
- 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()

linters-settings:
gci:
# Section configuration to compare against.
# Section names are case-insensitive and may contain parameters in ().
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
# If `custom-order` is `true`, it follows the order of `sections` option.
# Default: ["standard", "default"]
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/cosmos/cosmos-sdk) # Custom section: groups all imports with the specified Prefix.
- prefix(github.com/cosmos/ibc-go)
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
- 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.
# Skip generated files.
# Default: true
skip-generated: false
# 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
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

Expand Down
67 changes: 53 additions & 14 deletions cmd/demo/main.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,95 @@
// Package main provides a demo application showcasing the usage of the wasmvm library.
package main

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")
}
Loading
Loading