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

feat: add golangci-lint check #74

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Abirdcfly
Copy link
Contributor

This pr introduces golangci-lint to detect problems with go source code.

And turns on 4 linters: gofmt goimports govet gosimple
(The first 3 linters are maintained by golang.org, gosimple is a linter enabled by golangci-lint default)

linters describe link
gofmt Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification https://golang.org/cmd/gofmt/
goimports In addition to fixing imports, goimports also formats your code in the same style as gofmt. https://godoc.org/golang.org/x/tools/cmd/goimports
govet Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string https://golang.org/cmd/vet/
gosimple Linter for Go source code that specializes in simplifying code https://github.com/dominikh/go-tools/tree/master/simple

See a list of supported linters and which linters are enabled/disabled in https://golangci-lint.run/usage/linters/.

@Abirdcfly Abirdcfly force-pushed the upstream-golangci branch 2 times, most recently from 4adbb0b to bab013f Compare November 8, 2022 09:47
@Abirdcfly Abirdcfly changed the title [wip] feat: add golangci-lint check feat: add golangci-lint check Nov 8, 2022
@jkneubuh
Copy link
Contributor

jkneubuh commented Nov 8, 2022

Hi @Abirdcfly -

Thank you for the addition of the code simplification tools. Unfortunately, golangci-lint package has been released under a GPL license, and is incompatible with the operator's Apache license requirement.

The golang.org linters are OK to enable. Can we aim for extensions to the CI pipeline that focus on improvements to the golang linters, and make incremental updates to the areas of code that can be simplified? (I do prefer many of the suggestions made by the gosimple linter - the code changes look pretty good.)

@Abirdcfly
Copy link
Contributor Author

Abirdcfly commented Nov 9, 2022

golangci-lint package has been released under a GPL license, and is incompatible with the operator's Apache license requirement.

Thank you very much for pointing out the license problem, to be honest, I'm not very clear about it, the reason why golangci-lint is used is because this tool is widely used by kubernetes(Apache License 2.0) and other projects in the kubernetes ecosystem.

Through some small research, I found that there are also many other Apache License 2.0 projects using golangci-lint tool directly, for example:

There are other projects that use golangci-lint-action (MIT License) Just like this pr does:

Some libraries we depend on also use golangci-lint:

Some projects in hyperledger-labs is Apache License 2.0, also use golangci-lint action:

I investigated this issue because I also have a project that is Apache License 2.0 but uses golangci-lint to check the source code, and from the results above, this seems to be possible and widespread.

@jkneubuh
Copy link
Contributor

jkneubuh commented Nov 9, 2022

We may be OK to run a GPL code linter during the build pipeline, provided that the GPL libraries are not linked in to the binaries, runtime, libraries, or docker image generated by the build.

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