Skip to content
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
8 changes: 8 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ on:
push:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v8

test:
runs-on: ubuntu-latest
strategy:
Expand Down
30 changes: 30 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "2"

run:
issues-exit-code: 1

formatters:
enable:
- gofmt
- gci

linters:
enable:
- wrapcheck
settings:
wrapcheck:
ignore-package-globs:
# We already make sure your own packages wrap errors properly
- github.com/symfony-cli/*
errcheck:
exclude-functions:
- github.com/symfony-cli/terminal.Printf
- github.com/symfony-cli/terminal.Println
- github.com/symfony-cli/terminal.Printfln
- github.com/symfony-cli/terminal.Eprintf
- github.com/symfony-cli/terminal.Eprintln
- github.com/symfony-cli/terminal.Eprintfln
- github.com/symfony-cli/terminal.Eprint
- fmt.Fprintln
- fmt.Fprintf
- fmt.Fprint
2 changes: 1 addition & 1 deletion custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *state) dumpCustom(v reflect.Value, vv Dumpable) {
s.print(line)
}

s.Write([]byte("\n"))
_, _ = s.Write([]byte("\n"))
}

if err := scanner.Err(); err != nil {
Expand Down
14 changes: 8 additions & 6 deletions custom_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"reflect"
"sort"
"strings"

"github.com/pkg/errors"
)

func init() {
Expand All @@ -35,7 +37,7 @@ func init() {

func dumpHttpHeaders(s State, headers http.Header) {
s.Pad()
s.Write([]byte("Headers: {\n"))
_, _ = s.Write([]byte("Headers: {\n"))
s.DepthDown()
keys := make([]string, len(headers))
for key := range headers {
Expand All @@ -47,14 +49,14 @@ func dumpHttpHeaders(s State, headers http.Header) {
for _, v := range headers[key] {
s.Pad()
s.DumpString(key)
s.Write([]byte(": "))
_, _ = s.Write([]byte(": "))
s.Dump(v)
s.Write([]byte(",\n"))
_, _ = s.Write([]byte(",\n"))
}
}
s.DepthUp()
s.Pad()
s.Write([]byte("},\n"))
_, _ = s.Write([]byte("},\n"))
}

func dumpHttpRequest(s State, v reflect.Value) {
Expand Down Expand Up @@ -153,10 +155,10 @@ func copyBody(b io.ReadCloser) (io.ReadCloser, interface{}, error) {
}
var buf bytes.Buffer
if _, err := buf.ReadFrom(b); err != nil {
return b, "<invalid>", err
return b, "<invalid>", errors.Wrap(err, "failed to read from body")
}
if err := b.Close(); err != nil {
return b, "<invalid>", err
return b, "<invalid>", errors.Wrap(err, "failed to close body")
}

return io.NopCloser(&buf), buf.String(), nil
Expand Down
7 changes: 5 additions & 2 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"reflect"
"sort"
"strings"

"github.com/pkg/errors"
)

type state struct {
Expand All @@ -44,8 +46,9 @@ type state struct {
lastCaller string
}

func (s *state) Write(p []byte) (n int, err error) {
return s.w.Write(p)
func (s *state) Write(p []byte) (int, error) {
n, err := s.w.Write(p)
return n, errors.Wrap(err, "failed to write")
}

func (s *state) AddComment(comment string) {
Expand Down
17 changes: 9 additions & 8 deletions dumper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
package dumper

import (
"bufio"
"fmt"
"image"
"net/http"
"reflect"
"regexp"
"strings"
"testing"
"unsafe"

"bufio"
"net/http"

. "gopkg.in/check.v1"
)

Expand Down Expand Up @@ -283,10 +282,15 @@ func (ts *DumperSuite) TestPointer(c *C) {
c.Assert(Sdump(reflect.ValueOf(&foo).Pointer()), DumpEquals, `uintptr(0xXXXXXXXXXX)`)
var bar uintptr
bar = reflect.ValueOf(&foo).Pointer()
c.Assert(Sdump(bar), DumpEquals, `uintptr(0xXXXXXXXXXX)`)

bar = uintptr(0x0101010101)
c.Assert(Sdump(bar), DumpEquals, `uintptr(0xXXXXXXXXXX)`)

ptr := unsafe.Pointer(reflect.ValueOf(&foo).Pointer())
c.Assert(Sdump(ptr), DumpEquals, `unsafe.Pointer(uintptr(0xXXXXXXXXXX))`)

//nolint:govet
ptr = unsafe.Pointer(uintptr(0x0101010101))
c.Assert(Sdump(ptr), DumpEquals, `unsafe.Pointer(uintptr(0xXXXXXXXXXX))`)
}
Expand Down Expand Up @@ -314,9 +318,7 @@ func (ts *DumperSuite) TestFunc(c *C) {

func (ts *DumperSuite) TestCustomType(c *C) {
type testCustomType func() string
var f testCustomType

f = func() string { return "foo" }
var f testCustomType = func() string { return "foo" }

c.Assert(Sdump(f), DumpEquals, `dumper.testCustomType`)
}
Expand Down Expand Up @@ -352,8 +354,7 @@ Hello World!
}

func (ts *DumperSuite) TestCustomDumper(c *C) {
var foo interface{}
foo = TestCustomDumper{X: 42, Y: 43, Z: 44}
var foo interface{} = TestCustomDumper{X: 42, Y: 43, Z: 44}

c.Assert(Sdump(foo), DumpEquals, `dumper.TestCustomDumper{ // Custom comment
X: 44,
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ require gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
2 changes: 1 addition & 1 deletion print.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (s *state) printf(format string, args ...interface{}) {
}

func (s *state) Pad() {
s.Write(bytes.Repeat([]byte(" "), s.depth))
_, _ = s.Write(bytes.Repeat([]byte(" "), s.depth))
}

func (s *state) breakLineIfNecessary(n, i int) bool {
Expand Down
6 changes: 3 additions & 3 deletions wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func lastCaller() string {
func fdump(out io.Writer, styles map[string]string, values ...interface{}) {
for i, value := range values {
if i > 0 {
out.Write([]byte("\n"))
_, _ = out.Write([]byte("\n"))
}
state := state{
styles: styles,
Expand All @@ -79,7 +79,7 @@ func fdump(out io.Writer, styles map[string]string, values ...interface{}) {
// Fdump prints to the writer the value with indentation.
func Fdump(out io.Writer, values ...interface{}) {
fdump(out, defaultStyles, values...)
out.Write([]byte("\n"))
_, _ = out.Write([]byte("\n"))
}

// Sdump dumps the values into a string with indentation.
Expand All @@ -95,7 +95,7 @@ func Sdump(values ...interface{}) string {
// FdumpColor prints to the writer the value with indentation and color.
func FdumpColor(out io.Writer, values ...interface{}) {
fdump(out, colorStyles, values...)
out.Write([]byte("\n"))
_, _ = out.Write([]byte("\n"))
}

// Prints to given output the value(s) that is (are) passed as the argument(s)
Expand Down