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 golangci #6418

Merged
merged 119 commits into from
Jun 12, 2019
Merged

Add golangci #6418

merged 119 commits into from
Jun 12, 2019

Conversation

kolaente
Copy link
Member

This pr adds golangci to Gitea and replaces some linters (which golangci contains). This will (hopefully) enhance code quality.

Golangci lint calls a lot of golang lint tools directly, which make it a lot faster.

@kolaente
Copy link
Member Author

Looks like the new ci step works, now we just have to fix all the issues.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 23, 2019
@kolaente
Copy link
Member Author

kolaente commented Mar 24, 2019

Fixed most of the issues, however there are some issues where I don't really know what to do:

  • [ ]
modules/indexer/issues/indexer.go:95:32: Error return value of `issueIndexerUpdateQueue.Run` is not checked (errcheck)
        go issueIndexerUpdateQueue.Run()
                                      ^

It looks like issueIndexerUpdateQueue.Run() doesn't return an error in any of its implementations. Could we just remove the error return?

  • Fixed from the hint by @lunny.
models/git_diff.go:387:2: S1001: should use copy() instead of a loop (gosimple)
        for idx, lof := range hunk[:headerLines] {
        ^

I don't know how it is possible to let copy only copy some parts of a slice.

  • Done
models/repo_list.go:149:2: SA9004: only the first constant in this group has an explicit type (staticcheck)
        SearchOrderByAlphabetically        SearchOrderBy = "name ASC"
        ^

I don't really think this is an issue... or is it?

  • @jonasfranz said the check isn't needed at all, so I removed it completly.
routers/user/oauth.go:166:2: SA4006: this value of `errs` is never used (staticcheck)
        errs = form.Validate(ctx.Context, errs)
        ^

If the errors are not checked, can the whole check be removed? Or how can we check for the error?

# Conflicts:
#	models/repo_permission.go
@lunny
Copy link
Member

lunny commented Mar 25, 2019

@kolaente Is golangci support gitea? Since we will host gitea on gitea.com. If golangci don't support gitea, it will not work.

@kolaente
Copy link
Member Author

kolaente commented Mar 25, 2019

@lunny It's just a binary file which runs locally and in drone. Since we run it on our own infrastructure, we're not tied to a particular platform.

IIRC they offer tight ingration with github (things like having a bot which comments on the pr instead of just failing the pipeline) which we won't have. But I see no problem with it just failing the pipeline.

@kolaente
Copy link
Member Author

Just merged with Gitea's master, it did containt a lot of new issues which had to be fixed...

.drone.yml Outdated Show resolved Hide resolved
Copy link
Member

@sapk sapk left a comment

Choose a reason for hiding this comment

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

That a lot of missed error checking and more could still be logged in goroutine or defer. This will really improve the codebase and review.
LGTM, I would suggest to disable most of the linter that still failed and manage to enable them one at a time in separates PRs. This will ease the process of review and limit the number of conflict appearing.

@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 3, 2019
Copy link
Member

@sapk sapk left a comment

Choose a reason for hiding this comment

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

Found one template file to be removed

routers/user/profile.go Show resolved Hide resolved
@kolaente
Copy link
Member Author

kolaente commented Apr 6, 2019

@sapk I think we need to enable these now, I doubt there will be other prs soon otherwise...

models/release.go Outdated Show resolved Hide resolved
models/release.go Outdated Show resolved Hide resolved
@zeripath
Copy link
Contributor

zeripath commented Jun 6, 2019

thanks @kolaente !

@lunny
Copy link
Member

lunny commented Jun 8, 2019

conflicted

@kolaente
Copy link
Member Author

kolaente commented Jun 9, 2019

@lunny fixed.

@kolaente
Copy link
Member Author

@lunny @sapk please approve.

issue.LoadRepo()
err := issue.LoadRepo()
if err != nil {
log.Error("LoadRepo: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

This function should return error as second return parameter I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is it is called in SendAsync which just puts the mail in a queue to be sent. There's not much room for error handling there.

Copy link
Member

Choose a reason for hiding this comment

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

Or we have to return nil here, otherwise it may panic when invoke issue.Repo.HTMLURL().

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with this function is the error could never really be handled appropriatly. It would only be bubbled up to then be logged.
I would prefer to leave it as it is, to not having to deal with more complexty bubbling the error up would bring.

models/repo_redirect.go Show resolved Hide resolved
modules/git/repo.go Outdated Show resolved Hide resolved
modules/git/repo_compare.go Show resolved Hide resolved
modules/log/colors.go Outdated Show resolved Hide resolved
modules/pprof/pprof.go Outdated Show resolved Hide resolved
modules/repofiles/update.go Show resolved Hide resolved
modules/templates/helper.go Show resolved Hide resolved
routers/user/oauth.go Show resolved Hide resolved
routers/user/oauth.go Outdated Show resolved Hide resolved
routers/user/setting/profile.go Outdated Show resolved Hide resolved
cmd/serv.go Outdated Show resolved Hide resolved
jonasfranz and others added 2 commits June 11, 2019 20:56
Signed-off-by: konrad <konrad@kola-entertainments.de>
@techknowlogick techknowlogick merged commit f9ec2f8 into go-gitea:master Jun 12, 2019
@kolaente kolaente deleted the golanci branch June 12, 2019 21:22
@Cherrg Cherrg mentioned this pull request Jun 13, 2019
jeffliu27 pushed a commit to jeffliu27/gitea that referenced this pull request Jul 18, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.