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: remove unused local variables #22340

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@ linters-settings:
- regexpMust
- appendAssign
- ifElseChain
unused:
local-variables-are-used: false
Comment on lines +122 to +123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Reconsider disabling unused local variable checks

This change appears to contradict the PR's objective of removing unused local variables. Setting local-variables-are-used: false will prevent the linter from detecting unused variables, which could lead to code quality issues and dead code accumulation in the future.

Consider removing these lines to maintain strict checking for unused variables:

-  unused:
-    local-variables-are-used: false
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
unused:
local-variables-are-used: false
🧰 Tools
🪛 yamllint

[error] 123-123: no new line character at the end of file

(new-line-at-end-of-file)

2 changes: 1 addition & 1 deletion schema/indexer/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func StartIndexing(opts IndexingOptions) (IndexingTarget, error) {

targetCfg.Config, err = unmarshalIndexerCustomConfig(targetCfg.Config, init.ConfigType)
if err != nil {
return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %v", targetName, err)
return IndexingTarget{}, fmt.Errorf("failed to unmarshal indexer config for target %q: %w", targetName, err)
zakir-code marked this conversation as resolved.
Show resolved Hide resolved
}

initRes, err := init.InitFunc(InitParams{
Expand Down
2 changes: 0 additions & 2 deletions simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
// update bond intra-tx counters.
store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey))
iter := storetypes.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey)
counter := int16(0)

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
Expand All @@ -238,7 +237,6 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
if err = app.StakingKeeper.SetValidator(ctx, validator); err != nil {
panic(err)
}
counter++
}

if err := iter.Close(); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions store/cachekv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem corestore.KVSt
require.NoError(t, err)

krc := newKeyRangeCounter(r)
i := 0

for ; krc.valid(); krc.next() {
require.True(t, itr.Valid())
Expand All @@ -569,7 +568,6 @@ func assertIterateDomainCheck(t *testing.T, st types.KVStore, mem corestore.KVSt

itr.Next()
itr2.Next()
i++
}

require.False(t, itr.Valid())
Expand Down
1 change: 1 addition & 0 deletions types/mempool/priority_nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ func validateOrder(mtxs []sdk.Tx) error {
}
}
}
_ = iterations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Unused variable 'iterations' should be removed

The variable iterations in the validateOrder function is declared but never used in a meaningful way. Assigning _ = iterations is unnecessary and only suppresses the compiler warning. Considering the PR's objective to remove unused local variables, it's better to remove the variable entirely to clean up the code.

Apply the following diff to eliminate the unused variable:

 func validateOrder(mtxs []sdk.Tx) error {
-   iterations := 0
     var itxs []txSpec
     for i, mtx := range mtxs {
-     iterations++
       tx := mtx.(testTx)
       itxs = append(itxs, txSpec{p: int(tx.priority), n: int(tx.nonce), a: tx.address, i: i})
     }

     // Existing logic...

-   _ = iterations
     // fmt.Printf("validation in iterations: %d\n", iterations)
     return nil
 }

Committable suggestion was skipped due to low confidence.

// fmt.Printf("validation in iterations: %d\n", iterations)
zakir-code marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
Expand Down
3 changes: 0 additions & 3 deletions x/staking/keeper/query_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,9 @@ func (k Keeper) GetDelegatorValidator(
func (k Keeper) GetAllDelegatorDelegations(ctx context.Context, delegator sdk.AccAddress) ([]types.Delegation, error) {
delegations := make([]types.Delegation, 0)

var i int64
rng := collections.NewPrefixedPairRange[sdk.AccAddress, sdk.ValAddress](delegator)
err := k.Delegations.Walk(ctx, rng, func(key collections.Pair[sdk.AccAddress, sdk.ValAddress], del types.Delegation) (stop bool, err error) {
delegations = append(delegations, del)
i++

return false, nil
})
if err != nil {
Expand Down
Loading