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

Format project with gofumpt #135

Merged
merged 1 commit into from Jun 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/cdpgen/main.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions cmd/cdpgen/proto/proto.go
Expand Up @@ -404,10 +404,13 @@ func cleanDescription(d string, indent, startOffset int) string {
old string
new string
}{
{"<code>", ""}, {"</code>", ""},
{"<code>", ""},
{"</code>", ""},
// <p> is only used by DOM description.
{"<p>", "\n\n"}, {"</p>", ""},
{"&lt;", "<"}, {"&gt;", ">"},
{"<p>", "\n\n"},
{"</p>", ""},
{"&lt;", "<"},
{"&gt;", ">"},
// Fix typo...
{"&gt ", "> "},
}
Expand Down
4 changes: 2 additions & 2 deletions devtool/devtool_test.go
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion example/screencast/main.go
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Expand Up @@ -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
}

Expand Down
16 changes: 10 additions & 6 deletions internal/errors/errors.go
Expand Up @@ -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 }
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions protocol/internal/error.go
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions protocol/io/stream_reader.go
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions protocol/io/stream_reder_test.go
Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions protocol/runtime/util.go
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion protocol/runtime/util_test.go
Expand Up @@ -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)
}
Expand Down
12 changes: 4 additions & 8 deletions rpcc/conn.go
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions rpcc/socket.go
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions rpcc/socket_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions rpcc/stream.go
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion rpcc/stream_test.go
Expand Up @@ -76,7 +76,6 @@ func TestStream_Ready(t *testing.T) {
if closeEarly {
s.Close()
}

}()

for i := 0; i < 10; i++ {
Expand Down
4 changes: 1 addition & 3 deletions session/session_test.go
Expand Up @@ -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()
Expand Down