Skip to content

feat(ci): adding golangci-lint - #35

Closed
hjoshi123 wants to merge 2 commits into
apple:mainfrom
hjoshi123:feat/golangci-lint
Closed

feat(ci): adding golangci-lint#35
hjoshi123 wants to merge 2 commits into
apple:mainfrom
hjoshi123:feat/golangci-lint

Conversation

@hjoshi123

@hjoshi123 hjoshi123 commented Jun 28, 2025

Copy link
Copy Markdown

Fixes #27.

Added the following linters:

    - asasalint
    - asciicheck
    - bidichk
    - bodyclose
    - canonicalheader
    - contextcheck
    - copyloopvar
    - decorder
    - dogsled
    - dupword
    - durationcheck
    - errcheck
    - errchkjson
    - errname
    - exhaustive
    - exptostd
    - forbidigo
    - gocheckcompilerdirectives
    - gochecksumtype
    - gocritic
    - goheader
    - goprintffuncname
    - gosec
    - gosmopolitan
    - govet
    - grouper
    - importas
    - ineffassign
    - interfacebloat
    - intrange
    - loggercheck
    - makezero
    - mirror
    - misspell
    - musttag
    - nakedret
    - nilerr
    - nilnil
    - noctx
    - nosprintfhostport
    - predeclared
    - promlinter
    - protogetter
    - reassign
    - sloglint
    - staticcheck
    - tagalign
    - testableexamples
    - unconvert
    - unparam
    - unused
    - usestdlibvars
    - usetesting
    - wastedassign

Signed-off-by: hjoshi123 <hemant.joshi@vizio.com>
@katiewasnothere

Copy link
Copy Markdown
Contributor

Hi @hjoshi123 thank you for the change! Was there a particular reason you chose this set of checks?

Comment thread .golangci.yaml Outdated
gci:
sections:
- standard
- defaul

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

default

Comment thread .golangci.yaml Outdated
- exhaustive
- exptostd
- forbidigo
- ginkgolinter

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure we need this. We don't have any ginkgo tests in this repo.

Comment thread scripts/install-tools.sh Outdated
ci_install=true
fi
if [[ "$ci_install" == true ]]; then
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/cc3567e3127d8530afb69be1b7bd20ba9ebcc7c1/install.sh \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the other container project repos, we tend to install things under a .local directory for make to use (example https://github.com/apple/container/blob/9eb2f860fc35a933e7894bc5313e3b79cd001c52/Makefile#L162).

Comment thread scripts/install-tools.sh Outdated
ci_install=true
fi
if [[ "$ci_install" == true ]]; then
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/cc3567e3127d8530afb69be1b7bd20ba9ebcc7c1/install.sh \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we could do something like this for the address

https://raw.githubusercontent.com/golangci/golangci-lint/${GOLANGCI_LINTER_VERSION}/install.sh

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yup that makes sense.. changing it

Comment thread scripts/install-tools.sh
@hjoshi123

hjoshi123 commented Jul 1, 2025

Copy link
Copy Markdown
Author

Hi @hjoshi123 thank you for the change! Was there a particular reason you chose this set of checks?

Some of them were mentioned by default in the golangci lint docs and then I referred some of the k8s repos for others. Will make changes to remove some of them which are irrelevant as you mentioned.

@katiewasnothere

Copy link
Copy Markdown
Contributor

@hjoshi123 Were you able to make the changes here?

@hjoshi123

Copy link
Copy Markdown
Author

@katiewasnothere sorry was busy with work.. will push the changes by this weekend.

Signed-off-by: hjoshi123 <mail@hjoshi.me>
Comment thread Makefile

.PHONY: go-lint
go-lint: golangci-lint-install
$(GOLANGCI_LINT) config verify

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this will work when the script has installed golangci-lint under .local/bin. I think following something similar to what we do for installing protoc would be good. What do you think?

Comment thread scripts/install-tools.sh

install_golangci() {
ci_install=false
if [[ -x $(which golangci-lint) ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think which will not find the binary if it's installed under .local/bin

Comment thread scripts/install-tools.sh
Comment on lines +22 to +25
if [[ "${version}" == "${GOLANGCI_LINTER_VERSION#v}" ]]; then
ci_install=false
else
ci_install=true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we do something like how we install protoc, we get the check for whether to install golangci-lint for free since make will check if the file path exists, as it does for protoc here. Does that make sense?

- name: Check protobufs
run: |
- name: Verify linter configuration and Lint go code
uses: golangci/golangci-lint-action@v8

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should instead call the makefile command to install golangci-lint and then run it. That way the behavior is the same between local dev and the CI run.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also the CI right now won't run for this PR right now since golangci/golangci-lint-action@v8 is not in our allowlist for actions that can be run

@katiewasnothere

katiewasnothere commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

Closing for now since there haven't been updates on this PR in the last month. Please feel free to reopen.

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.

[Request]: Setup and Use GolangCI Lint for the project

3 participants