8000 Fix lints by thanethomson · Pull Request #625 · cometbft/cometbft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix lints #625

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

Merged
merged 24 commits into from
Apr 5, 2023
Merged

Fix lints #625

merged 24 commits into from
Apr 5, 2023

Conversation

thanethomson
Copy link
Contributor
@thanethomson thanethomson commented Mar 31, 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 to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
Signed-off-by: Thane Thomson <connect@thanethomson.com>
@thanethomson thanethomson added backport-to-v0.34.x Tell Mergify to backport the PR to v0.34.x backport-to-v0.37.x Tell Mergify to backport the PR to v0.37.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
@@ -231,7 +231,7 @@ format:

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
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 <connect@thanethomson.com>
@@ -31,7 +31,7 @@ jobs:
go.sum
- uses: golangci/golangci-lint-action@v3
with:
version: v1.51
version: latest
Copy link
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
@@ -98,7 +98,8 @@ var RootCmd = &cobra.Command{
}

// 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
Contributor Author

Choose a reason for hiding this comment

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

See #626.

Copy link
Contributor
@lasarojc lasarojc left a comment

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

@@ -178,11 +178,9 @@ func StartSwitches(switches []*Switch) error {
func MakeSwitch(
cfg *config.P2PConfig,
i int,
network, version string,
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch!

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
Contributor

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
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 _.

Copy link
Contributor
@sergio-mena sergio-mena left a comment

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
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 <connect@thanethomson.com>
@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/uncl
F438
og) 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 <connect@thanethomson.com>

---------

Signed-off-by: Thane Thomson <connect@thanethomson.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
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.34.x Tell Mergify to backport the PR to v0.34.x backport-to-v0.37.x Tell Mergify to backport the PR to v0.37.x 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
0