Skip to content

Fix lints - #625

Merged
mergify[bot] merged 24 commits into
mainfrom
thane/fix-lints
Apr 5, 2023
Merged

mergify[bot] merged 24 commits into
mainfrom
thane/fix-lints

Conversation

@thanethomson

@thanethomson thanethomson commented Mar 31, 2023 •

Copy link
Copy Markdown
Contributor

This touches a large number of files, but I believe it's necessary as part of our tech debt cleanup. There are so many functions littering the codebase where:

  1. We have unused parameters and they should have been refactored away, but they weren't
  2. We have unused parameters and they should be named according to proper Go conventions (e.g. in interface implementations where a particular function signature is required, but the variable names should either be left out or _ when unused)
  3. We have redundant code (a whole bunch of redundant if statements and error checks, for example)
  4. We use bad naming conventions for variables, like copy or len

I'm also tired of having the linter fail locally. And if we don't do this, it will all just rot even more.

This PR targets main, but should be applied across all the backport branches (which will, of course, require some conflict resolution, but I'm fine with doing that). I've left TODOs in some places where changes need to be made in follow-up PRs.

Commits are organized by package so that it's hopefully easier to review.

If you pick up on formatting changes, please see #604.


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
Signed-off-by: Thane Thomson <[email protected]>
@thanethomson thanethomson added backport-to-v0.34.x P:tech-debt Priority: Technical debt that needs to be paid off to enable us to move faster, reliably backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x labels Mar 31, 2023
Comment thread Makefile
lint:
@echo "--> Running linter"
@go run github.com/golangci/golangci-lint/cmd/golangci-lint run
@go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

By not specifying latest here, the version of golangci-lint used locally will be whichever version is currently installed in your ${GOPATH}/bin, meaning that each of us will potentially have a different version and therefore experience different results when linting locally.

Using latest here makes it consistent for all of us.

Signed-off-by: Thane Thomson <[email protected]>
- uses: golangci/golangci-lint-action@v3
with:
version: v1.51
version: latest

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think we should keep up with the latest golangci-lint releases, especially if we're enforcing this check in the lint target of the Makefile, to ensure consistency.

@thanethomson
thanethomson marked this pull request as ready for review March 31, 2023 13:23
@thanethomson
thanethomson requested a review from a team as a code owner March 31, 2023 13:23

// deprecateSnakeCase is a util function for 0.34.1. Should be removed in 0.35
func deprecateSnakeCase(cmd *cobra.Command, args []string) {
// TODO(thane): Remove this across all releases

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See #626.

@lasarojc lasarojc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

while I dislike some of the the practices pushed by the Lint, I all all for uniformity.
LGTM

Comment thread blocksync/reactor.go Resolved
Comment thread p2p/test_util.go
func MakeSwitch(
cfg *config.P2PConfig,
i int,
network, version string,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch!

Comment thread rpc/grpc/api.go
Comment on lines +15 to +20
func (bapi *broadcastAPI) Ping(context.Context, *RequestPing) (*ResponsePing, error) {
// kvstore so we can check if the server is up
return &ResponsePing{}, nil
}

func (bapi *broadcastAPI) BroadcastTx(ctx context.Context, req *RequestBroadcastTx) (*ResponseBroadcastTx, error) {
func (bapi *broadcastAPI) BroadcastTx(_ context.Context, req *RequestBroadcastTx) (*ResponseBroadcastTx, error) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We are setting the variable name to "_" in line 20, and removing the name altogether in line 15?
Can we treat the two cases the same way'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The convention in Go is that, if all function parameters are unused, then you can have unnamed parameters. But the moment that one of your parameters is used, they all have to be named, in which case the unused ones must be called _.

@sergio-mena sergio-mena left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this @thanethomson
I like it because there is zero risk of breaking something and the changes are sparse enough not to hinder git-blame significantly.
One thought: since this is strictly refactoring, is it worth your time backporting it to other branches?

@thanethomson

Copy link
Copy Markdown
Contributor Author

One thought: since this is strictly refactoring, is it worth your time backporting it to other branches?

If we don't, our local linter's going to fail when linting those branches, so I think I'll have to backport this.

Signed-off-by: Thane Thomson <[email protected]>
@mergify
mergify Bot merged commit 111d252 into main Apr 5, 2023
@mergify
mergify Bot deleted the thane/fix-lints branch April 5, 2023 10:55
mergify Bot pushed a commit that referenced this pull request Apr 5, 2023
This touches a large number of files, but I believe it's necessary as part of our tech debt cleanup. There are so many functions littering the codebase where:

1. We have unused parameters and they should have been refactored away, but they weren't
2. We have unused parameters and they should be named according to proper Go conventions (e.g. in interface implementations where a particular function signature is required, but the variable names should either be left out or `_` when unused)
3. We have redundant code (a whole bunch of redundant `if` statements and error checks, for example)
4. We use bad naming conventions for variables, like `copy` or `len`

I'm also tired of having the linter fail locally. And if we don't do this, it will all just rot even more.

This PR targets `main`, but should be applied across all the backport branches (which will, of course, require some conflict resolution, but I'm fine with doing that). I've left TODOs in some places where changes need to be made in follow-up PRs.

Commits are organized by package so that it's hopefully easier to review.

If you pick up on formatting changes, please see #604.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments

(cherry picked from commit 111d252)

# Conflicts:
#	consensus/state.go
#	rpc/core/abci.go
#	rpc/core/blocks.go
#	rpc/core/consensus.go
#	rpc/core/evidence.go
#	rpc/core/health.go
#	rpc/core/mempool.go
#	rpc/core/net.go
#	rpc/core/status.go
#	rpc/core/tx.go
@mergify mergify Bot mentioned this pull request Apr 5, 2023
mergify Bot pushed a commit that referenced this pull request Apr 5, 2023
This touches a large number of files, but I believe it's necessary as part of our tech debt cleanup. There are so many functions littering the codebase where:

1. We have unused parameters and they should have been refactored away, but they weren't
2. We have unused parameters and they should be named according to proper Go conventions (e.g. in interface implementations where a particular function signature is required, but the variable names should either be left out or `_` when unused)
3. We have redundant code (a whole bunch of redundant `if` statements and error checks, for example)
4. We use bad naming conventions for variables, like `copy` or `len`

I'm also tired of having the linter fail locally. And if we don't do this, it will all just rot even more.

This PR targets `main`, but should be applied across all the backport branches (which will, of course, require some conflict resolution, but I'm fine with doing that). I've left TODOs in some places where changes need to be made in follow-up PRs.

Commits are organized by package so that it's hopefully easier to review.

If you pick up on formatting changes, please see #604.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments

(cherry picked from commit 111d252)

# Conflicts:
#	abci/client/grpc_client.go
#	abci/client/grpc_client_test.go
#	abci/client/socket_client.go
#	abci/client/socket_client_test.go
#	abci/cmd/abci-cli/abci-cli.go
#	abci/example/kvstore/kvstore.go
#	abci/example/kvstore/kvstore_test.go
#	abci/server/grpc_server.go
#	abci/tests/server/client.go
#	abci/types/application.go
#	blocksync/reactor.go
#	cmd/cometbft/commands/inspect.go
#	consensus/reactor_test.go
#	consensus/replay_stubs.go
#	consensus/replay_test.go
#	consensus/state.go
#	consensus/state_test.go
#	consensus/types/height_vote_set_test.go
#	inspect/inspect.go
#	inspect/inspect_test.go
#	mempool/v0/clist_mempool_test.go
#	node/node.go
#	node/setup.go
#	p2p/base_reactor.go
#	p2p/mock/peer.go
#	p2p/mock/reactor.go
#	p2p/peer_set_test.go
#	rpc/client/local/local.go
#	rpc/client/mock/client.go
#	rpc/core/abci.go
#	rpc/core/blocks.go
#	rpc/core/consensus.go
#	rpc/core/dev.go
#	rpc/core/evidence.go
#	rpc/core/health.go
#	rpc/core/mempool.go
#	rpc/core/net.go
#	rpc/core/status.go
#	rpc/core/tx.go
#	state/indexer/block/kv/util.go
#	state/state_test.go
#	state/txindex/kv/utils.go
#	statesync/reactor.go
#	statesync/reactor_test.go
#	store/store_test.go
#	test/e2e/app/app.go
#	test/e2e/runner/evidence.go
#	types/event_bus.go
#	types/validator_set.go
mergify Bot pushed a commit that referenced this pull request Apr 5, 2023
This touches a large number of files, but I believe it's necessary as part of our tech debt cleanup. There are so many functions littering the codebase where:

1. We have unused parameters and they should have been refactored away, but they weren't
2. We have unused parameters and they should be named according to proper Go conventions (e.g. in interface implementations where a particular function signature is required, but the variable names should either be left out or `_` when unused)
3. We have redundant code (a whole bunch of redundant `if` statements and error checks, for example)
4. We use bad naming conventions for variables, like `copy` or `len`

I'm also tired of having the linter fail locally. And if we don't do this, it will all just rot even more.

This PR targets `main`, but should be applied across all the backport branches (which will, of course, require some conflict resolution, but I'm fine with doing that). I've left TODOs in some places where changes need to be made in follow-up PRs.

Commits are organized by package so that it's hopefully easier to review.

If you pick up on formatting changes, please see #604.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments

(cherry picked from commit 111d252)

# Conflicts:
#	.github/workflows/lint.yml
#	abci/client/grpc_client.go
#	abci/client/grpc_client_test.go
#	abci/client/socket_client.go
#	abci/client/socket_client_test.go
#	abci/cmd/abci-cli/abci-cli.go
#	abci/example/kvstore/kvstore.go
#	abci/example/kvstore/kvstore_test.go
#	abci/server/grpc_server.go
#	abci/tests/server/client.go
#	abci/types/application.go
#	blockchain/v0/reactor.go
#	cmd/cometbft/commands/inspect.go
#	cmd/cometbft/commands/light.go
#	consensus/reactor_test.go
#	consensus/replay_stubs.go
#	consensus/replay_test.go
#	consensus/state.go
#	consensus/state_test.go
#	consensus/types/height_vote_set_test.go
#	consensus/wal_generator.go
#	inspect/inspect.go
#	inspect/inspect_test.go
#	internal/test/validator.go
#	mempool/v0/clist_mempool_test.go
#	node/node.go
#	node/setup.go
#	p2p/base_reactor.go
#	p2p/mock/peer.go
#	p2p/mock/reactor.go
#	p2p/peer_set_test.go
#	p2p/switch_test.go
#	rpc/client/local/local.go
#	rpc/client/mock/client.go
#	rpc/core/abci.go
#	rpc/core/blocks.go
#	rpc/core/consensus.go
#	rpc/core/dev.go
#	rpc/core/evidence.go
#	rpc/core/health.go
#	rpc/core/mempool.go
#	rpc/core/net.go
#	rpc/core/status.go
#	rpc/core/tx.go
#	scripts/metricsgen/metricsgen.go
#	state/indexer/block/kv/util.go
#	state/state_test.go
#	state/txindex/kv/kv_test.go
#	state/txindex/kv/utils.go
#	statesync/reactor.go
#	statesync/reactor_test.go
#	store/store_test.go
#	test/e2e/app/app.go
#	test/e2e/runner/evidence.go
#	types/event_bus.go
#	types/validator_set.go
This was referenced Apr 5, 2023
thanethomson added a commit that referenced this pull request Apr 5, 2023
* Fix lints (#625)

This touches a large number of files, but I believe it's necessary as part of our tech debt cleanup. There are so many functions littering the codebase where:

1. We have unused parameters and they should have been refactored away, but they weren't
2. We have unused parameters and they should be named according to proper Go conventions (e.g. in interface implementations where a particular function signature is required, but the variable names should either be left out or `_` when unused)
3. We have redundant code (a whole bunch of redundant `if` statements and error checks, for example)
4. We use bad naming conventions for variables, like `copy` or `len`

I'm also tired of having the linter fail locally. And if we don't do this, it will all just rot even more.

This PR targets `main`, but should be applied across all the backport branches (which will, of course, require some conflict resolution, but I'm fine with doing that). I've left TODOs in some places where changes need to be made in follow-up PRs.

Commits are organized by package so that it's hopefully easier to review.

If you pick up on formatting changes, please see #604.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments

(cherry picked from commit 111d252)

# Conflicts:
#	consensus/state.go
#	rpc/core/abci.go
#	rpc/core/blocks.go
#	rpc/core/consensus.go
#	rpc/core/evidence.go
#	rpc/core/health.go
#	rpc/core/mempool.go
#	rpc/core/net.go
#	rpc/core/status.go
#	rpc/core/tx.go

* Fix conflicts

Signed-off-by: Thane Thomson <[email protected]>

---------

Signed-off-by: Thane Thomson <[email protected]>
Co-authored-by: Thane Thomson <[email protected]>
thanethomson added a commit that referenced this pull request May 6, 2023
This touches a large number of files, but I believe it's necessary as part of our tech debt cleanup. There are so many functions littering the codebase where:

1. We have unused parameters and they should have been refactored away, but they weren't
2. We have unused parameters and they should be named according to proper Go conventions (e.g. in interface implementations where a particular function signature is required, but the variable names should either be left out or `_` when unused)
3. We have redundant code (a whole bunch of redundant `if` statements and error checks, for example)
4. We use bad naming conventions for variables, like `copy` or `len`

I'm also tired of having the linter fail locally. And if we don't do this, it will all just rot even more.

This PR targets `main`, but should be applied across all the backport branches (which will, of course, require some conflict resolution, but I'm fine with doing that). I've left TODOs in some places where changes need to be made in follow-up PRs.

Commits are organized by package so that it's hopefully easier to review.

If you pick up on formatting changes, please see #604.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge backport-to-v0.38.x Tell Mergify to backport the PR to v0.38.x P:tech-debt Priority: Technical debt that needs to be paid off to enable us to move faster, reliably

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants