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

chore: add gci/dogsled/gosec/errcheckl linters #105

Merged
merged 10 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
go-version: 1.19
- uses: golangci/golangci-lint-action@v3
with:
version: v1.50.0
version: v1.54.2

shellcheck:
runs-on: ubuntu-latest
Expand Down
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@ linters:
- unparam
- stylecheck
- gocyclo
- gci
- dogsled
- gosec
- errcheck

linters-settings:
stylecheck:
checks: ["all", "-ST1003"]
gocyclo:
min-complexity: 15
gci:
custom-order: true
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/functionx/fx-core)
errcheck:
check-type-assertions: false
check-blank: false
26 changes: 16 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,23 @@ run-local: install
### Linting ###
###############################################################################

lint: format
@echo "--> Running linter"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
golangci-lint run -v --go=1.19 --out-format=tab

format: format-goimports
golangci-lint run --fix --out-format=tab --issues-exit-code=0
golangci_lint_cmd=golangci-lint
golangci_version=v1.54.2

lint-install:
@echo "--> Installing golangci-lint $(golangci_version)"
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)

lint:
echo "--> Running linter"
$(MAKE) lint-install
$(golangci_lint_cmd) run --build-tags=$(GO_BUILD) --fix --out-format=tab
@if [ $$(find . -name '*.go' -type f | xargs grep 'nolint' | wc -l) -ne 32 ]; then \
echo "--> increase or decrease nolint, please recheck them"; \
echo "--> list nolint: \`find . -name '*.go' -type f | xargs grep 'nolint'\`"; exit 1;\
fi

format-goimports:
@go install github.com/incu6us/goimports-reviser/v3@latest
@find . -name '*.go' -type f -not -path './build*' -not -name 'statik.go' -not -name '*.pb.go' -not -name '*.pb.gw.go' -exec goimports-reviser -use-cache -rm-unused {} \;
format: lint

