From fb26bb3f8826377b5fe6f1dcfa3691b825349428 Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Thu, 29 Jun 2017 12:26:04 -0400 Subject: [PATCH] Lint; remove dead code --- chunks/ast.go | 7 +------ chunks/chunk.go | 9 ++++++--- chunks/marshal.go | 5 ----- chunks/parser.go | 17 ----------------- chunks/render.go | 21 +++++++-------------- filters/filters.go | 2 +- generics/generics.go | 2 +- 7 files changed, 16 insertions(+), 47 deletions(-) diff --git a/chunks/ast.go b/chunks/ast.go index 6de8d53..25d48c9 100644 --- a/chunks/ast.go +++ b/chunks/ast.go @@ -8,6 +8,7 @@ import ( // ASTNode is a node of an AST. type ASTNode interface { + // Render evaluates an AST node and writes the result to an io.Writer. Render(io.Writer, Context) error } @@ -21,12 +22,6 @@ type ASTSeq struct { Children []ASTNode } -// ASTChunks is a sequence of chunks. -// TODO probably safe to remove this type and method, once the test suite is larger -type ASTChunks struct { - chunks []Chunk -} - // ASTFunctional renders itself via a render function that is created during parsing. type ASTFunctional struct { Chunk diff --git a/chunks/chunk.go b/chunks/chunk.go index cff5382..65b334f 100644 --- a/chunks/chunk.go +++ b/chunks/chunk.go @@ -34,7 +34,10 @@ type SourceInfo struct { type ChunkType int const ( - TextChunkType ChunkType = iota // TextChunkType is the type of a text Chunk - TagChunkType // TagChunkType is the type of a tag Chunk "{%…%}" - ObjChunkType // TextChunkType is the type of an object Chunk "{{…}}" + // TextChunkType is the type of a text Chunk + TextChunkType ChunkType = iota + // TagChunkType is the type of a tag Chunk "{%…%}" + TagChunkType + // TextChunkType is the type of an object Chunk "{{…}}" + ObjChunkType ) diff --git a/chunks/marshal.go b/chunks/marshal.go index abd6f19..5883998 100644 --- a/chunks/marshal.go +++ b/chunks/marshal.go @@ -29,11 +29,6 @@ func (c Chunk) MarshalYAML() (interface{}, error) { } } -// MarshalYAML marshalls a chunk for debugging. -func (n ASTChunks) MarshalYAML() (interface{}, error) { - return map[string]interface{}{"chunks": n.chunks}, nil -} - // MarshalYAML marshalls a chunk for debugging. func (n ASTControlTag) MarshalYAML() (interface{}, error) { return map[string]map[string]interface{}{ diff --git a/chunks/parser.go b/chunks/parser.go index 997f3af..352b939 100644 --- a/chunks/parser.go +++ b/chunks/parser.go @@ -68,13 +68,6 @@ func Parse(chunks []Chunk) (ASTNode, error) { ccn.Branches = append(ccn.Branches, n) ap = &n.Body case cd.isEndTag: - // if ccn != nil && cd.parser != nil { - // renderer, err := cd.parser(*ccn) - // if err != nil { - // return nil, err - // } - // ccn.renderer = renderer - // } f := stack[len(stack)-1] stack = stack[:len(stack)-1] ccd, ccn, ap = f.cd, f.cn, f.ap @@ -88,16 +81,6 @@ func Parse(chunks []Chunk) (ASTNode, error) { } else { return nil, fmt.Errorf("unknown tag: %s", c.Name) } - // } else if len(*ap) > 0 { - // switch n := ((*ap)[len(*ap)-1]).(type) { - // case *ASTChunks: - // n.chunks = append(n.chunks, c) - // default: - // *ap = append(*ap, &ASTChunks{chunks: []Chunk{c}}) - // } - // } else { - // *ap = append(*ap, &ASTChunks{chunks: []Chunk{c}}) - // } } } if ccd != nil { diff --git a/chunks/render.go b/chunks/render.go index 618e852..a098772 100644 --- a/chunks/render.go +++ b/chunks/render.go @@ -7,7 +7,7 @@ import ( "github.com/osteele/liquid/generics" ) -// Render evaluates an AST node and writes the result to an io.Writer. +// Render is in the ASTNode interface. func (n *ASTSeq) Render(w io.Writer, ctx Context) error { for _, c := range n.Children { if err := c.Render(w, ctx); err != nil { @@ -17,29 +17,23 @@ func (n *ASTSeq) Render(w io.Writer, ctx Context) error { return nil } -// Render evaluates an AST node and writes the result to an io.Writer. -// TODO probably safe to remove this type and method, once the test suite is larger -func (n *ASTChunks) Render(w io.Writer, _ Context) error { - fmt.Println(MustYAML(n)) - return fmt.Errorf("unimplemented: ASTChunks.Render") -} - -// Render evaluates an AST node and writes the result to an io.Writer. +// Render is in the ASTNode interface. func (n *ASTFunctional) Render(w io.Writer, ctx Context) error { err := n.render(w, ctx) + // TODO restore something like this // if err != nil { // fmt.Println("while parsing", n.Source) // } return err } -// Render evaluates an AST node and writes the result to an io.Writer. +// Render is in the ASTNode interface. func (n *ASTText) Render(w io.Writer, _ Context) error { _, err := w.Write([]byte(n.Source)) return err } -// Render evaluates an AST node and writes the result to an io.Writer. +// Render is in the ASTNode interface. func (n *ASTRaw) Render(w io.Writer, _ Context) error { for _, s := range n.slices { _, err := w.Write([]byte(s)) @@ -50,7 +44,7 @@ func (n *ASTRaw) Render(w io.Writer, _ Context) error { return nil } -// Render evaluates an AST node and writes the result to an io.Writer. +// Render is in the ASTNode interface. func (n *ASTControlTag) Render(w io.Writer, ctx Context) error { cd, ok := findControlTagDefinition(n.Name) if !ok || cd.parser == nil { @@ -59,12 +53,11 @@ func (n *ASTControlTag) Render(w io.Writer, ctx Context) error { renderer := n.renderer if renderer == nil { panic(fmt.Errorf("unset renderer for %v", n)) - return nil } return renderer(w, ctx) } -// Render evaluates an AST node and writes the result to an io.Writer. +// Render is in the ASTNode interface. func (n *ASTObject) Render(w io.Writer, ctx Context) error { value, err := ctx.Evaluate(n.expr) if err != nil { diff --git a/filters/filters.go b/filters/filters.go index 1720707..b19b25e 100644 --- a/filters/filters.go +++ b/filters/filters.go @@ -93,7 +93,7 @@ func DefineStandardFilters() { case int, int16, int32, int64: return int(a) / bt.(int) case float32, float64: - return a / float64(b.(float64)) + return a / b.(float64) default: return nil } diff --git a/generics/generics.go b/generics/generics.go index 83e8a5f..5be0749 100644 --- a/generics/generics.go +++ b/generics/generics.go @@ -38,7 +38,7 @@ func IsEmpty(value interface{}) bool { case reflect.Array, reflect.Map, reflect.Slice, reflect.String: return r.Len() == 0 case reflect.Bool: - return r.Bool() == false + return !r.Bool() default: return false }