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

Update golangci-lint and ensure the code passes make lint/go #4656

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

karamaru-alpha
Copy link
Contributor

@karamaru-alpha karamaru-alpha commented Nov 7, 2023

What this PR does / why we need it:

  • Update golangci-lint v1.46.2 to v1.55.2 in order to support Go 1.20(v1.51.0~)
  • Ensure the code passes golangci-lint
    • Currently, the make lint/go command does not output any errors.
    • Temporarily disabled a few linters(errcheck,goerr113,gosec) that seemed time-consuming to address in order to expedite the implementation of CI. I will handle them in the near future.
Resolved errors from the `make lint/go` command
pkg/app/ops/deploymentchaincontroller/controller.go:133:79: (*DeploymentChainController).syncDeploymentChains - result 0 (error) is always nil (unparam)
func (d *DeploymentChainController) syncDeploymentChains(ctx context.Context) error {
                                                                              ^
pkg/app/piped/appconfigreporter/appconfigreporter.go:236:112: (*Reporter).findOutOfSyncRegisteredApps - result 1 (error) is always nil (unparam)
func (r *Reporter) findOutOfSyncRegisteredApps(repoPath, repoID, headCommit string) ([]*model.ApplicationInfo, error) {
                                                                                                               ^
pkg/app/piped/cmd/piped/piped.go:700:3: singleCaseSwitch: should rewrite switch statement to if statement (gocritic)
		switch sm.Type {
		^
pkg/app/piped/controller/controller.go:291:56: (*controller).syncPlanners - result 0 (error) is always nil (unparam)
func (c *controller) syncPlanners(ctx context.Context) error {
                                                       ^
pkg/app/piped/controller/controller.go:509:58: (*controller).syncSchedulers - result 0 (error) is always nil (unparam)
func (c *controller) syncSchedulers(ctx context.Context) error {
                                                         ^
pkg/app/piped/controller/controller.go:556:13: appendAssign: append result not assigned to the same slice (gocritic)
	targets := append(runnings, planneds...)
	           ^
pkg/app/piped/driftdetector/cloudrun/detector.go:125:47: (*detector).check - result 0 (error) is always nil (unparam)
func (d *detector) check(ctx context.Context) error {
                                              ^
pkg/app/piped/driftdetector/kubernetes/detector.go:123:47: (*detector).check - result 0 (error) is always nil (unparam)
func (d *detector) check(ctx context.Context) error {
                                              ^
pkg/app/piped/driftdetector/terraform/detector.go:124:47: (*detector).check - result 0 (error) is always nil (unparam)
func (d *detector) check(ctx context.Context) error {
                                              ^
pkg/app/piped/executor/analysis/analysis.go:119:47: `analysises` is a misspelling of `analyses` (misspell)
				// Stop the context to cancel all running analysises.
				                                          ^
pkg/app/piped/executor/kubernetes/kubernetes.go:311:2: Consider pre-allocating `out` (prealloc)
	var out []provider.Manifest
	^
pkg/app/piped/executor/kubernetes/kubernetes.go:325:2: Consider pre-allocating `out` (prealloc)
	var out []provider.Manifest
	^
pkg/app/piped/executor/kubernetes/kubernetes_test.go:1021:3: assignOp: replace `out.Key.Namespace = out.Key.Namespace + "+"` with `out.Key.Namespace += "+"` (gocritic)
		out.Key.Namespace = out.Key.Namespace + "+"
		^
pkg/app/piped/livestatereporter/cloudrun/report.go:99:56: (*reporter).flushSnapshots - result 0 (error) is always nil (unparam)
func (r *reporter) flushSnapshots(ctx context.Context) error {
                                                       ^
pkg/app/piped/livestatereporter/kubernetes/reporter.go:112:56: (*reporter).flushSnapshots - result 0 (error) is always nil (unparam)
func (r *reporter) flushSnapshots(ctx context.Context) error {
                                                       ^
pkg/app/piped/livestatestore/kubernetes/appnodes.go:87:55: `(*appNodes).deleteManagingResource` - `key` is unused (unparam)
func (a *appNodes) deleteManagingResource(uid string, key provider.ResourceKey, now time.Time) (model.KubernetesResourceStateEvent, bool) {
                                                      ^
pkg/app/piped/livestatestore/kubernetes/appnodes.go:141:55: `(*appNodes).deleteDependedResource` - `key` is unused (unparam)
func (a *appNodes) deleteDependedResource(uid string, key provider.ResourceKey, now time.Time) (model.KubernetesResourceStateEvent, bool) {
                                                      ^
pkg/app/piped/livestatestore/kubernetes/reflector.go:153:27: `(*reflector).start` - `ctx` is unused (unparam)
func (r *reflector) start(ctx context.Context) error {
                          ^
pkg/app/piped/notifier/slack.go:353:32: `truncateText` - `max` always receives `8` (unparam)
func truncateText(text string, max int) string {
                               ^
pkg/app/piped/planner/kubernetes/kubernetes.go:344:2: Consider pre-allocating `out` (prealloc)
	var out []provider.Manifest
	^
pkg/app/piped/planpreview/builder.go:304:205: `(*builder).findTriggerApps` - result `err` is always `nil` (unparam)
func (b *builder) findTriggerApps(ctx context.Context, repo git.Repo, apps []*model.Application, headCommit string) (triggerApps []*model.Application, failedResults []*model.ApplicationPlanPreviewResult, err error) {
                                                                                                                                                                                                            ^
pkg/app/piped/platformprovider/kubernetes/hasher.go:50:3: ifElseChain: rewrite if-else to switch statement (gocritic)
		if m.Key.IsConfigMap() {
		^
pkg/app/piped/platformprovider/kubernetes/resourcekey.go:24:5: ST1003: var builtInApiVersions should be builtInAPIVersions (stylecheck)
var builtInApiVersions = map[string]struct{}{
    ^
pkg/app/piped/platformprovider/kubernetes/state.go:427:3: S1023: redundant `return` statement (gosimple)
		return
		^
pkg/app/piped/trigger/trigger.go:477:45: `(*Trigger).notifyDeploymentTriggered` - `ctx` is unused (unparam)
func (t *Trigger) notifyDeploymentTriggered(ctx context.Context, appCfg *config.GenericApplicationSpec, d *model.Deployment) {
                                            ^
pkg/app/server/apikeyverifier/verifier.go:89:32: `(*Verifier).checkAPIKey` - `ctx` is unused (unparam)
func (v *Verifier) checkAPIKey(ctx context.Context, apiKey *model.APIKey, id, key string) error {
                               ^
pkg/crypto/hybrid.go:48: File is not `goimports`-ed with -local github.com/pipe-cd/pipecd (goimports)
//   RSA ciphertext length || RSA ciphertext || AES ciphertext
pkg/git/client.go:271:19: `retryCommand` - `retries` always receives `3` (unparam)
func retryCommand(retries int, interval time.Duration, logger *zap.Logger, commander func() ([]byte, error)) (out []byte, err error) {
                  ^
pkg/git/client_test.go:119:25: `(*faker).repoDir` - `org` always receives `org` (`"test-repo-org"`) (unparam)
func (f *faker) repoDir(org, repo string) string {

TODO (another PR)

  • Integrate golangci-lint into GitHub Actions
  • Resolve errcheck,goerr113,gosec errors

Which issue(s) this PR fixes:

Part of #4566

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

- gosec
- gocritic
- unparam
- deadcode
Copy link
Contributor Author

@karamaru-alpha karamaru-alpha Nov 7, 2023

Choose a reason for hiding this comment

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

Delete "deadcode" because this linter is deprecated.
cf. golangci/golangci-lint#1841

Comment on lines 40 to +47
depguard:
list-type: blacklist
include-go-root: true
packages-with-error-message:
- sync/atomic: "Use go.uber.org/atomic instead of sync/atomic"
- io/ioutil: "Use corresponding 'os' or 'io' functions instead."
rules:
main:
deny:
- pkg: "sync/atomic"
desc: "Use go.uber.org/atomic instead of sync/atomic."
- pkg: "io/ioutil"
desc: "Use corresponding 'os' or 'io' functions instead."
Copy link
Contributor Author

@karamaru-alpha karamaru-alpha Nov 7, 2023

Choose a reason for hiding this comment

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

The configuration method of "depguard" has been changed.
cf. https://golangci-lint.run/usage/linters/#depguard

desc: "Use corresponding 'os' or 'io' functions instead."
gocritic:
disabled-checks:
- appendAssign
Copy link
Contributor Author

@karamaru-alpha karamaru-alpha Nov 7, 2023

Choose a reason for hiding this comment

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

Since I didn't think the following error was particularly harmful, I ignored "appendAssign".

pkg/app/piped/controller/controller.go:556:13: appendAssign: append result not assigned to the same slice (gocritic)
targets := append(runnings, planneds...)

cf. go-critic/go-critic#865 (comment)

@@ -350,6 +350,7 @@ func makeSlackDate(unix int64) string {
return fmt.Sprintf("<!date^%d^{date_num} {time_secs}|date>", unix)
}

// nolint:unparam
Copy link
Contributor Author

@karamaru-alpha karamaru-alpha Nov 7, 2023

Choose a reason for hiding this comment

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

Ignore "unparam" to resolve the following error.

pkg/app/piped/notifier/slack.go:353:32: truncateText - max always receives 8 (unparam)
func truncateText(text string, max int) string {

It is impossible to remove the "always receives X" check by config currently.
cf. mvdan/unparam#31

Comment on lines +25 to +28
# TODO: Enable these linters
# - errcheck
# - goerr113
# - gosec
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 have decided to temporarily ignore linters that present numerous errors, seem time-consuming to resolve, or require discussion. This is because I believe it's more important to integrate golangci-lint into GitHub Actions to prevent a continuous increase in errors in the future.

Copy link
Member

Choose a reason for hiding this comment

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

got it, thanks 👍

@karamaru-alpha karamaru-alpha marked this pull request as ready for review November 7, 2023 20:27
Copy link

codecov bot commented Nov 7, 2023

Codecov Report

Attention: 8 lines in your changes are missing coverage. Please review.

Comparison is base (89fb203) 30.81% compared to head (b92198d) 30.84%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4656      +/-   ##
==========================================
+ Coverage   30.81%   30.84%   +0.02%     
==========================================
  Files         221      221              
  Lines       25941    25935       -6     
==========================================
+ Hits         7995     7999       +4     
+ Misses      17296    17286      -10     
  Partials      650      650              
Files Coverage Δ
pkg/app/piped/executor/kubernetes/kubernetes.go 58.59% <100.00%> (ø)
pkg/app/piped/executor/kubernetes/traffic.go 24.84% <100.00%> (ø)
pkg/app/piped/notifier/slack.go 3.57% <ø> (ø)
pkg/app/piped/planner/kubernetes/kubernetes.go 52.40% <100.00%> (ø)
...kg/app/piped/platformprovider/kubernetes/hasher.go 64.70% <100.00%> (ø)
...p/piped/platformprovider/kubernetes/resourcekey.go 27.85% <100.00%> (ø)
pkg/app/piped/platformprovider/kubernetes/state.go 0.00% <ø> (ø)
pkg/app/server/apikeyverifier/verifier.go 70.45% <100.00%> (ø)
pkg/crypto/hybrid.go 50.63% <ø> (ø)
pkg/git/client.go 47.67% <ø> (ø)
... and 6 more

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@kentakozuka kentakozuka left a comment

Choose a reason for hiding this comment

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

LGTM 👍
Thanks!

@kentakozuka kentakozuka merged commit b8a8c0c into pipe-cd:master Nov 10, 2023
13 checks passed
ffjlabo pushed a commit that referenced this pull request Nov 13, 2023
khanhtc1202 added a commit that referenced this pull request Nov 13, 2023
#4628 #4629 #4631 #4632 #4633 #4637 #4638 #4641 #4648 #4650 #4656 #4658 #4662 #4666 (#4669)

* Bump golang.org/x/net from 0.7.0 to 0.17.0 in /tool/actions-plan-preview (#4611)

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.7.0 to 0.17.0.
- [Commits](golang/net@v0.7.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump golang.org/x/net from 0.7.0 to 0.17.0 in /tool/actions-gh-release (#4612)

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.7.0 to 0.17.0.
- [Commits](golang/net@v0.7.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Khanh Tran <[email protected]>

* Bump golang.org/x/net from 0.8.0 to 0.17.0 (#4613)

Bumps [golang.org/x/net](https://github.com/golang/net) from 0.8.0 to 0.17.0.
- [Commits](golang/net@v0.8.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @babel/traverse from 7.14.7 to 7.23.2 in /web (#4619)

* Fix part of lint/go errors (misspell, depguard, unconvert) (#4621)

* Fix lint/go errors (misspell)

Signed-off-by: karamaru-alpha <[email protected]>

* Fix lint/go errors (depguard)

Signed-off-by: karamaru-alpha <[email protected]>

* Fix lint/go errors (unconvert)

Signed-off-by: karamaru-alpha <[email protected]>

---------

Signed-off-by: karamaru-alpha <[email protected]>

* Fix part of lint/go errors (goimports, staticcheck, gosimple) (#4622)

* Fix lint/go errors (goimport)

Signed-off-by: karamaru-alpha <[email protected]>

* Fix lint/go errors (staticcheck)

Signed-off-by: karamaru-alpha <[email protected]>

* Fix lint/go errors (gosimple)

Signed-off-by: karamaru-alpha <[email protected]>

* Fix lint/go errors (gosimple)

Signed-off-by: karamaru-alpha <[email protected]>

* Fix return error by function

Signed-off-by: karamaru-alpha <[email protected]>

---------

Signed-off-by: karamaru-alpha <[email protected]>

* Fix part of lint/go errors (deadcode, ineffassign, depguard) (#4624)

* Ignore mannwhitney from golangci-lint

Signed-off-by: karamaru-alpha <[email protected]>

* Fix lint/go errors (deadcode)

Signed-off-by: karamaru-alpha <[email protected]>

* Fix lint/go errors (depguard)

Signed-off-by: karamaru-alpha <[email protected]>

---------

Signed-off-by: karamaru-alpha <[email protected]>

* Add tests to terraform platform provider (#4625)

Signed-off-by: Kenta Kozuka <[email protected]>

* Add tests to apikey model (#4626)

Signed-off-by: Kenta Kozuka <[email protected]>

* Add tests to application model (#4627)

Signed-off-by: Kenta Kozuka <[email protected]>

* Reduce `make lint/go` execution time by adding the GOCACHE environment variable (#4628)

* Add GOCACHE env to lint/go

Signed-off-by: karamaru-alpha <[email protected]>

* Add verbose flag to lint/go

Signed-off-by: karamaru-alpha <[email protected]>

* Change timeout golangci.yml

Signed-off-by: karamaru-alpha <[email protected]>

---------

Signed-off-by: karamaru-alpha <[email protected]>

* Add tests to model/deployment (#4629)

Signed-off-by: Kenta Kozuka <[email protected]>

* Add tests to model/notificationevent (#4631)

* Add tests to model/notificationevent

Signed-off-by: Kenta Kozuka <[email protected]>

* Add Parallel()

Signed-off-by: Kenta Kozuka <[email protected]>

---------

Signed-off-by: Kenta Kozuka <[email protected]>

* Add tests to model/deployment_chain (#4632)

* Bump google.golang.org/grpc from 1.54.0 to 1.56.3 (#4633)

* Bump google.golang.org/grpc from 1.54.0 to 1.56.3

Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.54.0 to 1.56.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](grpc/grpc-go@v1.54.0...v1.56.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update grpc test version

Signed-off-by: khanhtc1202 <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: khanhtc1202 <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: khanhtc1202 <[email protected]>

* Fix lint/go errors (gocritic) (#4637)

Signed-off-by: karamaru-alpha <[email protected]>

* Fix part of lint/go errors (stylecheck)  (#4638)

* Fix lint/go errors (stylecheck)

Signed-off-by: karamaru-alpha <[email protected]>

* Remove nolint:stylecheck

Signed-off-by: karamaru-alpha <[email protected]>

* Change method reveiver name

Signed-off-by: karamaru-alpha <[email protected]>

* Change receiver name k to ak

Signed-off-by: karamaru-alpha <[email protected]>

---------

Signed-off-by: karamaru-alpha <[email protected]>

* Bump github.com/docker/docker (#4641)

* Make actions plan preview handle timeout option (#4648)

* Format and make tests pass in tool/actions-plan-preview

Signed-off-by: mi11km <[email protected]>

* Use --piped-handle-timeout to make the timeout arg activate

Signed-off-by: mi11km <[email protected]>

* Add tests to model/notificationevent (#4631)

* Add tests to model/notificationevent

Signed-off-by: Kenta Kozuka <[email protected]>

* Add Parallel()

Signed-off-by: Kenta Kozuka <[email protected]>

---------

Signed-off-by: Kenta Kozuka <[email protected]>
Signed-off-by: mi11km <[email protected]>

* add piped-handle-timeout(input args)

Signed-off-by: mi11km <[email protected]>

---------

Signed-off-by: mi11km <[email protected]>
Signed-off-by: Kenta Kozuka <[email protected]>
Co-authored-by: Kenta Kozuka <[email protected]>
Co-authored-by: Khanh Tran <[email protected]>

* Fix panic error in ListDeployments API (#4650)

* Update golangci-lint and fix lint errors (#4656)

Signed-off-by: karamaru-alpha <[email protected]>

* Send error comment before plan preview exit (#4658)

* Send error comment before plan preview exit

Signed-off-by: Takumaron <[email protected]>

* Apply review commnet

Signed-off-by: Takumaron <[email protected]>

---------

Signed-off-by: Takumaron <[email protected]>

* Handle plan preview workflow's error and exit with error status code (#4662)

* Add a flag to skip running standalone task during deployment (#4666)

* Add a flag to skip running standalone task during deployment

Signed-off-by: Kenta Kozuka <[email protected]>

* Fix docs

Signed-off-by: Kenta Kozuka <[email protected]>

---------

Signed-off-by: Kenta Kozuka <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: karamaru-alpha <[email protected]>
Signed-off-by: Kenta Kozuka <[email protected]>
Signed-off-by: khanhtc1202 <[email protected]>
Signed-off-by: mi11km <[email protected]>
Signed-off-by: Takumaron <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Khanh Tran <[email protected]>
Co-authored-by: karamaru <[email protected]>
Co-authored-by: Kenta Kozuka <[email protected]>
Co-authored-by: khanhtc1202 <[email protected]>
Co-authored-by: Masafumi Ikeyama <[email protected]>
Co-authored-by: Seitaro Fujigaki <[email protected]>
Co-authored-by: Kurosawa Takuma <[email protected]>
@github-actions github-actions bot mentioned this pull request Dec 1, 2023
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Dec 17, 2023
@github-actions github-actions bot mentioned this pull request Feb 6, 2024
sZma5a pushed a commit to sZma5a/pipecd that referenced this pull request Feb 12, 2024
Signed-off-by: karamaru-alpha <[email protected]>
Signed-off-by: 鈴木 優耀 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants