Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- [#3977](https://github.com/ignite/cli/pull/3977) Add `chain lint` command to lint the chain's codebase using `golangci-lint`

### Changes

- [#3959](https://github.com/ignite/cli/pull/3959) Remove app name prefix from the `.gitignore` file
Expand Down
1 change: 1 addition & 0 deletions ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ chain.
NewChainFaucet(),
NewChainSimulate(),
NewChainDebug(),
NewChainLint(),
)

return c
Expand Down
37 changes: 37 additions & 0 deletions ignite/cmd/chain_lint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ignitecmd

import (
"github.com/ignite/cli/v28/ignite/pkg/cliui"
"github.com/ignite/cli/v28/ignite/services/chain"
"github.com/spf13/cobra"
)

// NewChainLint returns a lint command to build a blockchain app.
func NewChainLint() *cobra.Command {
c := &cobra.Command{
Use: "lint",
Short: "Lint codebase using golangci-lint",
Long: "The lint command runs the golangci-lint tool to lint the codebase.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
session := cliui.New(
cliui.StartSpinnerWithText("Linting..."),
)
defer session.End()

chainOption := []chain.Option{
chain.WithOutputer(session),
chain.CollectEvents(session.EventBus()),
}

c, err := newChainWithHomeFlags(cmd, chainOption...)
if err != nil {
return err
}

return c.Lint(cmd.Context())
},
}

return c
}
19 changes: 19 additions & 0 deletions ignite/services/chain/lint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package chain

import (
"context"
"fmt"

"github.com/ignite/cli/v28/ignite/pkg/cmdrunner/exec"
)

var golangCiLintVersion = "latest"

// Lint runs the linting process for the chain.
// It uses golangci-lint to lint the chain's codebase.
func (c *Chain) Lint(ctx context.Context) error {
if err := exec.Exec(ctx, []string{"go", "install", fmt.Sprintf("github.com/golangci/golangci-lint/cmd/golangci-lint@%s", golangCiLintVersion)}); err != nil {
return fmt.Errorf("failed to install golangci-lint: %w", err)
}
return exec.Exec(ctx, []string{"golangci-lint", "run", "./...", "--out-format=tab"}, exec.IncludeStdLogsToError())
}
7 changes: 7 additions & 0 deletions ignite/services/chain/lint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package chain_test

import "testing"

func TestChainLint(t *testing.T) {

}
2 changes: 1 addition & 1 deletion ignite/templates/app/files/app/ibc.go.plush
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" // nolint:staticcheck // Deprecated: params key table is needed for params migration
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down