From 7cd152df7cdfae2fbc7fe969b0082ad5dbcd06ab Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 4 Jun 2022 14:59:09 +0300 Subject: [PATCH] Format project with gofumpt --- README.md | 2 +- cmd/cdpgen/main.go | 6 +++--- cmd/cdpgen/proto/proto.go | 9 ++++++--- devtool/devtool_test.go | 4 ++-- example/screencast/main.go | 2 +- example_test.go | 2 +- internal/errors/errors.go | 16 ++++++++++------ protocol/internal/error.go | 6 ++++-- protocol/io/stream_reader.go | 7 +++---- protocol/io/stream_reder_test.go | 1 + protocol/runtime/util.go | 4 +--- protocol/runtime/util_test.go | 2 +- rpcc/conn.go | 12 ++++-------- rpcc/socket.go | 4 +--- rpcc/socket_test.go | 3 +++ rpcc/stream.go | 8 +++----- rpcc/stream_test.go | 1 - session/session_test.go | 4 +--- 18 files changed, 46 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 6f0c279..5f758d6 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ func run(timeout time.Duration) error { if err != nil { return err } - if err = ioutil.WriteFile(screenshotName, screenshot.Data, 0644); err != nil { + if err = ioutil.WriteFile(screenshotName, screenshot.Data, 0o644); err != nil { return err } diff --git a/cmd/cdpgen/main.go b/cmd/cdpgen/main.go index 95d6785..c64de50 100644 --- a/cmd/cdpgen/main.go +++ b/cmd/cdpgen/main.go @@ -34,7 +34,7 @@ func panicErr(err error) { } func mkdir(name string) error { - err := os.Mkdir(name, 0755) + err := os.Mkdir(name, 0o755) if os.IsExist(err) { return nil } @@ -280,7 +280,7 @@ func (g *Generator) writeFile(f string) { return } log.Printf("Writing %s...", fp) - err := ioutil.WriteFile(fp, g.format(), 0644) + err := ioutil.WriteFile(fp, g.format(), 0o644) panicErr(err) if g.testbuf.Len() > 0 { @@ -291,7 +291,7 @@ func (g *Generator) writeFile(f string) { fptest := strings.Replace(fp, ".go", "_test.go", 1) log.Printf("Writing %s...", fptest) - err = ioutil.WriteFile(fptest, g.format(), 0644) + err = ioutil.WriteFile(fptest, g.format(), 0o644) panicErr(err) } g.clear() diff --git a/cmd/cdpgen/proto/proto.go b/cmd/cdpgen/proto/proto.go index 83ceac1..96cc67c 100644 --- a/cmd/cdpgen/proto/proto.go +++ b/cmd/cdpgen/proto/proto.go @@ -404,10 +404,13 @@ func cleanDescription(d string, indent, startOffset int) string { old string new string }{ - {"", ""}, {"", ""}, + {"", ""}, + {"", ""}, //

is only used by DOM description. - {"

", "\n\n"}, {"

", ""}, - {"<", "<"}, {">", ">"}, + {"

", "\n\n"}, + {"

", ""}, + {"<", "<"}, + {">", ">"}, // Fix typo... {"> ", "> "}, } diff --git a/devtool/devtool_test.go b/devtool/devtool_test.go index 2f92103..21285f8 100644 --- a/devtool/devtool_test.go +++ b/devtool/devtool_test.go @@ -132,7 +132,7 @@ func TestDevTools(t *testing.T) { if got := buf.Bytes(); !bytes.Equal(got, want) { if *update { - err := ioutil.WriteFile(out, got, 0666) + err := ioutil.WriteFile(out, got, 0o666) if err != nil { t.Error(err) } @@ -201,7 +201,7 @@ func TestDevTools_Error(t *testing.T) { if got := buf.Bytes(); !bytes.Equal(got, want) { if *update { - err := ioutil.WriteFile(out, got, 0666) + err := ioutil.WriteFile(out, got, 0o666) if err != nil { t.Error(err) } diff --git a/example/screencast/main.go b/example/screencast/main.go index ff89420..81a8684 100644 --- a/example/screencast/main.go +++ b/example/screencast/main.go @@ -88,7 +88,7 @@ func run() error { // Write the frame to file (without blocking). go func() { - err = ioutil.WriteFile(name, ev.Data, 0644) + err = ioutil.WriteFile(name, ev.Data, 0o644) if err != nil { log.Printf("Failed to write ScreencastFrame to %q: %v", name, err) } diff --git a/example_test.go b/example_test.go index 87761c2..4960e7e 100644 --- a/example_test.go +++ b/example_test.go @@ -100,7 +100,7 @@ func run(timeout time.Duration) error { if err != nil { return err } - if err = ioutil.WriteFile(screenshotName, screenshot.Data, 0644); err != nil { + if err = ioutil.WriteFile(screenshotName, screenshot.Data, 0o644); err != nil { return err } diff --git a/internal/errors/errors.go b/internal/errors/errors.go index c8d0145..c6c25c7 100644 --- a/internal/errors/errors.go +++ b/internal/errors/errors.go @@ -42,9 +42,11 @@ type wrapped struct { msg string } -var _ error = (*wrapped)(nil) -var _ causer = (*wrapped)(nil) -var _ wrapper = (*wrapped)(nil) +var ( + _ error = (*wrapped)(nil) + _ causer = (*wrapped)(nil) + _ wrapper = (*wrapped)(nil) +) func (e *wrapped) Error() string { return fmt.Sprintf("%s: %s", e.msg, e.err.Error()) } func (e *wrapped) Cause() error { return e.err } @@ -69,9 +71,11 @@ type merged struct { s []error } -var _ error = (*merged)(nil) -var _ causer = (*merged)(nil) -var _ wrapper = (*merged)(nil) +var ( + _ error = (*merged)(nil) + _ causer = (*merged)(nil) + _ wrapper = (*merged)(nil) +) func (e *merged) Error() string { var s strings.Builder diff --git a/protocol/internal/error.go b/protocol/internal/error.go index f614458..b0e52e8 100644 --- a/protocol/internal/error.go +++ b/protocol/internal/error.go @@ -25,8 +25,10 @@ func (e *OpError) Unwrap() error { return e.Err } -type causer interface{ Cause() error } -type wrapper interface{ Unwrap() error } +type ( + causer interface{ Cause() error } + wrapper interface{ Unwrap() error } +) var ( _ error = (*OpError)(nil) diff --git a/protocol/io/stream_reader.go b/protocol/io/stream_reader.go index 999e6a1..2e5e235 100644 --- a/protocol/io/stream_reader.go +++ b/protocol/io/stream_reader.go @@ -18,16 +18,15 @@ type StreamReader struct { eof bool } -var ( - _ io.ReadCloser = (*StreamReader)(nil) -) +var _ io.ReadCloser = (*StreamReader)(nil) // NewStreamReader returns a reader for io.Streams that implements io.Reader // from the standard library. func NewStreamReader(ctx context.Context, ioClient interface { Read(context.Context, *ReadArgs) (*ReadReply, error) Close(context.Context, *CloseArgs) error -}, handle StreamHandle) *StreamReader { +}, handle StreamHandle, +) *StreamReader { args := NewReadArgs(handle) return &StreamReader{ next: func(pos, size int) (*ReadReply, error) { diff --git a/protocol/io/stream_reder_test.go b/protocol/io/stream_reder_test.go index 7652338..17fc86d 100644 --- a/protocol/io/stream_reder_test.go +++ b/protocol/io/stream_reder_test.go @@ -70,6 +70,7 @@ func (c *streamReaderTestClient) Read(context.Context, *ReadArgs) (*ReadReply, e c.reply = c.reply[1:] return &reply, nil } + func (c *streamReaderTestClient) Close(context.Context, *CloseArgs) error { return c.close } diff --git a/protocol/runtime/util.go b/protocol/runtime/util.go index b59c7ec..8d37e92 100644 --- a/protocol/runtime/util.go +++ b/protocol/runtime/util.go @@ -14,9 +14,7 @@ func (r ExceptionDetails) Error() string { return fmt.Sprintf("runtime.ExceptionDetails: %s exception at %d:%d%s", r.Text, r.LineNumber, r.ColumnNumber, desc) } -var ( - _ error = (*ExceptionDetails)(nil) -) +var _ error = (*ExceptionDetails)(nil) // String returns a human readable string of a runtime object. func (r RemoteObject) String() string { diff --git a/protocol/runtime/util_test.go b/protocol/runtime/util_test.go index 0433e98..570ffa5 100644 --- a/protocol/runtime/util_test.go +++ b/protocol/runtime/util_test.go @@ -48,7 +48,7 @@ func TestRuntimeRemoteObject_String(t *testing.T) { if got := buf.Bytes(); !bytes.Equal(got, want) { if *update { - err := ioutil.WriteFile(out, got, 0666) + err := ioutil.WriteFile(out, got, 0o666) if err != nil { t.Error(err) } diff --git a/rpcc/conn.go b/rpcc/conn.go index 6b609e3..863e071 100644 --- a/rpcc/conn.go +++ b/rpcc/conn.go @@ -29,11 +29,9 @@ func (e *closeError) Closed() bool { return true } func (e *closeError) Cause() error { return e.err } func (e *closeError) Unwrap() error { return e.err } -var ( - // ErrConnClosing indicates that the operation is illegal because - // the connection is closing. - ErrConnClosing = &closeError{msg: "rpcc: the connection is closing"} -) +// ErrConnClosing indicates that the operation is illegal because +// the connection is closing. +var ErrConnClosing = &closeError{msg: "rpcc: the connection is closing"} const ( defaultWriteBufferSize = 4096 @@ -313,9 +311,7 @@ func (e *ResponseError) Error() string { return fmt.Sprintf("rpc error: %s (code = %d%s)", e.Message, e.Code, data) } -var ( - _ error = (*ResponseError)(nil) -) +var _ error = (*ResponseError)(nil) // Context returns the underlying context for this connection. func (c *Conn) Context() context.Context { diff --git a/rpcc/socket.go b/rpcc/socket.go index 8c8659f..9aacab9 100644 --- a/rpcc/socket.go +++ b/rpcc/socket.go @@ -19,9 +19,7 @@ type wsReadWriteCloser struct { r io.Reader } -var ( - _ io.ReadWriteCloser = (*wsReadWriteCloser)(nil) -) +var _ io.ReadWriteCloser = (*wsReadWriteCloser)(nil) // Read calls Read on the WebSocket Reader and requests the NextReader // when io.EOF is encountered. Imlpements io.Reader. diff --git a/rpcc/socket_test.go b/rpcc/socket_test.go index eaacae8..8240fcf 100644 --- a/rpcc/socket_test.go +++ b/rpcc/socket_test.go @@ -21,12 +21,14 @@ func (c *fakeSocketConn) NextReader() (int, io.Reader, error) { c.reader = new(fakeReader) return 0, c.reader, nil } + func (c *fakeSocketConn) NextWriter(int) (io.WriteCloser, error) { c.nextWriterCount++ c.writer = new(fakeWriteCloser) c.writer.err = c.writerErr return c.writer, c.nextWriterErr } + func (c *fakeSocketConn) Close() error { c.closed = true return nil @@ -54,6 +56,7 @@ func (c *fakeWriteCloser) Write(p []byte) (n int, err error) { c.count++ return c.n, c.err } + func (c *fakeWriteCloser) Close() error { c.closed = true return c.err diff --git a/rpcc/stream.go b/rpcc/stream.go index fdc72ce..5f77c9a 100644 --- a/rpcc/stream.go +++ b/rpcc/stream.go @@ -7,11 +7,9 @@ import ( "sync" ) -var ( - // ErrStreamClosing indicates that the operation is illegal because - // the stream is closing and there are no pending messages. - ErrStreamClosing = &closeError{msg: "rpcc: the stream is closing"} -) +// ErrStreamClosing indicates that the operation is illegal because +// the stream is closing and there are no pending messages. +var ErrStreamClosing = &closeError{msg: "rpcc: the stream is closing"} // message contains the invoked method name, data and next func. type message struct { diff --git a/rpcc/stream_test.go b/rpcc/stream_test.go index 2758e02..69e546b 100644 --- a/rpcc/stream_test.go +++ b/rpcc/stream_test.go @@ -76,7 +76,6 @@ func TestStream_Ready(t *testing.T) { if closeEarly { s.Close() } - }() for i := 0; i < 10; i++ { diff --git a/session/session_test.go b/session/session_test.go index a87950d..07ef4fc 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -194,9 +194,7 @@ func TestManager_NewOnClosedConn(t *testing.T) { } } -var ( - browserFlag = flag.Bool("browser", false, "Test with browser") -) +var browserFlag = flag.Bool("browser", false, "Test with browser") func TestMain(m *testing.M) { flag.Parse()