Skip to content

Commit

Permalink
Fix issue16 (#21)
Browse files Browse the repository at this point in the history
* add line to dl4006

* fix bug dl4006
  • Loading branch information
zabio3 committed Jul 4, 2022
1 parent 294161c commit c448b88
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion linter/rules/dl4006.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ func validateDL4006(node *parser.Node) (rst []ValidateResult, err error) {
case SHELL:
isShellPipeFail = true
case RUN:
var isInQuote bool
for _, v := range strings.Fields(child.Next.Value) {
switch v {
case "|":
if !isShellPipeFail {
if !isInQuote && !isShellPipeFail {
rst = append(rst, ValidateResult{line: child.StartLine})
}
default:
if strings.HasPrefix(v, "'") {
isInQuote = true
}
if strings.HasSuffix(v, "'") {
isInQuote = false
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions linter/rules/dl4006_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func TestValidateDL4006(t *testing.T) {
{
dockerfileStr: `SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN wget -O - https://some.site | wc -l > /number
`,
expectedRst: nil,
expectedErr: nil,
},
{
dockerfileStr: `SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN yq eval '.".docker".script[1] | explode(.)' /base.yml > /usr/local/bin/entrypoint
`,
expectedRst: nil,
expectedErr: nil,
Expand Down
3 changes: 2 additions & 1 deletion testdata/DL4006_Dockerfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
RUN wget -O - https://some.site | wc -l > /number
RUN wget -O - https://some.site | wc -l > /number
RUN yq eval '.".docker".script[1] | explode(.)' /base.yml > /usr/local/bin/entrypoint

0 comments on commit c448b88

Please sign in to comment.