Skip to content

Commit 81b6cff

Browse files
committed
Add gopls modernize formatting
1 parent 0e477b5 commit 81b6cff

File tree

242 files changed

+458
-778
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+458
-778
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@v1
3838
ACTIONLINT_PACKAGE ?= github.com/rhysd/actionlint/cmd/actionlint@v1
39-
GOPLS_PACKAGE ?= golang.org/x/tools/[email protected]
39+
GOPLS_PACKAGE ?= golang.org/x/tools/[email protected]
40+
GOPLS_MODERNIZE_PACKAGE ?= golang.org/x/tools/gopls/internal/analysis/modernize/cmd/[email protected]
4041

4142
DOCKER_IMAGE ?= gitea/gitea
4243
DOCKER_TAG ?= latest
@@ -247,6 +248,7 @@ fmt: ## format the Go code
247248
-e 's/{{[ ]\{1,\}/{{/g' -e '/^[ ]\{1,\}}}/! s/[ ]\{1,\}}}/}}/g' \
248249
-e 's/([ ]\{1,\}/(/g' -e '/^[ ]\{1,\})/! s/[ ]\{1,\})/)/g' \
249250
$(TEMPLATES)
251+
@$(GO) run $(GOPLS_MODERNIZE_PACKAGE) -fix ./...
250252

251253
.PHONY: fmt-check
252254
fmt-check: fmt
@@ -373,8 +375,8 @@ lint-go-vet: ## lint go files with vet
373375

374376
.PHONY: lint-go-gopls
375377
lint-go-gopls: ## lint go files with gopls
376-
@echo "Running gopls check..."
377-
@GO=$(GO) GOPLS_PACKAGE=$(GOPLS_PACKAGE) tools/lint-go-gopls.sh $(GO_SOURCES_NO_BINDATA)
378+
@echo "Running gopls..."
379+
@GO=$(GO) GOPLS_PACKAGE=$(GOPLS_PACKAGE) GOPLS_MODERNIZE_PACKAGE=$(GOPLS_MODERNIZE_PACKAGE) tools/lint-go-gopls.sh $(GO_SOURCES_NO_BINDATA)
378380

379381
.PHONY: lint-editorconfig
380382
lint-editorconfig:

cmd/cert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ func runCert(c *cli.Context) error {
146146
BasicConstraintsValid: true,
147147
}
148148

149-
hosts := strings.Split(c.String("host"), ",")
150-
for _, h := range hosts {
149+
hosts := strings.SplitSeq(c.String("host"), ",")
150+
for h := range hosts {
151151
if ip := net.ParseIP(h); ip != nil {
152152
template.IPAddresses = append(template.IPAddresses, ip)
153153
} else {

cmd/doctor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func runRecreateTable(ctx *cli.Context) error {
120120

121121
args := ctx.Args()
122122
names := make([]string, 0, ctx.NArg())
123-
for i := 0; i < ctx.NArg(); i++ {
123+
for i := range ctx.NArg() {
124124
names = append(names, args.Get(i))
125125
}
126126

cmd/dump_repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ func runDumpRepository(ctx *cli.Context) error {
135135
opts.PullRequests = true
136136
opts.ReleaseAssets = true
137137
} else {
138-
units := strings.Split(ctx.String("units"), ",")
139-
for _, unit := range units {
138+
units := strings.SplitSeq(ctx.String("units"), ",")
139+
for unit := range units {
140140
switch strings.ToLower(strings.TrimSpace(unit)) {
141141
case "":
142142
continue

cmd/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ func hookPrintResult(output, isCreate bool, branch, url string) {
485485
func pushOptions() map[string]string {
486486
opts := make(map[string]string)
487487
if pushCount, err := strconv.Atoi(os.Getenv(private.GitPushOptionCount)); err == nil {
488-
for idx := 0; idx < pushCount; idx++ {
488+
for idx := range pushCount {
489489
opt := os.Getenv(fmt.Sprintf("GIT_PUSH_OPTION_%d", idx))
490490
kv := strings.SplitN(opt, "=", 2)
491491
if len(kv) == 2 {
@@ -740,7 +740,7 @@ func readPktLine(ctx context.Context, in *bufio.Reader, requestType pktLineType)
740740

741741
// read prefix
742742
lengthBytes := make([]byte, 4)
743-
for i := 0; i < 4; i++ {
743+
for i := range 4 {
744744
lengthBytes[i], err = in.ReadByte()
745745
if err != nil {
746746
return nil, fail(ctx, "Protocol: stdin error", "Pkt-Line: read stdin failed : %v", err)

cmd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66
import (
77
"fmt"
88
"os"
9+
"slices"
910
"strings"
1011

1112
"code.gitea.io/gitea/modules/log"
@@ -75,7 +76,7 @@ func appGlobalFlags() []cli.Flag {
7576
}
7677

7778
func prepareSubcommandWithConfig(command *cli.Command, globalFlags []cli.Flag) {
78-
command.Flags = append(append([]cli.Flag{}, globalFlags...), command.Flags...)
79+
command.Flags = slices.Concat(globalFlags, command.Flags)
7980
command.Action = prepareWorkPathAndCustomConf(command.Action)
8081
command.HideHelp = true
8182
if command.Name != "help" {

contrib/backport/backport.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ func determineRemote(ctx context.Context, forkUser string) (string, string, erro
342342
fmt.Fprintf(os.Stderr, "Unable to list git remotes:\n%s\n", string(out))
343343
return "", "", fmt.Errorf("unable to determine forked remote: %w", err)
344344
}
345-
lines := strings.Split(string(out), "\n")
346-
for _, line := range lines {
345+
lines := strings.SplitSeq(string(out), "\n")
346+
for line := range lines {
347347
fields := strings.Split(line, "\t")
348348
name, remote := fields[0], fields[1]
349349
// only look at pushers

contrib/environment-to-ini/environment-to-ini.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func main() {
8080

8181
func runEnvironmentToIni(c *cli.Context) error {
8282
// the config system may change the environment variables, so get a copy first, to be used later
83-
env := append([]string{}, os.Environ()...)
83+
env := os.Environ()
8484
setting.InitWorkPathAndCfgProvider(os.Getenv, setting.ArgWorkPathAndCustomConf{
8585
WorkPath: c.String("work-path"),
8686
CustomPath: c.String("custom-path"),

models/actions/status.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package actions
55

66
import (
7+
"slices"
8+
79
"code.gitea.io/gitea/modules/translation"
810

911
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
@@ -88,12 +90,7 @@ func (s Status) IsBlocked() bool {
8890

8991
// In returns whether s is one of the given statuses
9092
func (s Status) In(statuses ...Status) bool {
91-
for _, v := range statuses {
92-
if s == v {
93-
return true
94-
}
95-
}
96-
return false
93+
return slices.Contains(statuses, s)
9794
}
9895

9996
func (s Status) AsResult() runnerv1.Result {

models/activities/action.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"net/url"
1111
"path"
12+
"slices"
1213
"strconv"
1314
"strings"
1415
"time"
@@ -127,12 +128,7 @@ func (at ActionType) String() string {
127128
}
128129

129130
func (at ActionType) InActions(actions ...string) bool {
130-
for _, action := range actions {
131-
if action == at.String() {
132-
return true
133-
}
134-
}
135-
return false
131+
return slices.Contains(actions, at.String())
136132
}
137133

138134
// Action represents user operation type and other information to

0 commit comments

Comments
 (0)