Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Mueller <mail@themue.dev>
  • Loading branch information
Frank Mueller committed Jan 13, 2020
1 parent 6f71476 commit 2b8d641
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 52 deletions.
45 changes: 34 additions & 11 deletions etc/etc.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ func (e *Etc) Split(path string) (*Etc, error) {
if err != nil {
return nil, failure.Annotate(err, "cannot split configuration")
}
values.At(fullPath[len(fullPath)-1:]...).SetKey("etc")
_, err = values.At(fullPath[len(fullPath)-1:]...).SetKey("etc")
if err != nil {
return nil, failure.Annotate(err, "cannot split configuration")
}
es := &Etc{
values: values,
}
Expand Down Expand Up @@ -257,21 +260,39 @@ func (e *Etc) Write(target io.Writer, prettyPrint bool) error {
doDepth := len(ks)
tag := ks[doDepth-1]
for i := depth; i > doDepth; i-- {
builder.EndTagNode()
if err := builder.EndTagNode(); err != nil {
return err
}
}
switch {
case doDepth > depth:
builder.BeginTagNode(tag)
builder.TextNode(v)
if err := builder.BeginTagNode(tag); err != nil {
return err
}
if err := builder.TextNode(v); err != nil {
return err
}
depth = doDepth
case doDepth == depth:
builder.EndTagNode()
builder.BeginTagNode(tag)
builder.TextNode(v)
if err := builder.EndTagNode(); err != nil {
return err
}
if err := builder.BeginTagNode(tag); err != nil {
return err
}
if err := builder.TextNode(v); err != nil {
return err
}
case doDepth < depth:
builder.EndTagNode()
builder.BeginTagNode(tag)
builder.TextNode(v)
if err := builder.EndTagNode(); err != nil {
return err
}
if err := builder.BeginTagNode(tag); err != nil {
return err
}
if err := builder.TextNode(v); err != nil {
return err
}
depth = doDepth
}
return nil
Expand All @@ -280,7 +301,9 @@ func (e *Etc) Write(target io.Writer, prettyPrint bool) error {
return err
}
for i := depth; i > 0; i-- {
builder.EndTagNode()
if err := builder.EndTagNode(); err != nil {
return err
}
}
root, err := builder.Root()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion gjp/gjp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func TestClear(t *testing.T) {
doc, err := gjp.Parse(bs, "/")
assert.Nil(err)
doc.Clear()
doc.SetValueAt("/", "foo")
err = doc.SetValueAt("/", "foo")
assert.NoError(err)
foo := doc.ValueAt("/").AsString("<undefined>")
assert.Equal(foo, "foo")
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.13

require (
tideland.dev/go/audit v0.3.0
tideland.dev/go/dsa v0.3.0
tideland.dev/go/together v0.0.0-20200110213028-8f143e2737a6
tideland.dev/go/trace v0.0.0-20200110203012-77bd5be58e01
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
tideland.dev/go v0.2.0 h1:JC/dwuqqn8NfU2jTNytDCjzbUTsWFGj1V2XfYJn0MKI=
tideland.dev/go/audit v0.3.0 h1:zUEjdr279z7OE+iFsqz8xQm4KrLRxARmUSg5TzlO2RY=
tideland.dev/go/audit v0.3.0/go.mod h1:iVQWp3A7czp2I4eH9nHERMMqljQRuwqTKuEzxoj9crI=
tideland.dev/go/dsa v0.3.0 h1:zIZDlIvVgzspyypZZfJsZqDQMVFAPEoBGbrR2xy942A=
tideland.dev/go/dsa v0.3.0/go.mod h1:8wQ77lLGRU3IRovPKxjHDBpj48u/QyYR5L3YWQFrwn0=
tideland.dev/go/together v0.0.0-20200110213028-8f143e2737a6 h1:RcwIrnqp20h2CJUVIJj3oHgDbUajmXvR5b4u9yVc3hg=
tideland.dev/go/together v0.0.0-20200110213028-8f143e2737a6/go.mod h1:g+TjCwnKorfsYdJk0XwGYeP3mxSvF1MbnWoQpKk3Y+U=
tideland.dev/go/trace v0.0.0-20200110203012-77bd5be58e01 h1:KKlJTuzV2lnWnnI2dY6loIO1iHxnL9+akHnXrTVY8wc=
Expand Down
8 changes: 5 additions & 3 deletions scroller/scroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ SeekLoop:
buffer = buffer[0:end]
}
// Final positioning.
s.source.Seek(seekPos, io.SeekStart)
return nil
_, err = s.source.Seek(seekPos, io.SeekStart)
return err
}

// readLine reads the next valid line from the reader, even if it is
Expand All @@ -302,7 +302,9 @@ func (s *Scroller) readLine() ([]byte, error) {
case io.EOF:
// Reached EOF without a delimiter,
// so step back for next time.
s.source.Seek(-int64(len(line)), io.SeekCurrent)
if _, serr := s.source.Seek(-int64(len(line)), io.SeekCurrent); serr != nil {
return nil, serr
}
return nil, err
default:
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions scroller/scroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var tests = []struct {
injector: func(s *scroller.Scroller, rs *readSeeker) func([]string) {
return func(lines []string) {
if len(lines) == 25 {
s.Stop()
_ = s.Stop()
}
}
},
Expand Down Expand Up @@ -377,7 +377,8 @@ func newReceiver(assert *asserts.Asserts, data []string) *receiver {

func (r *receiver) autoClose(scroller *scroller.Scroller) {
go func() {
scroller.Wait()
// Error of Wait() can be ignored here. Will be tested later.
_ = scroller.Wait()
r.writer.Close()
}()
}
Expand Down
4 changes: 3 additions & 1 deletion sml/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func (tn *tagNode) ProcessWith(p Processor) error {
func (tn *tagNode) String() string {
var buf bytes.Buffer
context := NewWriterContext(NewStandardSMLWriter(), &buf, true, "\t")
WriteSML(tn, context)
if err := WriteSML(tn, context); err != nil {
panic(err)
}
return buf.String()
}

Expand Down
12 changes: 9 additions & 3 deletions sml/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ func (mr *mlReader) readTagChildren() error {
}
default:
mr.index--
mr.reader.UnreadRune()
if err = mr.reader.UnreadRune(); err != nil {
return err
}
if err = mr.readTextNode(); err != nil {
return err
}
Expand All @@ -155,7 +157,9 @@ func (mr *mlReader) readBracedContent() error {
return failure.New("unexpected end of file while reading a tag or raw node")
case rc == rcTag:
mr.index--
mr.reader.UnreadRune()
if err = mr.reader.UnreadRune(); err != nil {
return err
}
return mr.readTagNode()
case rc == rcExclamation:
return mr.readRawNode()
Expand Down Expand Up @@ -233,7 +237,9 @@ func (mr *mlReader) readTextNode() error {
return failure.New("unexpected end of file while reading a text node")
case rc == rcOpen || rc == rcClose:
mr.index--
mr.reader.UnreadRune()
if err = mr.reader.UnreadRune(); err != nil {
return err
}
return mr.builder.TextNode(buf.String())
case rc == rcEscape:
r, rc, err = mr.readRune()
Expand Down
51 changes: 26 additions & 25 deletions sml/sml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func TestWriterProcessing(t *testing.T) {
ctxA := sml.NewWriterContext(sml.NewStandardSMLWriter(), bufA, true, " ")
ctxB := sml.NewWriterContext(sml.NewStandardSMLWriter(), bufB, false, "")

sml.WriteSML(root, ctxA)
sml.WriteSML(root, ctxB)
assert.NoError(sml.WriteSML(root, ctxA))
assert.NoError(sml.WriteSML(root, ctxB))

assert.Logf("===== WITH INDENT =====")
assert.Logf(bufA.String())
Expand All @@ -107,7 +107,7 @@ func TestPositiveNodeReading(t *testing.T) {

buf := bytes.NewBufferString("")
ctx := sml.NewWriterContext(sml.NewStandardSMLWriter(), buf, true, " ")
sml.WriteSML(root, ctx)
assert.NoError(sml.WriteSML(root, ctx))

assert.Logf("===== PARSED SML =====")
assert.Logf(buf.String())
Expand Down Expand Up @@ -172,8 +172,8 @@ for foo := 0; foo < 42; foo++ {

buf := bytes.NewBufferString("")
ctx := sml.NewWriterContext(sml.NewXMLWriter("pre"), buf, true, " ")
ctx.Register("li", newLIWriter())
sml.WriteSML(root, ctx)
assert.NoError(ctx.Register("li", newLIWriter()))
assert.NoError(sml.WriteSML(root, ctx))

assert.Logf("===== XML =====")
assert.Logf(buf.String())
Expand All @@ -186,33 +186,34 @@ for foo := 0; foo < 42; foo++ {

// Create a node structure.
func createNodeStructure(assert *asserts.Asserts) sml.Node {
check := assert.NoError
builder := sml.NewNodeBuilder()

builder.BeginTagNode("root")
check(builder.BeginTagNode("root"))

builder.TextNode("Text A")
builder.TextNode("Text B")
builder.CommentNode("A first comment.")
check(builder.TextNode("Text A"))
check(builder.TextNode("Text B"))
check(builder.CommentNode("A first comment."))

builder.BeginTagNode("sub-a:1st:important")
builder.TextNode("Text A.A")
builder.CommentNode("A second comment.")
builder.EndTagNode()
check(builder.BeginTagNode("sub-a:1st:important"))
check(builder.TextNode("Text A.A"))
check(builder.CommentNode("A second comment."))
check(builder.EndTagNode())

builder.BeginTagNode("sub-b:2nd")
builder.TextNode("Text B.A")
builder.BeginTagNode("text")
builder.TextNode("Any text with the special characters {, }, and ^.")
builder.EndTagNode()
builder.EndTagNode()
check(builder.BeginTagNode("sub-b:2nd"))
check(builder.TextNode("Text B.A"))
check(builder.BeginTagNode("text"))
check(builder.TextNode("Any text with the special characters {, }, and ^."))
check(builder.EndTagNode())
check(builder.EndTagNode())

builder.BeginTagNode("sub-c")
builder.TextNode("Before raw.")
builder.RawNode("func Test(i int) { println(i) }")
builder.TextNode("After raw.")
builder.EndTagNode()
check(builder.BeginTagNode("sub-c"))
check(builder.TextNode("Before raw."))
check(builder.RawNode("func Test(i int) { println(i) }"))
check(builder.TextNode("After raw."))
check(builder.EndTagNode())

builder.EndTagNode()
check(builder.EndTagNode())

root, err := builder.Root()
assert.Nil(err)
Expand Down
24 changes: 18 additions & 6 deletions sml/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,23 @@ func (w *mlWriter) activePlugin() WriterProcessor {
func (w *mlWriter) writeIndent(open bool) {
if w.context.prettyPrint {
for i := 0; i < w.indent; i++ {
w.context.Writef(w.context.indentStr)
if err := w.context.Writef(w.context.indentStr); err != nil {
panic(err)
}
}
} else if open {
w.context.Writef(" ")
if err := w.context.Writef(" "); err != nil {
panic(err)
}
}
}

// writeNewline writes a newline if wanted.
func (w *mlWriter) writeNewline() {
if w.context.prettyPrint {
w.context.Writef("\n")
if err := w.context.Writef("\n"); err != nil {
panic(err)
}
}
}

Expand Down Expand Up @@ -277,12 +283,18 @@ func (w *xmlWriter) SetContext(ctx *WriterContext) {

// OpenTag writes the opening of a tag.
func (w *xmlWriter) OpenTag(tag []string) error {
w.context.Writef("<%s", tag[0])
if err := w.context.Writef("<%s", tag[0]); err != nil {
return err
}
if len(tag) > 1 {
w.context.Writef(" id=%q", tag[1])
if err := w.context.Writef(" id=%q", tag[1]); err != nil {
return err
}
}
if len(tag) > 2 {
w.context.Writef(" class=%q", tag[2])
if err := w.context.Writef(" class=%q", tag[2]); err != nil {
return err
}
}
return w.context.Writef(">")
}
Expand Down

0 comments on commit 2b8d641

Please sign in to comment.