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

Add lint-go-gopls #30729

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Add lint-go-gopls #30729

wants to merge 17 commits into from

Conversation

silverwind
Copy link
Member

@silverwind silverwind commented Apr 27, 2024

Uses gopls check <files> as a linter. Tested locally and brings up 149 errors currently for me. I don't think I want to fix them in this PR, but I would like at least to get this analysis running on CI.

List of errors:

modules/indexer/code/indexer.go:181:11: impossible condition: nil != nil
routers/private/hook_post_receive.go:120:15: tautological condition: nil == nil
services/auth/source/oauth2/providers.go:185:9: tautological condition: nil == nil
services/convert/issue.go:216:11: tautological condition: non-nil != nil
tests/integration/git_test.go:332:9: impossible condition: nil != nil
services/migrations/migrate.go:179:24-43: unused parameter: ctx
services/repository/transfer.go:288:48-69: unused parameter: doer
tests/integration/api_repo_tags_test.go:75:41-61: unused parameter: session
tests/integration/git_test.go:696:64-74: unused parameter: baseBranch
tests/integration/gpg_git_test.go:265:27-39: unused parameter: t
tests/integration/gpg_git_test.go:284:23-29: unused parameter: tmpDir
tests/integration/gpg_git_test.go:284:31-35: unused parameter: name
tests/integration/gpg_git_test.go:284:37-42: unused parameter: email

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 27, 2024
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 27, 2024
@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 27, 2024
@silverwind
Copy link
Member Author

silverwind commented Apr 27, 2024

The gopls check command currently does not set a proper exit code when there are errors, so we would likely have to analyze the output.

silverwind pushed a commit that referenced this pull request Apr 27, 2024
Suggested by logs in #30729

- Remove `math/rand.Seed`
`rand.Seed is deprecated: As of Go 1.20 there is no reason to call Seed
with a random value.`
- Replace `math/rand.Read`
`rand.Read is deprecated: For almost all use cases, [crypto/rand.Read]
is more appropriate.`
- Replace `math/rand` with `math/rand/v2`, which is available since Go
1.22
@silverwind silverwind marked this pull request as draft April 27, 2024 17:15
@silverwind
Copy link
Member Author

silverwind commented Apr 27, 2024

Lint script added which performs error detection and error counting. It should now fail the CI like this and also be much less verbose with module downloads which it apparently does:

/Users/silverwind/git/gitea/modules/git/commit_info_nogogit.go:100:35-54: unused parameter: ctx [windows,amd64]
/Users/silverwind/git/gitea/modules/git/commit_info_nogogit.go:100:35-54: unused parameter: ctx
Found 149 'gopls check' errors
make: *** [Makefile:432: lint-go-gopls] Error 1

@silverwind silverwind marked this pull request as ready for review April 27, 2024 19:07
tools/lint-go-gopls.sh Outdated Show resolved Hide resolved
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 27, 2024
@silverwind
Copy link
Member Author

silverwind commented Apr 27, 2024

Output and failure detection looks good now. I will add || true so we can merge it without fixing the errors.

lunny pushed a commit that referenced this pull request Apr 28, 2024
In both cases, the `err` is nil because of `if` checks before

Reference: #30729
wxiaoguang pushed a commit to wxiaoguang/gitea that referenced this pull request Apr 28, 2024
In both cases, the `err` is nil because of `if` checks before

Reference: go-gitea#30729
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 28, 2024
@silverwind
Copy link
Member Author

This causes a number of annotations to show up on PRs that we should fix first before merging, otherwise it would be annoying having those show up on every PR.

silverwind pushed a commit that referenced this pull request Apr 29, 2024
)

Resolve all cases for `unused parameter` and `unnecessary type
arguments`

Related: #30729

---------

Co-authored-by: Giteabot <teabot@gitea.io>
@silverwind
Copy link
Member Author

Will post an update later on the outstanding issues. I think we should only merge this after all issues have been fixed.

@silverwind
Copy link
Member Author

49 errors left, #30735 will fix a few.

@silverwind
Copy link
Member Author

silverwind commented Apr 29, 2024

It seems gopls has no support for //nolint currently, so we need to get more creative for technical debt like this one:

//lint:ignore SA1019 We use IsAnInteractiveSession because IsWindowsService has a different permissions profile
isAnInteractiveSession, err := svc.IsAnInteractiveSession() //nolint:staticcheck

@silverwind
Copy link
Member Author

silverwind commented Apr 29, 2024

It seems all deprecations that are warned here already have //nolint comments, so I'll just ignore any error with "is deprecated". Some of these should defintely be looked at though.

@silverwind silverwind marked this pull request as draft April 29, 2024 21:40
silverwind added a commit that referenced this pull request Apr 30, 2024
As discovered by #30729.

---------

Co-authored-by: Giteabot <teabot@gitea.io>
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this pull request May 9, 2024
As discovered by go-gitea/gitea#30729.

---------

Co-authored-by: Giteabot <teabot@gitea.io>
(cherry picked from commit 610802df85933e7a190a705bc3f7800da87ce868)

Conflicts:
	tests/integration/git_test.go
	trivial conflict because of https://codeberg.org/forgejo/forgejo/pulls/2834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 1 This PR needs approval from one additional maintainer to be merged. modifies/internal size/M Denotes a PR that changes 30-99 lines, ignoring generated files. topic/code-linting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants