Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gofumpt the repo #1207

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

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: golangci-lint
on:
pull_request:
permissions:
contents: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: "1.18.10"

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.3
only-new-issues: true

- name: Check go.mod
run: |
go mod tidy && git diff --exit-code
14 changes: 14 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[run]
timeout = "1m"

[output]
format = "colored-line-number"

[linters]
disable-all = true
enable = [
"gofumpt",
]

[issues]
exclude-use-default = false
2 changes: 1 addition & 1 deletion build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ func (s *Session) SourceMappingCallback(m *sourcemap.Map) func(generatedLine, ge

// WriteCommandPackage writes the final JavaScript output file at pkgObj path.
func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string) error {
if err := os.MkdirAll(filepath.Dir(pkgObj), 0777); err != nil {
if err := os.MkdirAll(filepath.Dir(pkgObj), 0o777); err != nil {
return err
}
codeFile, err := os.Create(pkgObj)
Expand Down
2 changes: 1 addition & 1 deletion build/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (bc *BuildCache) StoreArchive(a *compiler.Archive) {
return // Caching is disabled.
}
path := cachedPath(bc.archiveKey(a.ImportPath))
if err := os.MkdirAll(filepath.Dir(path), 0750); err != nil {
if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
log.Warningf("Failed to create build cache directory: %v", err)
return
}
Expand Down
18 changes: 11 additions & 7 deletions build/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,21 @@ func embedFiles(pkg *PackageData, fset *token.FileSet, files []*ast.File) (*ast.
&ast.CallExpr{
Fun: em.Spec.Type,
Args: []ast.Expr{
&ast.Ident{Name: buildIdent(fs[0].Name),
NamePos: em.Spec.Names[0].NamePos},
&ast.Ident{
Name: buildIdent(fs[0].Name),
NamePos: em.Spec.Names[0].NamePos,
},
},
}}
},
}
case goembed.EmbedBytes:
// value = []byte(data)
em.Spec.Values = []ast.Expr{
&ast.CallExpr{
Fun: em.Spec.Type,
Args: []ast.Expr{ast.NewIdent(buildIdent(fs[0].Name))},
}}
},
}
case goembed.EmbedString:
// value = data
em.Spec.Values = []ast.Expr{ast.NewIdent(buildIdent(fs[0].Name))}
Expand Down Expand Up @@ -115,15 +119,15 @@ func embedFiles(pkg *PackageData, fset *token.FileSet, files []*ast.File) (*ast.
Elt: &ast.StructType{
Fields: &ast.FieldList{
List: []*ast.Field{
&ast.Field{
{
Names: []*ast.Ident{ast.NewIdent("name")},
Type: ast.NewIdent("string"),
},
&ast.Field{
{
Names: []*ast.Ident{ast.NewIdent("data")},
Type: ast.NewIdent("string"),
},
&ast.Field{
{
Names: []*ast.Ident{ast.NewIdent("hash")},
Type: &ast.ArrayType{
Len: &ast.BasicLit{Kind: token.INT, Value: "16"},
Expand Down
3 changes: 0 additions & 3 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ jobs:
executor: gopherjs
steps:
- setup_and_install_gopherjs
- run:
name: Check gofmt
command: diff -u <(echo -n) <(gofmt -d .)
- run:
name: Check go vet
command: |
Expand Down
6 changes: 4 additions & 2 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"golang.org/x/tools/go/gcexportdata"
)

var sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
var reservedKeywords = make(map[string]bool)
var (
sizes32 = &types.StdSizes{WordSize: 4, MaxAlign: 8}
reservedKeywords = make(map[string]bool)
)

func init() {
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"} {
Expand Down
3 changes: 2 additions & 1 deletion compiler/natives/src/embed/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ func buildFS(list []struct {
name string
data string
hash [16]byte
}) (f FS) {
},
) (f FS) {
n := len(list)
files := make([]file, n)
for i := 0; i < n; i++ {
Expand Down
2 changes: 1 addition & 1 deletion compiler/natives/src/encoding/gob/gob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestEndToEnd(t *testing.T) {
// TODO: Fix this problem:
// TypeError: dst.$set is not a function
// at typedmemmove (/github.com/gopherjs/gopherjs/reflect.go:487:3)
//Marr: map[[2]string][2]*float64{arr1: floatArr1, arr2: floatArr2},
// Marr: map[[2]string][2]*float64{arr1: floatArr1, arr2: floatArr2},
EmptyMap: make(map[string]int),
N: &[3]float64{1.5, 2.5, 3.5},
Strs: &[2]string{s1, s2},
Expand Down
3 changes: 2 additions & 1 deletion compiler/natives/src/internal/reflectlite/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
package reflectlite_test

import (
. "internal/reflectlite"
"testing"

. "internal/reflectlite"
)

func TestTypes(t *testing.T) {
Expand Down
12 changes: 5 additions & 7 deletions compiler/natives/src/internal/reflectlite/reflectlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func init() {
uint8Type = TypeOf(uint8(0)).(*rtype) // set for real
}

var (
uint8Type *rtype
)
var uint8Type *rtype

var (
idJsType = "_jsType"
Expand Down Expand Up @@ -578,7 +576,7 @@ func maplen(m unsafe.Pointer) int {
}

func cvtDirect(v Value, typ Type) Value {
var srcVal = v.object()
srcVal := v.object()
if srcVal == jsType(v.typ).Get("nil") {
return makeValue(typ, jsType(typ).Get("nil"), v.flag)
}
Expand Down Expand Up @@ -914,7 +912,7 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool {
return true
}
}
var n = v1.Len()
n := v1.Len()
if n != v2.Len() {
return false
}
Expand All @@ -932,7 +930,7 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool {
case Ptr:
return deepValueEqualJs(v1.Elem(), v2.Elem(), visited)
case Struct:
var n = v1.NumField()
n := v1.NumField()
for i := 0; i < n; i++ {
if !deepValueEqualJs(v1.Field(i), v2.Field(i), visited) {
return false
Expand All @@ -946,7 +944,7 @@ func deepValueEqualJs(v1, v2 Value, visited [][2]unsafe.Pointer) bool {
if v1.object() == v2.object() {
return true
}
var keys = v1.MapKeys()
keys := v1.MapKeys()
if len(keys) != v2.Len() {
return false
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/natives/src/internal/reflectlite/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func (e *errorString) Error() string {
return e.s
}

var (
ErrSyntax = &errorString{"invalid syntax"}
)
var ErrSyntax = &errorString{"invalid syntax"}

func unquote(s string) (string, error) {
if len(s) < 2 {
Expand Down
10 changes: 6 additions & 4 deletions compiler/natives/src/math/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (
"github.com/gopherjs/gopherjs/js"
)

var math = js.Global.Get("Math")
var _zero float64 = 0
var posInf = 1 / _zero
var negInf = -1 / _zero
var (
math = js.Global.Get("Math")
_zero float64 = 0
posInf = 1 / _zero
negInf = -1 / _zero
)

// Usually, NaN can be obtained in JavaScript with `0 / 0` operation. However,
// in V8, `0 / _zero` yields a bitwise-different value of NaN compared to the
Expand Down
1 change: 1 addition & 0 deletions compiler/natives/src/net/netip/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package netip

import (
"fmt"

"internal/intern"
)

Expand Down
2 changes: 1 addition & 1 deletion compiler/natives/src/reflect/reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestIssue22073(t *testing.T) {
// TypeError: Cannot read property 'apply' of undefined

// Shouldn't panic.
//m.Call(nil)
// m.Call(nil)
}

func TestCallReturnsEmpty(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions compiler/natives/src/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"github.com/gopherjs/gopherjs/js"
)

const GOOS = "js"
const GOARCH = "ecmascript"
const Compiler = "gopherjs"
const (
GOOS = "js"
GOARCH = "ecmascript"
Compiler = "gopherjs"
)

// The Error interface identifies a run time error.
type Error interface {
Expand Down
1 change: 0 additions & 1 deletion compiler/natives/src/sync/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestPool(t *testing.T) {
t.Fatalf("Got: p.Get() returned: %s. Want: %s.", got, want)
}
}

}

func TestPoolGC(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions compiler/natives/src/syscall/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"github.com/gopherjs/gopherjs/js"
)

var syscallModule *js.Object
var alreadyTriedToLoad = false
var minusOne = -1
var (
syscallModule *js.Object
alreadyTriedToLoad = false
minusOne = -1
)

var warningPrinted = false

Expand Down
1 change: 0 additions & 1 deletion compiler/prelude/prelude.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,4 @@ func Minified() string {
log.Fatalf("Prelude minification failed with %d errors", errCount)
}
return string(result.Code)

}
1 change: 0 additions & 1 deletion tests/arrays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func TestArrayPointer(t *testing.T) {
})

t.Run("reflect.IsNil", func(t *testing.T) {

})
}

Expand Down
4 changes: 2 additions & 2 deletions tests/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (t T) M() int {
}

func TestExplicitConversion(t *testing.T) {
var coolGuy = S{x: 42}
coolGuy := S{x: 42}
var i I
i = T(coolGuy)
if i.M() != 42 {
Expand All @@ -138,7 +138,7 @@ func TestCopyStructByReflect(t *testing.T) {
type Info struct {
name string
}
a := []Info{Info{"A"}, Info{"B"}, Info{"C"}}
a := []Info{{"A"}, {"B"}, {"C"}}
v := reflect.ValueOf(a)
i := v.Index(0).Interface()
a[0] = Info{"X"}
Expand Down
2 changes: 1 addition & 1 deletion tests/deferblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestBlockingInDefer(t *testing.T) {

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

recoverCompleted := false

Expand Down
8 changes: 4 additions & 4 deletions tests/gorepo/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ func (t *test) run() {
t.makeTempDir()
defer os.RemoveAll(t.tempDir)

err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0644)
err = ioutil.WriteFile(filepath.Join(t.tempDir, t.gofile), srcBytes, 0o644)
check(err)

// A few tests (of things like the environment) require these to be set.
Expand Down Expand Up @@ -855,7 +855,7 @@ func (t *test) run() {
return
}
tfile := filepath.Join(t.tempDir, "tmp__.go")
if err := ioutil.WriteFile(tfile, out, 0666); err != nil {
if err := ioutil.WriteFile(tfile, out, 0o666); err != nil {
t.err = fmt.Errorf("write tempfile:%s", err)
return
}
Expand All @@ -876,7 +876,7 @@ func (t *test) run() {
return
}
tfile := filepath.Join(t.tempDir, "tmp__.go")
err = ioutil.WriteFile(tfile, out, 0666)
err = ioutil.WriteFile(tfile, out, 0o666)
if err != nil {
t.err = fmt.Errorf("write tempfile:%s", err)
return
Expand Down Expand Up @@ -1079,7 +1079,7 @@ func (t *test) updateErrors(out string, file string) {
}
}
// Write new file.
err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0640)
err = ioutil.WriteFile(file, []byte(strings.Join(lines, "\n")), 0o640)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
Expand Down
6 changes: 2 additions & 4 deletions tests/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestDate(t *testing.T) {

// https://github.com/gopherjs/gopherjs/issues/287
func TestInternalizeDate(t *testing.T) {
var a = time.Unix(0, (123 * time.Millisecond).Nanoseconds())
a := time.Unix(0, (123 * time.Millisecond).Nanoseconds())
var b time.Time
js.Global.Set("internalizeDate", func(t time.Time) { b = t })
js.Global.Call("eval", "(internalizeDate(new Date(123)))")
Expand Down Expand Up @@ -478,7 +478,6 @@ func TestMakeWrapper(t *testing.T) {
if js.MakeWrapper(m).Interface() != m {
t.Fail()
}

}

func TestMakeFullWrapperType(t *testing.T) {
Expand All @@ -502,7 +501,7 @@ func TestMakeFullWrapperGettersAndSetters(t *testing.T) {
Name: "Gopher",
Struct: F{Field: 42},
Pointer: f,
Array: [1]F{F{Field: 42}},
Array: [1]F{{Field: 42}},
Slice: []*F{f},
}

Expand Down Expand Up @@ -731,7 +730,6 @@ func TestExternalize(t *testing.T) {
if result != tt.want {
t.Errorf("Unexpected result %q != %q", result, tt.want)
}

})
}
}
Expand Down
Loading