Skip to content

Commit 714862f

Browse files
authored
Merge pull request gopherjs#1207 from gopherjs/gofumpt
gofumpt the repo
2 parents aa25f6c + 0e53da9 commit 714862f

31 files changed

+132
-81
lines changed

.github/workflows/lint.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: golangci-lint
2+
on:
3+
pull_request:
4+
permissions:
5+
contents: read
6+
jobs:
7+
golangci:
8+
name: lint
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- uses: actions/setup-go@v3
14+
with:
15+
go-version: "1.18.10"
16+
17+
- name: golangci-lint
18+
uses: golangci/golangci-lint-action@v3
19+
with:
20+
version: v1.53.3
21+
only-new-issues: true
22+
23+
- name: Check go.mod
24+
run: |
25+
go mod tidy && git diff --exit-code

.golangci.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[run]
2+
timeout = "1m"
3+
4+
[output]
5+
format = "colored-line-number"
6+
7+
[linters]
8+
disable-all = true
9+
enable = [
10+
"gofumpt",
11+
]
12+
13+
[issues]
14+
exclude-use-default = false

build/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ func (s *Session) SourceMappingCallback(m *sourcemap.Map) func(generatedLine, ge
730730

731731
// WriteCommandPackage writes the final JavaScript output file at pkgObj path.
732732
func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string) error {
733-
if err := os.MkdirAll(filepath.Dir(pkgObj), 0777); err != nil {
733+
if err := os.MkdirAll(filepath.Dir(pkgObj), 0o777); err != nil {
734734
return err
735735
}
736736
codeFile, err := os.Create(pkgObj)

build/cache/cache.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (bc *BuildCache) StoreArchive(a *compiler.Archive) {
9595
return // Caching is disabled.
9696
}
9797
path := cachedPath(bc.archiveKey(a.ImportPath))
98-
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
98+
if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
9999
log.Warningf("Failed to create build cache directory: %v", err)
100100
return
101101
}

build/embed.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ func embedFiles(pkg *PackageData, fset *token.FileSet, files []*ast.File) (*ast.
5555
&ast.CallExpr{
5656
Fun: em.Spec.Type,
5757
Args: []ast.Expr{
58-
&ast.Ident{Name: buildIdent(fs[0].Name),
59-
NamePos: em.Spec.Names[0].NamePos},
58+
&ast.Ident{
59+
Name: buildIdent(fs[0].Name),
60+
NamePos: em.Spec.Names[0].NamePos,
61+
},
6062
},
61-
}}
63+
},
64+
}
6265
case goembed.EmbedBytes:
6366
// value = []byte(data)
6467
em.Spec.Values = []ast.Expr{
6568
&ast.CallExpr{
6669
Fun: em.Spec.Type,
6770
Args: []ast.Expr{ast.NewIdent(buildIdent(fs[0].Name))},
68-
}}
71+
},
72+
}
6973
case goembed.EmbedString:
7074
// value = data
7175
em.Spec.Values = []ast.Expr{ast.NewIdent(buildIdent(fs[0].Name))}
@@ -115,15 +119,15 @@ func embedFiles(pkg *PackageData, fset *token.FileSet, files []*ast.File) (*ast.
115119
Elt: &ast.StructType{
116120
Fields: &ast.FieldList{
117121
List: []*ast.Field{
118-
&ast.Field{
122+
{
119123
Names: []*ast.Ident{ast.NewIdent("name")},
120124
Type: ast.NewIdent("string"),
121125
},
122-
&ast.Field{
126+
{
123127
Names: []*ast.Ident{ast.NewIdent("data")},
124128
Type: ast.NewIdent("string"),
125129
},
126-
&ast.Field{
130+
{
127131
Names: []*ast.Ident{ast.NewIdent("hash")},
128132
Type: &ast.ArrayType{
129133
Len: &ast.BasicLit{Kind: token.INT, Value: "16"},

circle.yml

-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ jobs:
7272
executor: gopherjs
7373
steps:
7474
- setup_and_install_gopherjs
75-
- run:
76-
name: Check gofmt
77-
command: diff -u <(echo -n) <(gofmt -d .)
7875
- run:
7976
name: Check go vet
8077
command: |

compiler/compiler.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import (
2121
"golang.org/x/tools/go/gcexportdata"
2222
)
2323

24-
var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
25-
var reservedKeywords = make(map[string]bool)
24+
var (
25+
sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
26+
reservedKeywords = make(map[string]bool)
27+
)
2628

2729
func init() {
2830
for _, keyword := range []string{"abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "undefined", "var", "void", "volatile", "while", "with", "yield"} {

compiler/natives/src/embed/embed.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ func buildFS(list []struct {
77
name string
88
data string
99
hash [16]byte
10-
}) (f FS) {
10+
},
11+
) (f FS) {
1112
n := len(list)
1213
files := make([]file, n)
1314
for i := 0; i < n; i++ {

compiler/natives/src/encoding/gob/gob_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func TestEndToEnd(t *testing.T) {
6868
// TODO: Fix this problem:
6969
// TypeError: dst.$set is not a function
7070
// at typedmemmove (/github.com/gopherjs/gopherjs/reflect.go:487:3)
71-
//Marr: map[[2]string][2]*float64{arr1: floatArr1, arr2: floatArr2},
71+
// Marr: map[[2]string][2]*float64{arr1: floatArr1, arr2: floatArr2},
7272
EmptyMap: make(map[string]int),
7373
N: &[3]float64{1.5, 2.5, 3.5},
7474
Strs: &[2]string{s1, s2},

compiler/natives/src/internal/reflectlite/all_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
package reflectlite_test
55

66
import (
7-
. "internal/reflectlite"
87
"testing"
8+
9+
. "internal/reflectlite"
910
)
1011

1112
func TestTypes(t *testing.T) {

compiler/natives/src/internal/reflectlite/reflectlite.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ func init() {
3232
uint8Type = TypeOf(uint8(0)).(*rtype) // set for real
3333
}
3434

35-
var (
36-
uint8Type *rtype
37-
)
35+
var uint8Type *rtype
3836

3937
var (
4038
idJsType = "_jsType"
@@ -578,7 +576,7 @@ func maplen(m unsafe.Pointer) int {
578576
}
579577

580578
func cvtDirect(v Value, typ Type) Value {
581-
var srcVal = v.object()
579+
srcVal := v.object()
582580
if srcVal == jsType(v.typ).Get("nil") {
583581
return makeValue(typ, jsType(typ).Get("nil"), v.flag)
584582
}
@@ -914,7 +912,7 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool {
914912
return true
915913
}
916914
}
917-
var n = v1.Len()
915+
n := v1.Len()
918916
if n != v2.Len() {
919917
return false
920918
}
@@ -932,7 +930,7 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool {
932930
case Ptr:
933931
return deepValueEqualJs(v1.Elem(), v2.Elem(), visited)
934932
case Struct:
935-
var n = v1.NumField()
933+
n := v1.NumField()
936934
for i := 0; i < n; i++ {
937935
if !deepValueEqualJs(v1.Field(i), v2.Field(i), visited) {
938936
return false
@@ -946,7 +944,7 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool {
946944
if v1.object() == v2.object() {
947945
return true
948946
}
949-
var keys = v1.MapKeys()
947+
keys := v1.MapKeys()
950948
if len(keys) != v2.Len() {
951949
return false
952950
}

compiler/natives/src/internal/reflectlite/utils.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ func (e *errorString) Error() string {
2323
return e.s
2424
}
2525

26-
var (
27-
ErrSyntax = &errorString{"invalid syntax"}
28-
)
26+
var ErrSyntax = &errorString{"invalid syntax"}
2927

3028
func unquote(s string) (string, error) {
3129
if len(s) < 2 {

compiler/natives/src/math/math.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import (
77
"github.com/gopherjs/gopherjs/js"
88
)
99

10-
var math = js.Global.Get("Math")
11-
var _zero float64 = 0
12-
var posInf = 1 / _zero
13-
var negInf = -1 / _zero
10+
var (
11+
math = js.Global.Get("Math")
12+
_zero float64 = 0
13+
posInf = 1 / _zero
14+
negInf = -1 / _zero
15+
)
1416

1517
// Usually, NaN can be obtained in JavaScript with `0 / 0` operation. However,
1618
// in V8, `0 / _zero` yields a bitwise-different value of NaN compared to the

compiler/natives/src/net/netip/export_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package netip
44

55
import (
66
"fmt"
7+
78
"internal/intern"
89
)
910

compiler/natives/src/reflect/reflect_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestIssue22073(t *testing.T) {
157157
// TypeError: Cannot read property 'apply' of undefined
158158

159159
// Shouldn't panic.
160-
//m.Call(nil)
160+
// m.Call(nil)
161161
}
162162

163163
func TestCallReturnsEmpty(t *testing.T) {

compiler/natives/src/runtime/runtime.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"github.com/gopherjs/gopherjs/js"
88
)
99

10-
const GOOS = "js"
11-
const GOARCH = "ecmascript"
12-
const Compiler = "gopherjs"
10+
const (
11+
GOOS = "js"
12+
GOARCH = "ecmascript"
13+
Compiler = "gopherjs"
14+
)
1315

1416
// The Error interface identifies a run time error.
1517
type Error interface {

compiler/natives/src/sync/pool_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func TestPool(t *testing.T) {
2424
t.Fatalf("Got: p.Get() returned: %s. Want: %s.", got, want)
2525
}
2626
}
27-
2827
}
2928

3029
func TestPoolGC(t *testing.T) {

compiler/natives/src/syscall/legacy.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"github.com/gopherjs/gopherjs/js"
77
)
88

9-
var syscallModule *js.Object
10-
var alreadyTriedToLoad = false
11-
var minusOne = -1
9+
var (
10+
syscallModule *js.Object
11+
alreadyTriedToLoad = false
12+
minusOne = -1
13+
)
1214

1315
var warningPrinted = false
1416

compiler/prelude/prelude.go

-1
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ func Minified() string {
4545
log.Fatalf("Prelude minification failed with %d errors", errCount)
4646
}
4747
return string(result.Code)
48-
4948
}

tests/arrays_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ func TestArrayPointer(t *testing.T) {
7474
})
7575

7676
t.Run("reflect.IsNil", func(t *testing.T) {
77-
7877
})
7978
}
8079

tests/copy_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (t T) M() int {
125125
}
126126

127127
func TestExplicitConversion(t *testing.T) {
128-
var coolGuy = S{x: 42}
128+
coolGuy := S{x: 42}
129129
var i I
130130
i = T(coolGuy)
131131
if i.M() != 42 {
@@ -138,7 +138,7 @@ func TestCopyStructByReflect(t *testing.T) {
138138
type Info struct {
139139
name string
140140
}
141-
a := []Info{Info{"A"}, Info{"B"}, Info{"C"}}
141+
a := []Info{{"A"}, {"B"}, {"C"}}
142142
v := reflect.ValueOf(a)
143143
i := v.Index(0).Interface()
144144
a[0] = Info{"X"}

tests/deferblock_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestBlockingInDefer(t *testing.T) {
4545

4646
func TestIssue1083(t *testing.T) {
4747
// https://github.com/gopherjs/gopherjs/issues/1083
48-
var block = make(chan bool)
48+
block := make(chan bool)
4949

5050
recoverCompleted := false
5151

tests/gorepo/run.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ func (t *test) run() {
683683
t.makeTempDir()
684684
defer os.RemoveAll(t.tempDir)
685685

686-
err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644)
686+
err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0o644)
687687
check(err)
688688

689689
// A few tests (of things like the environment) require these to be set.
@@ -855,7 +855,7 @@ func (t *test) run() {
855855
return
856856
}
857857
tfile := filepath.Join(t.tempDir, "tmp__.go")
858-
if err := ioutil.WriteFile(tfile, out, 0666); err != nil {
858+
if err := ioutil.WriteFile(tfile, out, 0o666); err != nil {
859859
t.err = fmt.Errorf("write tempfile:%s", err)
860860
return
861861
}
@@ -876,7 +876,7 @@ func (t *test) run() {
876876
return
877877
}
878878
tfile := filepath.Join(t.tempDir, "tmp__.go")
879-
err = ioutil.WriteFile(tfile, out, 0666)
879+
err = ioutil.WriteFile(tfile, out, 0o666)
880880
if err != nil {
881881
t.err = fmt.Errorf("write tempfile:%s", err)
882882
return
@@ -1079,7 +1079,7 @@ func (t *test) updateErrors(out string, file string) {
10791079
}
10801080
}
10811081
// Write new file.
1082-
err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0640)
1082+
err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0o640)
10831083
if err != nil {
10841084
fmt.Fprintln(os.Stderr, err)
10851085
return

tests/js_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func TestDate(t *testing.T) {
294294

295295
// https://github.com/gopherjs/gopherjs/issues/287
296296
func TestInternalizeDate(t *testing.T) {
297-
var a = time.Unix(0, (123 * time.Millisecond).Nanoseconds())
297+
a := time.Unix(0, (123 * time.Millisecond).Nanoseconds())
298298
var b time.Time
299299
js.Global.Set("internalizeDate", func(t time.Time) { b = t })
300300
js.Global.Call("eval", "(internalizeDate(new Date(123)))")
@@ -478,7 +478,6 @@ func TestMakeWrapper(t *testing.T) {
478478
if js.MakeWrapper(m).Interface() != m {
479479
t.Fail()
480480
}
481-
482481
}
483482

484483
func TestMakeFullWrapperType(t *testing.T) {
@@ -502,7 +501,7 @@ func TestMakeFullWrapperGettersAndSetters(t *testing.T) {
502501
Name: "Gopher",
503502
Struct: F{Field: 42},
504503
Pointer: f,
505-
Array: [1]F{F{Field: 42}},
504+
Array: [1]F{{Field: 42}},
506505
Slice: []*F{f},
507506
}
508507

@@ -731,7 +730,6 @@ func TestExternalize(t *testing.T) {
731730
if result != tt.want {
732731
t.Errorf("Unexpected result %q != %q", result, tt.want)
733732
}
734-
735733
})
736734
}
737735
}

0 commit comments

Comments
 (0)