diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-02-28 15:52:49 -0800 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-02-29 03:31:19 +0000 |
commit | 351c15f1cee364a91ef606ef9114d55247a6a0c2 (patch) | |
tree | 8dcea615817f3a640786e55a4ebcfe75306abe77 /src/encoding/csv | |
parent | 28ce6f3600fd87a1ae39c492ee56307f0be3c32f (diff) | |
download | go-351c15f1cee364a91ef606ef9114d55247a6a0c2.tar.gz go-351c15f1cee364a91ef606ef9114d55247a6a0c2.zip |
all: remove public named return values when useless
Named returned values should only be used on public funcs and methods
when it contributes to the documentation.
Named return values should not be used if they're only saving the
programmer a few lines of code inside the body of the function,
especially if that means there's stutter in the documentation or it
was only there so the programmer could use a naked return
statement. (Naked returns should not be used except in very small
functions)
This change is a manual audit & cleanup of public func signatures.
Signatures were not changed if:
* the func was private (wouldn't be in public godoc)
* the documentation referenced it
* the named return value was an interesting name. (i.e. it wasn't
simply stutter, repeating the name of the type)
There should be no changes in behavior. (At least: none intended)
Change-Id: I3472ef49619678fe786e5e0994bdf2d9de76d109
Reviewed-on: https://go-review.googlesource.com/20024
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/encoding/csv')
-rw-r--r-- | src/encoding/csv/writer.go | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/encoding/csv/writer.go b/src/encoding/csv/writer.go index a6056285b4..e8739fb554 100644 --- a/src/encoding/csv/writer.go +++ b/src/encoding/csv/writer.go @@ -37,27 +37,28 @@ func NewWriter(w io.Writer) *Writer { // Writer writes a single CSV record to w along with any necessary quoting. // A record is a slice of strings with each string being one field. -func (w *Writer) Write(record []string) (err error) { +func (w *Writer) Write(record []string) error { for n, field := range record { if n > 0 { - if _, err = w.w.WriteRune(w.Comma); err != nil { - return + if _, err := w.w.WriteRune(w.Comma); err != nil { + return err } } // If we don't have to have a quoted field then just // write out the field and continue to the next field. if !w.fieldNeedsQuotes(field) { - if _, err = w.w.WriteString(field); err != nil { - return + if _, err := w.w.WriteString(field); err != nil { + return err } continue } - if err = w.w.WriteByte('"'); err != nil { - return + if err := w.w.WriteByte('"'); err != nil { + return err } for _, r1 := range field { + var err error switch r1 { case '"': _, err = w.w.WriteString(`""`) @@ -75,20 +76,21 @@ func (w *Writer) Write(record []string) (err error) { _, err = w.w.WriteRune(r1) } if err != nil { - return + return err } } - if err = w.w.WriteByte('"'); err != nil { - return + if err := w.w.WriteByte('"'); err != nil { + return err } } + var err error if w.UseCRLF { _, err = w.w.WriteString("\r\n") } else { err = w.w.WriteByte('\n') } - return + return err } // Flush writes any buffered data to the underlying io.Writer. @@ -104,9 +106,9 @@ func (w *Writer) Error() error { } // WriteAll writes multiple CSV records to w using Write and then calls Flush. -func (w *Writer) WriteAll(records [][]string) (err error) { +func (w *Writer) WriteAll(records [][]string) error { for _, record := range records { - err = w.Write(record) + err := w.Write(record) if err != nil { return err } |