Skip to content

Conversation

@ctlong
Copy link
Member

@ctlong ctlong commented Apr 12, 2022

Description

Add a golangci configuration, and add a job to the Go workflow to lint our code while using it.

go vet is great. golangci-lint may be better 😁 .

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Testing performed?

  • Unit tests
  • Integration tests
  • Acceptance tests

Checklist:

  • This PR is being made against the main branch, or relevant version branch
  • I have made corresponding changes to the documentation
  • I have added testing for my changes

@cf-gitbot
Copy link

We have created an issue in Pivotal Tracker to manage this. Unfortunately, the Pivotal Tracker project is private so you may be unable to view the contents of the story.

The labels on this github issue will be updated when the story is started.

@ctlong ctlong changed the title Update: add golangci configuration and workflow Update: add golangci configuration and workflow for better go linting Apr 15, 2022
@ctlong ctlong marked this pull request as draft April 26, 2022 18:25
@ctlong ctlong marked this pull request as ready for review April 27, 2022 01:06
@ctlong ctlong requested a review from rroberts2222-zz May 4, 2022 16:24
Copy link

@rroberts2222-zz rroberts2222-zz left a comment

Choose a reason for hiding this comment

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

Lint test is failing because "Error return value of lw.Write is not checked (errcheck)"
Located in internal/command/query.go, internal/command/tail.go, and internal/command/meta.go

ctlong added 5 commits May 5, 2022 13:40
* [golangci](https://golangci-lint.run/) is a common and useful Go linter
aggregator that is fast, more opinionated  / frequently updated than `go
vet`, and it provides a nice output.
* `.golangci.yml` describes our current configuration of golangci.
* The new `lint` job in the Go workflow will run golangci on PRs and
pushes.
* golangci can be run manually: `golangci-lint run ./...`.
If the cf CLI is set to be insecure then we would want to copy that
setting, even though it's not ideal. Therefore we should ignore gosec
warning `G402`, which looks for bad TLS connection settings, and
always triggers because we might set TLS.InsecureSkipVerify to true.
golang.org/x/crypto/ssh/terminal is deprecated and has been moved to
golang.org/x/term.
Remove two unused vars: `invalidTimestampResponse` and `invalidPayloadResponse`.
gocyclo measures cyclomatic complexity, which is:
> a code quality metric which can be used to identify code that needs refactoring. It measures the number of linearly independent paths through a function's source code.

The default min-complexity that gocyclo ships with is 30. However, the
folks managing golangci currently recommend setting this factor between
10-20.
ctlong added 3 commits May 5, 2022 13:46
The error is not checked anywhere, so there's not much point in
returning it. We probably should go back and do check this error at some
point.
Several functions are too complex to pass the recommended
`min-complexity` settings.

This gets golang-ci closer to passing with our current code. We should
come back and lower the complexity + refactor the offending functions at
some point.
@ctlong ctlong requested a review from rroberts2222-zz May 5, 2022 20:59
@ctlong
Copy link
Member Author

ctlong commented May 5, 2022

This is as close as we're going to get to passing golangci-lint until we replace the deprecated protobuf package, which depends upon changes to go-loggregator: cloudfoundry/go-loggregator#62.

Copy link

@rroberts2222-zz rroberts2222-zz left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants