Skip to content

Commit

Permalink
style: update golangci config and fix lint errors (#1384)
Browse files Browse the repository at this point in the history
* style: update golangci config and fix lint errors

* include types package and fix lint errors

* include data module and fix lint errors

* include ecocredit module and fix lint errors

* clean up configuration and update workflow

* clean up configuration and update workflow

* clean up configuration and update workflow

* clean up configuration and update workflow

* clean up configuration and update workflow

* clean up configuration and update workflow

* clean up configuration and update workflow

* clean up configuration and update workflow

* update format make command and apply fixes

* update format make command and make tidy

* try without gofmt and only goimports

* try without gofmt and goimports

* udpate changelog

* update workflow and add todo comments
  • Loading branch information
ryanchristo authored Aug 22, 2022
1 parent 971b3cd commit 256e45e
Show file tree
Hide file tree
Showing 183 changed files with 1,377 additions and 1,312 deletions.
65 changes: 53 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Lint
# **Why we have it**: Ensures all go files and proto files are
# properly formatted according to lint configuration files.
#
# **What does it impact**: Code cleanliness.
# **What does it impact**: Code quality.

on:
pull_request:
Expand All @@ -22,54 +22,95 @@ concurrency:
jobs:
golangci:
runs-on: ubuntu-latest
strategy:
matrix:
module: ["app", "types", "x/data", "x/ecocredit"]
steps:
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
id: git-diff-app
with:
PATTERNS: |
**/**.go
**/go.mod
**/go.sum
app/**/**.go
go.mod
go.sum
if: matrix.module == 'app'
- uses: technote-space/get-diff-action@v6
id: git-diff-types
with:
PATTERNS: |
types/**/**.go
types/go.mod
types/go.sum
if: matrix.module == 'types'
- uses: technote-space/get-diff-action@v6
id: git-diff-data
with:
PATTERNS: |
x/data/**/**.go
x/data/go.mod
x/data/go.sum
if: matrix.module == 'x/data'
- uses: technote-space/get-diff-action@v6
id: git-diff-ecocredit
with:
PATTERNS: |
x/ecocredit/**/**.go
x/ecocredit/go.mod
x/ecocredit/go.sum
if: matrix.module == 'x/ecocredit'
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
if: env.GIT_DIFF
- uses: golangci/golangci-lint-action@v3
with:
args: --timeout 5m --verbose
only-new-issues: true
if: env.GIT_DIFF
working-directory: "."
if: steps.git-diff-app.outputs.diff
- uses: golangci/golangci-lint-action@v3
with:
working-directory: "types"
if: steps.git-diff-types.outputs.diff
- uses: golangci/golangci-lint-action@v3
with:
working-directory: "x/data"
if: steps.git-diff-data.outputs.diff
- uses: golangci/golangci-lint-action@v3
with:
working-directory: "x/ecocredit"
if: steps.git-diff-ecocredit.outputs.diff

buf-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
id: git_diff
id: git-diff-proto
with:
PATTERNS: |
**/**.proto
- uses: bufbuild/buf-setup-action@v1
if: env.GIT_DIFF
if: steps.git-diff-proto.outputs.diff
- uses: bufbuild/buf-lint-action@v1
with:
input: 'proto'
if: env.GIT_DIFF
if: steps.git-diff-proto.outputs.diff

protolint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v6
id: git-diff-proto
with:
PATTERNS: |
**/**.proto
- uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
if: env.GIT_DIFF
if: steps.git-diff-proto.outputs.diff
- name: Run protolint
run: |
go install github.com/yoheimuta/protolint/cmd/protolint@latest
protolint .
if: env.GIT_DIFF
if: steps.git-diff-proto.outputs.diff
49 changes: 11 additions & 38 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
run:
tests: false
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
timeout: 5m

linters:
disable-all: true
Expand All @@ -11,61 +9,36 @@ linters:
- depguard
- dogsled
- errcheck
- exportloopref
- goconst
- gocritic
- gofmt
- goimports
- golint
# TODO: investigate why golangci-lint-action is producing an error when latest golangci-lint does not locally
# - gofmt
# - goimports
- gosec
- gosimple
- govet
- ineffassign
- maligned
- misspell
- nakedret
- nolintlint
- prealloc
- scopelint
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- unparam
- misspell
- unused
# TODO: consider enabling and resolving
# - wsl
- nolintlint

issues:
exclude-rules:
- text: "Use of weak random number generator"
- text: "G404: Use of weak random number generator"
linters:
- gosec
- text: "comment on exported var"
linters:
- golint
- text: "don't use an underscore in package name"
linters:
- golint
- text: "ST1003:"
linters:
- stylecheck
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
# https://github.com/dominikh/go-tools/issues/389
- text: "ST1016:"
linters:
- stylecheck
max-issues-per-linter: 10000
max-same-issues: 10000


linters-settings:
dogsled:
max-blank-identifiers: 3
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
nolintlint:
allow-unused: false
allow-leading-space: true
require-explanation: false
require-specific: false
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1362](https://github.com/regen-network/regen-ledger/pull/1362) Update `ClassIssuer` state validation checks
- [#1362](https://github.com/regen-network/regen-ledger/pull/1362) Update `CreditType` state validation checks
- [#1362](https://github.com/regen-network/regen-ledger/pull/1362) Update `Project` state validation checks
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `DateCriteria.ToApi` to `DateCriteria.ToAPI`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `QueryProjectsByReferenceIdCmd` to `QueryProjectsByReferenceIDCmd`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `FlagReferenceId` to `FlagReferenceID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `MaxReferenceIdLength` to `MaxReferenceIDLength`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `RegexClassId` to `RegexClassID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `RegexProjectId` to `RegexProjectID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `FormatClassId` to `FormatClassID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `FormatProjectId` to `FormatProjectID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `ValidateClassId` to `ValidateClassID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `ValidateProjectId` to `ValidateProjectID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `GetClassIDFromProjectId` to `GetClassIDFromProjectID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `GetClassIdFromBatchDenom` to `GetClassIDFromBatchDenom`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `GetProjectIdFromBatchDenom` to `GetProjectIDFromBatchDenom`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `GetCreditTypeAbbrevFromClassId` to `GetCreditTypeAbbrevFromClassID`
- [#1384](https://github.com/regen-network/regen-ledger/pull/1384) Renamed `BasketSupplyInvariant` to `SupplyInvariant`

#### Removed

Expand Down
21 changes: 13 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ generate:
###############################################################################

lint:
golangci-lint run --out-format=tab
protolint .
@echo "Linting all go modules..."
@find . -name 'go.mod' -type f -execdir golangci-lint run --out-format=tab \;

lint-fix:
golangci-lint run --fix --out-format=tab --issues-exit-code=0
protolint -fix .
lint-fix: format
@echo "Attempting to fix lint errors in all go modules..."
@find . -name 'go.mod' -type f -execdir golangci-lint run --fix --out-format=tab --issues-exit-code=0 \;

format_filter = -name '*.go' -type f \
-not -path '*.git*' \
Expand All @@ -221,10 +221,15 @@ format_filter = -name '*.go' -type f \
-not -name '*.cosmos_orm.go' \
-not -name 'statik.go'

format_local = \
github.com/tendermint/tendermint \
github.com/cosmos/cosmos-sdk \
github.com/cosmos/ibc-go \
github.com/regen-network/regen-ledger

format:
@find . $(format_filter) | xargs gofmt -w -s
@find . $(format_filter) | xargs misspell -w
@find . $(format_filter) | xargs goimports -w
@echo "Formatting imports in all go modules..."
@find . $(format_filter) | xargs goimports -w -local $(subst $(whitespace),$(comma),$(format_local))

.PHONY: lint lint-fix format

Expand Down
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
dbm "github.com/tendermint/tm-db"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -63,6 +64,9 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/cosmos-sdk/x/mint"
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
Expand All @@ -80,10 +84,6 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/x/group"
groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper"
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"

"github.com/cosmos/ibc-go/v5/modules/apps/transfer"
ibctransferkeeper "github.com/cosmos/ibc-go/v5/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
Expand Down
3 changes: 2 additions & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

"github.com/tendermint/tendermint/libs/log"
)

func TestSimAppExportAndBlockedAddrs(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion app/client/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/spf13/cast"
"github.com/spf13/cobra"

dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand All @@ -35,7 +37,6 @@ import (
tmcfg "github.com/tendermint/tendermint/config"
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

"github.com/regen-network/regen-ledger/v4/app"
)
Expand Down
5 changes: 2 additions & 3 deletions app/client/cli/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,9 @@ func calculateIP(ip string, i int) (string, error) {
}

func writeFile(name string, dir string, contents []byte) error {
writePath := filepath.Join(dir)
file := filepath.Join(writePath, name)
file := filepath.Join(dir, name)

err := tmos.EnsureDir(writePath, 0755)
err := tmos.EnsureDir(dir, 0755)
if err != nil {
return err
}
Expand Down
11 changes: 7 additions & 4 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import (
"os"
"testing"

ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host"
"github.com/regen-network/regen-ledger/x/ecocredit"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/simapp"
Expand All @@ -34,6 +32,11 @@ import (
"github.com/cosmos/cosmos-sdk/x/simulation"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

ibctransfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
ibchost "github.com/cosmos/ibc-go/v5/modules/core/24-host"

"github.com/regen-network/regen-ledger/x/ecocredit"
)

// Get flags every time the simulator is run
Expand Down
3 changes: 2 additions & 1 deletion app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"time"

"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"

abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
Expand Down
6 changes: 4 additions & 2 deletions app/testsuite/network_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import (
"fmt"
"time"

dbm "github.com/tendermint/tm-db"

tmrand "github.com/tendermint/tendermint/libs/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
tmrand "github.com/tendermint/tendermint/libs/rand"
dbm "github.com/tendermint/tm-db"

"github.com/regen-network/regen-ledger/types/testutil/network"
"github.com/regen-network/regen-ledger/v4/app"
Expand Down
Loading

0 comments on commit 256e45e

Please sign in to comment.