Skip to content

Commit

Permalink
Bug fix DL4001
Browse files Browse the repository at this point in the history
Output a message only at the use location when using curl and wget in both directions
  • Loading branch information
zabio3 committed Mar 28, 2019
1 parent 8904231 commit d6b992e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package command line tool to analyzer dockerfile.
package cmd

import (
Expand Down
7 changes: 6 additions & 1 deletion linter/rules/dl4001.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ import (
// validateDL4001 Either use Wget or Curl but not both
func validateDL4001(node *parser.Node) (rst []ValidateResult, err error) {
isCurl, isWget := false, false
var numArr []int
for _, child := range node.Children {
switch child.Value {
case RUN:
for _, v := range strings.Fields(child.Next.Value) {
switch v {
case "curl":
isCurl = true
numArr = append(numArr, child.StartLine)
case "wget":
isWget = true
numArr = append(numArr, child.StartLine)
}
}
}
if isCurl && isWget {
rst = append(rst, ValidateResult{line: child.StartLine, addMsg: ""})
for _, num := range numArr {
rst = append(rst, ValidateResult{line: num, addMsg: ""})
}
}
}
return rst, nil
Expand Down
1 change: 1 addition & 0 deletions linter/rules/dl4001_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ RUN wget http://google.com
RUN curl http://bing.com
`,
expectedRst: []ValidateResult{
{line: 2, addMsg: ""},
{line: 3, addMsg: ""},
},
expectedErr: nil,
Expand Down
2 changes: 1 addition & 1 deletion linter/rules/dl4003.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/moby/buildkit/frontend/dockerfile/parser"
)

// validateDL4003 Either use Wget or Curl but not both
// validateDL4003 Multiple CMD instructions found.
func validateDL4003(node *parser.Node) (rst []ValidateResult, err error) {
isCmd := false
for _, child := range node.Children {
Expand Down

0 comments on commit d6b992e

Please sign in to comment.