lint-shell:
# install shellcheck > https://github.com/koalaman/shellcheck
Expand Down
3 changes: 2 additions & 1 deletion client/cli/block_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func ParseBlockResults(cdc codec.JSONCodec, blockResults *coretypes.ResultBlockR
txsResults = append(txsResults, TxResultToMap(cdc, txResult))
}
var validatorUpdates []json.RawMessage
for _, valUp := range blockResults.ValidatorUpdates {
for i := 0; i < len(blockResults.ValidatorUpdates); i++ {
valUp := blockResults.ValidatorUpdates[i]
valUpData, err := cdc.MarshalJSON(&valUp)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/cli/keys/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ HbP+c6JmeJy9JXe2rbbF1QtCX1gLqGcDQPBXiCtFvP7/8wTZtVOPj8vREzhZ9ElO
t.Cleanup(cleanupKeys(t, kb, "keyname1"))

keyfile := filepath.Join(kbHome, "key.asc")
require.NoError(t, os.WriteFile(keyfile, []byte(armoredKey), 0o644))
require.NoError(t, os.WriteFile(keyfile, []byte(armoredKey), 0o600))

defer func() {
_ = os.RemoveAll(kbHome)
Expand Down
4 changes: 2 additions & 2 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func Test_updateCfgCmd(t *testing.T) {
for _, entry := range publicDir {
appConfig, err := os.ReadFile(fmt.Sprintf("../public/%s/app.toml", entry.Name()))
assert.NoError(t, err)
assert.NoError(t, os.WriteFile(filepath.Join(tempDir, "config/app.toml"), appConfig, 0o700))
assert.NoError(t, os.WriteFile(filepath.Join(tempDir, "config/app.toml"), appConfig, 0o600))

tmConfig, err := os.ReadFile(fmt.Sprintf("../public/%s/config.toml", entry.Name()))
assert.NoError(t, err)
assert.NoError(t, os.WriteFile(filepath.Join(tempDir, "config/config.toml"), tmConfig, 0o700))
assert.NoError(t, os.WriteFile(filepath.Join(tempDir, "config/config.toml"), tmConfig, 0o600))

rootCmd.SetArgs([]string{"config", "update"})
assert.NoError(t, rootCmd.Execute())
Expand Down
4 changes: 2 additions & 2 deletions server/config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
const (
// BypassMinFeeMsgTypesKey defines the configuration key for the
// BypassMinFeeMsgTypes value.
BypassMinFeeMsgTypesKey = "bypass-min-fee.msg-types"
BypassMinFeeMsgTypesKey = "bypass-min-fee.msg-types" //nolint:gosec
Fixed Show fixed Hide fixed

BypassMinFeeMsgMaxGasUsageKey = "bypass-min-fee.msg-max-gas-usage"
BypassMinFeeMsgMaxGasUsageKey = "bypass-min-fee.msg-max-gas-usage" //nolint:gosec
Fixed Show fixed Hide fixed
)

const (
Expand Down
22 changes: 15 additions & 7 deletions x/crosschain/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func InitGenesis(ctx sdk.Context, k Keeper, state *types.GenesisState) {
k.CommonSetOracleTotalPower(ctx)

latestOracleSetNonce := uint64(0)
for _, set := range state.OracleSets {
for i := 0; i < len(state.OracleSets); i++ {
set := state.OracleSets[i]
// 0x15 0x29
if set.Nonce > latestOracleSetNonce {
latestOracleSetNonce = set.Nonce
Expand All @@ -56,15 +57,17 @@ func InitGenesis(ctx sdk.Context, k Keeper, state *types.GenesisState) {
// 0x26 0x27
k.AddBridgeToken(ctx, bridgeToken.Token, bridgeToken.Denom)
}
for _, confirm := range state.BatchConfirms {
for i := 0; i < len(state.BatchConfirms); i++ {
confirm := state.BatchConfirms[i]
for _, oracle := range state.Oracles {
if confirm.BridgerAddress == oracle.BridgerAddress {
// 0x22
k.SetBatchConfirm(ctx, oracle.GetOracle(), &confirm)
}
}
}
for _, confirm := range state.OracleSetConfirms {
for i := 0; i < len(state.OracleSetConfirms); i++ {
confirm := state.OracleSetConfirms[i]
for _, oracle := range state.Oracles {
if confirm.BridgerAddress == oracle.BridgerAddress {
// 0x16
Expand All @@ -73,22 +76,25 @@ func InitGenesis(ctx sdk.Context, k Keeper, state *types.GenesisState) {
}
}

for _, transfer := range state.UnbatchedTransfers {
for i := 0; i < len(state.UnbatchedTransfers); i++ {
transfer := state.UnbatchedTransfers[i]
// 0x18
if err := k.AddUnbatchedTx(ctx, &transfer); err != nil {
panic(err)
}
}

for _, batch := range state.Batches {
for i := 0; i < len(state.Batches); i++ {
batch := state.Batches[i]
// 0x20 0x21
if err := k.StoreBatch(ctx, &batch); err != nil {
panic(err)
}
}

// reset attestations in state
for _, att := range state.Attestations {
for i := 0; i < len(state.Attestations); i++ {
att := state.Attestations[i]
claim, err := types.UnpackAttestationClaim(k.cdc, &att)
if err != nil {
panic("couldn't cast to claim")
Expand All @@ -100,7 +106,9 @@ func InitGenesis(ctx sdk.Context, k Keeper, state *types.GenesisState) {

// reset attestation state of specific validators
// this must be done after the above to be correct
for _, att := range state.Attestations {
for i := 0; i < len(state.Attestations); i++ {

att := state.Attestations[i]
claim, err := types.UnpackAttestationClaim(k.cdc, &att)
if err != nil {
panic("couldn't cast to claim")
Expand Down
4 changes: 2 additions & 2 deletions x/crosschain/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ func (m *MsgUpdateParams) GetSignBytes() []byte {

// GetSigners returns the expected signers for a MsgUpdateParams message.
func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}

Expand Down Expand Up @@ -864,6 +864,6 @@ func (m *MsgUpdateChainOracles) ValidateBasic() error {
}

func (m *MsgUpdateChainOracles) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
zakir-code marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 1 addition & 1 deletion x/erc20/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ func (suite *KeeperTestSuite) TestConvertDenom() {
}

coinBalance := suite.app.BankKeeper.GetBalance(suite.ctx, signer.AccAddress(), coin.Denom)
addr, _ := sdk.AccAddressFromBech32(msg.Receiver)
addr := sdk.MustAccAddressFromBech32(msg.Receiver)

expCoinBalance := suite.app.BankKeeper.GetBalance(suite.ctx, addr, expCoin.Denom)
_, err = suite.app.Erc20Keeper.ConvertDenom(sdk.WrapSDKContext(suite.ctx), &msg)
Expand Down
2 changes: 1 addition & 1 deletion x/erc20/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
EventTypeConvertDenom = "convert_denom"
EventTypeRegisterCoin = "register_coin"
EventTypeRegisterERC20 = "register_erc20"
EventTypeToggleTokenRelay = "toggle_token_relay"
EventTypeToggleTokenRelay = "toggle_token_relay" //nolint:gosec
Fixed Show fixed Hide fixed
EventTypeERC20Processing = "erc20_processing"
EventTypeRelayTransfer = "relay_transfer"
EventTypeRelayTransferCrossChain = "relay_transfer_cross_chain"
Expand Down
12 changes: 6 additions & 6 deletions x/erc20/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

TypeMsgRegisterCoin = "register_coin"
TypeMsgRegisterERC20 = "register_erc20"
TypeMsgToggleTokenConversion = "toggle_token_conversion"
TypeMsgToggleTokenConversion = "toggle_token_conversion" //nolint:gosec
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
TypeMsgUpdateDenomAlias = "update_denom_alias"
)

Expand Down Expand Up @@ -180,7 +180,7 @@

// GetSigners returns the expected signers for a MsgUpdateParams message.
func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
zakir-code marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -224,7 +224,7 @@
}

func (m *MsgRegisterCoin) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}

Expand Down Expand Up @@ -265,7 +265,7 @@
}

func (m *MsgRegisterERC20) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}

Expand Down Expand Up @@ -295,7 +295,7 @@
}

func (m *MsgToggleTokenConversion) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}

Expand Down Expand Up @@ -326,6 +326,6 @@
}

func (m *MsgUpdateDenomAlias) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}
2 changes: 1 addition & 1 deletion x/evm/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (m *MsgCallContract) GetSignBytes() []byte {

// GetSigners returns the expected signers for a MsgUpdateParams message.
func (m *MsgCallContract) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}

Expand Down
4 changes: 2 additions & 2 deletions x/gov/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (m *MsgUpdateParams) GetSignBytes() []byte {

// GetSigners returns the expected signers for a MsgUpdateParams message.
func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func (m *MsgUpdateEGFParams) GetSignBytes() []byte {

// GetSigners returns the expected signers for a MsgUpdateParams message.
func (m *MsgUpdateEGFParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.Authority)
addr := sdk.MustAccAddressFromBech32(m.Authority)
return []sdk.AccAddress{addr}
zakir-code marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Loading