Fix golint warnings for builder

Addresses: #14756

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Upstream-commit: 8c4a282a5719455cb5c63b917deb2a2042eed685
Component: engine
This commit is contained in:
Qiang Huang
2015-07-22 13:29:03 +08:00
parent 8f8c0a2957
commit 43c8d7a97f
13 changed files with 131 additions and 107 deletions
@@ -151,7 +151,7 @@ func parseNameVal(rest string, key string) (*Node, map[string]bool, error) {
if !strings.Contains(words[0], "=") {
node := &Node{}
rootnode = node
strs := TOKEN_WHITESPACE.Split(rest, 2)
strs := tokenWhitespace.Split(rest, 2)
if len(strs) < 2 {
return nil, nil, fmt.Errorf(key + " must have two arguments")
@@ -205,7 +205,7 @@ func parseStringsWhitespaceDelimited(rest string) (*Node, map[string]bool, error
node := &Node{}
rootnode := node
prevnode := node
for _, str := range TOKEN_WHITESPACE.Split(rest, -1) { // use regexp
for _, str := range tokenWhitespace.Split(rest, -1) { // use regexp
prevnode = node
node.Value = str
node.Next = &Node{}
@@ -232,13 +232,13 @@ func parseString(rest string) (*Node, map[string]bool, error) {
// parseJSON converts JSON arrays to an AST.
func parseJSON(rest string) (*Node, map[string]bool, error) {
var myJson []interface{}
if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJson); err != nil {
var myJSON []interface{}
if err := json.NewDecoder(strings.NewReader(rest)).Decode(&myJSON); err != nil {
return nil, nil, err
}
var top, prev *Node
for _, str := range myJson {
for _, str := range myJSON {
s, ok := str.(string)
if !ok {
return nil, nil, errDockerfileNotStringArray
+9 -9
View File
@@ -1,4 +1,4 @@
// This package implements a parser and parse tree dumper for Dockerfiles.
// Package parser implements a parser and parse tree dumper for Dockerfiles.
package parser
import (
@@ -33,10 +33,10 @@ type Node struct {
}
var (
dispatch map[string]func(string) (*Node, map[string]bool, error)
TOKEN_WHITESPACE = regexp.MustCompile(`[\t\v\f\r ]+`)
TOKEN_LINE_CONTINUATION = regexp.MustCompile(`\\[ \t]*$`)
TOKEN_COMMENT = regexp.MustCompile(`^#.*$`)
dispatch map[string]func(string) (*Node, map[string]bool, error)
tokenWhitespace = regexp.MustCompile(`[\t\v\f\r ]+`)
tokenLineContinuation = regexp.MustCompile(`\\[ \t]*$`)
tokenComment = regexp.MustCompile(`^#.*$`)
)
func init() {
@@ -70,8 +70,8 @@ func parseLine(line string) (string, *Node, error) {
return "", nil, nil
}
if TOKEN_LINE_CONTINUATION.MatchString(line) {
line = TOKEN_LINE_CONTINUATION.ReplaceAllString(line, "")
if tokenLineContinuation.MatchString(line) {
line = tokenLineContinuation.ReplaceAllString(line, "")
return line, nil, nil
}
@@ -96,8 +96,8 @@ func parseLine(line string) (string, *Node, error) {
return "", node, nil
}
// The main parse routine. Handles an io.ReadWriteCloser and returns the root
// of the AST.
// Parse is the main parse routine.
// It handles an io.ReadWriteCloser and returns the root of the AST.
func Parse(rwc io.Reader) (*Node, error) {
root := &Node{}
scanner := bufio.NewScanner(rwc)
+5 -5
View File
@@ -7,8 +7,8 @@ import (
"unicode"
)
// dumps the AST defined by `node` as a list of sexps. Returns a string
// suitable for printing.
// Dump dumps the AST defined by `node` as a list of sexps.
// Returns a string suitable for printing.
func (node *Node) Dump() string {
str := ""
str += node.Value
@@ -59,7 +59,7 @@ func splitCommand(line string) (string, []string, string, error) {
var flags []string
// Make sure we get the same results irrespective of leading/trailing spaces
cmdline := TOKEN_WHITESPACE.Split(strings.TrimSpace(line), 2)
cmdline := tokenWhitespace.Split(strings.TrimSpace(line), 2)
cmd := strings.ToLower(cmdline[0])
if len(cmdline) == 2 {
@@ -77,8 +77,8 @@ func splitCommand(line string) (string, []string, string, error) {
// this function.
func stripComments(line string) string {
// string is already trimmed at this point
if TOKEN_COMMENT.MatchString(line) {
return TOKEN_COMMENT.ReplaceAllString(line, "")
if tokenComment.MatchString(line) {
return tokenComment.ReplaceAllString(line, "")
}
return line