Skip to content

Commit 99ebc9c

Browse files
crazy-maxwillnorris
authored andcommitted
Update Dockerfile handling to keep parser directives at the top
Signed-off-by: CrazyMax <[email protected]>
1 parent 5be3bee commit 99ebc9c

File tree

8 files changed

+46
-0
lines changed

8 files changed

+46
-0
lines changed

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ var head = []string{
296296
"# encoding:", // Ruby encoding
297297
"# frozen_string_literal:", // Ruby interpreter instruction
298298
"<?php", // PHP opening tag
299+
"# escape", // Dockerfile directive https://docs.docker.com/engine/reference/builder/#parser-directives
300+
"# syntax", // Dockerfile directive https://docs.docker.com/engine/reference/builder/#parser-directives
299301
}
300302

301303
func hashBang(b []byte) []byte {

main_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ func TestAddLicense(t *testing.T) {
242242
{"# encoding: UTF-8\ncontent", "# encoding: UTF-8\n// HYS\n\ncontent", true},
243243
{"# frozen_string_literal: true\ncontent", "# frozen_string_literal: true\n// HYS\n\ncontent", true},
244244
{"<?php\ncontent", "<?php\n// HYS\n\ncontent", true},
245+
{"# escape: `\ncontent", "# escape: `\n// HYS\n\ncontent", true},
246+
{"# syntax: docker/dockerfile:1.3\ncontent", "# syntax: docker/dockerfile:1.3\n// HYS\n\ncontent", true},
245247

246248
// ensure files with existing license or generated files are
247249
// skipped. No need to test all permutations of these, since

testdata/expected/file2.Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# syntax=docker/dockerfile:1.3
2+
# Copyright 2018 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
FROM scratch
17+
CMD ["echo", "hello world"]

testdata/expected/file3.Dockerfile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# escape=`
2+
# Copyright 2018 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
FROM microsoft/nanoserver
17+
COPY testfile.txt c:\
18+
RUN dir c:\
File renamed without changes.

testdata/initial/file2.Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# syntax=docker/dockerfile:1.3
2+
FROM scratch
3+
CMD ["echo", "hello world"]

testdata/initial/file3.Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# escape=`
2+
FROM microsoft/nanoserver
3+
COPY testfile.txt c:\
4+
RUN dir c:\

0 commit comments

Comments
 (0)