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

Resolve staticcheck linter reported issues #5734

Closed
blackpiglet opened this issue Jan 4, 2023 · 2 comments · Fixed by #5788
Closed

Resolve staticcheck linter reported issues #5734

blackpiglet opened this issue Jan 4, 2023 · 2 comments · Fixed by #5788
Assignees
Milestone

Comments

@blackpiglet
Copy link
Contributor

blackpiglet commented Jan 4, 2023

Describe the problem/challenge you have
[A description of the current limitation/problem/challenge that you are experiencing.]
#5726 wants to enable more linters for Velero to comply with cluster-api's standard.
There is a significant gap between the cluster-api and Velero GolangCI enabled linters.
By far, staticcheck linter reports most issues, so try to resolve those first.

Describe the solution you'd like
[A clear and concise description of what you want to happen.]
This is the result of staticcheck linter scan result of Velero repository. There are 266 issues.
It looks like there is no whitelist setting available for staticcheck linter. dot_import_whitelist looks related, but it's used for dot-importing some external testing packages. It cannot make linter only to choose specific path of Velero code.

We need to resolve most of the reported issues to enable the staticcheck linter, because staticcheck makes the golangci check halt until timeout on my developing environment.

staticcheck_result_formatted.json

staticcheck_result_raw.json

Anything else you would like to add:
[Miscellaneous information that will assist in solving the issue.]

Environment:

  • Velero version (use velero version):
  • Kubernetes version (use kubectl version):
  • Kubernetes installer & version:
  • Cloud provider or hardware configuration:
  • OS (e.g. from /etc/os-release):

Vote on this issue!

This is an invitation to the Velero community to vote on issues, you can see the project's top voted issues listed here.
Use the "reaction smiley face" up to the right of this comment to vote.

  • 👍 for "The project would be better with this feature added"
  • 👎 for "This feature will not enhance the project in a meaningful way"
@blackpiglet
Copy link
Contributor Author

blackpiglet commented Jan 4, 2023

First install staticcheck linter binary, then run the linter to get the scan result.

# install staticcheck binary
go install honnef.co/go/tools/cmd/[email protected]

# run staticcheck linter
cd ~/go/src/github.com/vmware-tanzu/velero
staticcheck -f json ./... > staticcheck_result_raw.json

The result is ouputed as multiple JSONs. Need to integrate them into a JSON array to better display.

import json

results = []
for line in open('staticcheck_result_raw.json', 'r'):
    results.append(json.loads(line))

out_file = open("staticcheck_result_formatted.json", "w")
  
json.dump(results, out_file, indent = 2)
  
out_file.close()

Formatted JSON file is a bit long. Can split the file into several shards.

split -l 1000 staticcheck_result_formatted.json split_

@blackpiglet blackpiglet added this to the v1.11 milestone Jan 9, 2023
@reasonerjt reasonerjt modified the milestone: v1.11 Jan 10, 2023
@reasonerjt
Copy link
Contributor

Let's target v1.11 to enable the check. However, there may be too many errors to fix, we'll skip the check for some of the packages and fix the issues iteratively in future patch releases.

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 a pull request may close this issue.

2 participants