Skip to content
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

feat: goimports-reviser script #282

Closed
wants to merge 2 commits into from
Closed
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: 3 additions & 1 deletion pkg/appgateserver/config/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

var (
codespace = "appgate_config"
Expand Down
4 changes: 3 additions & 1 deletion pkg/appgateserver/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package appgateserver

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

var (
codespace = "appgateserver"
Expand Down
4 changes: 3 additions & 1 deletion pkg/client/keyring/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package keyring

import "cosmossdk.io/errors"
import (
"cosmossdk.io/errors"
)

var (
// ErrEmptySigningKeyName represents an error which indicates that the
Expand Down
4 changes: 3 additions & 1 deletion pkg/client/tx/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tx

import errorsmod "cosmossdk.io/errors"
import (
errorsmod "cosmossdk.io/errors"
)

var (
// ErrInvalidMsg signifies that there was an issue in validating the
Expand Down
4 changes: 3 additions & 1 deletion pkg/observable/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package observable

import errorsmod "cosmossdk.io/errors"
import (
errorsmod "cosmossdk.io/errors"
)

var (
ErrObserverClosed = errorsmod.Register(codespace, 1, "observer is closed")
Expand Down
4 changes: 3 additions & 1 deletion pkg/observable/interface.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package observable

import "context"
import (
"context"
)

// NOTE: We explicitly decided to write a small and custom notifications package
// to keep logic simple and minimal. If the needs & requirements of this library ever
Expand Down
4 changes: 3 additions & 1 deletion pkg/polylog/context.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package polylog

import "context"
import (
"context"
)

// CtxKey is the key used to store the polylog.Logger in a context.Context. This
// is **independant** of any logger-implementation-specific context key that may
Expand Down
4 changes: 3 additions & 1 deletion pkg/relayer/config/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

var (
codespace = "relayminer_config"
Expand Down
4 changes: 3 additions & 1 deletion pkg/relayer/miner/gen/template.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import "text/template"
import (
"text/template"
)

var (
relayFixtureLineFmt = "\t\t\"%x\","
Expand Down
4 changes: 3 additions & 1 deletion pkg/relayer/protocol/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package protocol

import errorsmod "cosmossdk.io/errors"
import (
errorsmod "cosmossdk.io/errors"
)

var (
ErrDifficulty = errorsmod.New(codespace, 1, "difficulty error")
Expand Down
4 changes: 3 additions & 1 deletion pkg/relayer/session/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package session

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

var (
codespace = "relayer_session"
Expand Down
4 changes: 3 additions & 1 deletion pkg/sdk/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sdk

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

var (
codespace = "poktrollsdk"
Expand Down
4 changes: 3 additions & 1 deletion pkg/sdk/urls.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package sdk

import "fmt"
import (
"fmt"
)

// HostToWebsocketURL converts the provided host into a websocket URL that can
// be used to subscribe to onchain events and query the chain via a client
Expand Down
4 changes: 3 additions & 1 deletion pkg/signer/simple_signer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package signer

import "github.com/cosmos/cosmos-sdk/crypto/keyring"
import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
)

var _ Signer = (*SimpleSigner)(nil)

Expand Down
4 changes: 3 additions & 1 deletion testutil/testerrors/require.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package testerrors

import errorsmod "cosmossdk.io/errors"
import (
errorsmod "cosmossdk.io/errors"
)

var (
// ErrAsync is returned when a test assertion fails in a goroutine other than
Expand Down
4 changes: 3 additions & 1 deletion testutil/testkeyring/gen_accounts/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

package main

import "text/template"
import (
"text/template"
)

var (
preGeneratedAccountLineFmt = "\t\tmustParsePreGeneratedAccount(%q),"
Expand Down
4 changes: 3 additions & 1 deletion testutil/yaml/yaml.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package yaml

import "strings"
import (
"strings"
)

// YAML is indentation sensitive, so we need to remove the extra indentation from the test cases and make sure
// it is space-indented instead of tab-indented, otherwise the YAML parser will fail
Expand Down
34 changes: 34 additions & 0 deletions tools/scripts/goimports-revisor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

FLAGS=(
-rm-unused
-use-cache
-imports-order "std,general,company,project,blanked,dotted"
-project-name "github.com/pokt-network/poktrolld"
)

# Define a function to check for the exclusion comment and run goimports-reviser
process_file() {
local file=$1
if ! grep -q "//go:build ignore" "$file"; then
echo "Processing $file"
goimports-reviser "${FLAGS[@]}" "$file"
fi
}

export -f process_file

# Find all .go files, excluding specified patterns, and process them
find . -type f -name '*.go' \
! -path "./vendors/*" \
! -path "./ts-client/*" \
! -path "./.git/*" \
! -path "./.github/*" \
! -path "./bin/*" \
! -path "./docs/*" \
! -path "./localnet/*" \
! -path "./proto/*" \
! -path "./tools/*" \
! -name "*mock.go" \
! -name "*pb.go" \
-exec bash -c 'process_file "$0"' {} \;
39 changes: 39 additions & 0 deletions tools/scripts/restore-scaffold-lines.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

# The line to be restored
RESTORE_LINE="// this line is used by starport scaffolding # root/moduleImport"

# The pattern after which the line should be restored (modify this as needed)
PATTERN="import ("

# Function to restore the line in a file
restore_line() {
local file=$1
local temp_file=$(mktemp)

# Flag to indicate if the line has been restored
local restored=0

# Read the file line by line
while IFS= read -r line; do
echo "$line" >> "$temp_file"
# Check if the line matches the pattern
if [[ $line == *"$PATTERN"* ]]; then
# Add the RESTORE_LINE after the pattern
echo "$RESTORE_LINE" >> "$temp_file"
restored=1
fi
done < "$file"

# Replace the original file with the temp file
mv "$temp_file" "$file"
}

# Process each file changed in the git diff
git diff --name-only | while IFS= read -r file; do
# Check if the file is a .go file and the specific line was deleted
if [[ $file == *.go ]] && git diff "$file" | grep -q "^\-.*$RESTORE_LINE"; then
echo "Restoring line in $file"
restore_line "$file"
fi
done
4 changes: 3 additions & 1 deletion x/application/client/config/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

var (
codespace = "applicationconfig"
Expand Down
4 changes: 3 additions & 1 deletion x/application/types/key_application.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "encoding/binary"
import (
"encoding/binary"
)

var _ binary.ByteOrder

Expand Down
4 changes: 3 additions & 1 deletion x/gateway/types/key_gateway.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "encoding/binary"
import (
"encoding/binary"
)

var _ binary.ByteOrder

Expand Down
4 changes: 3 additions & 1 deletion x/service/types/relay.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "crypto/sha256"
import (
"crypto/sha256"
)

// getSignableBytes returns the bytes resulting from marshaling the relay request
// A value receiver is used to avoid overwriting any pre-existing signature
Expand Down
4 changes: 3 additions & 1 deletion x/supplier/client/config/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import sdkerrors "cosmossdk.io/errors"
import (
sdkerrors "cosmossdk.io/errors"
)

var (
codespace = "supplierconfig"
Expand Down
4 changes: 3 additions & 1 deletion x/supplier/types/key_proof.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "encoding/binary"
import (
"encoding/binary"
)

var _ binary.ByteOrder

Expand Down
4 changes: 3 additions & 1 deletion x/supplier/types/key_supplier.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import "encoding/binary"
import (
"encoding/binary"
)

var _ binary.ByteOrder

Expand Down