Browse code

Warn on empty continuation lines only, not for comments

Commit 8d1ae76dcbbb73d8e20c6a14a7d3fe2410b95f55 added
deprecation warnings for empty continuation lines,
but also treated comment-only lines as empty.

This patch distinguishes empty continuation lines
from comment-only lines, and only outputs warnings
for the former.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2017/09/28 05:18:24
Showing 2 changed files
... ...
@@ -290,6 +290,10 @@ func Parse(rwc io.Reader) (*Result, error) {
290 290
 			}
291 291
 			currentLine++
292 292
 
293
+			if isComment(scanner.Bytes()) {
294
+				// original line was a comment (processLine strips comments)
295
+				continue
296
+			}
293 297
 			if isEmptyContinuationLine(bytesRead) {
294 298
 				hasEmptyContinuationLine = true
295 299
 				continue
... ...
@@ -331,8 +335,12 @@ func trimWhitespace(src []byte) []byte {
331 331
 	return bytes.TrimLeftFunc(src, unicode.IsSpace)
332 332
 }
333 333
 
334
+func isComment(line []byte) bool {
335
+	return tokenComment.Match(trimWhitespace(line))
336
+}
337
+
334 338
 func isEmptyContinuationLine(line []byte) bool {
335
-	return len(trimComments(trimWhitespace(line))) == 0
339
+	return len(trimWhitespace(line)) == 0
336 340
 }
337 341
 
338 342
 var utf8bom = []byte{0xEF, 0xBB, 0xBF}
... ...
@@ -141,6 +141,13 @@ RUN something \
141 141
 RUN another \
142 142
 
143 143
     thing
144
+RUN non-indented \
145
+# this is a comment
146
+   after-comment
147
+
148
+RUN indented \
149
+    # this is an indented comment
150
+    comment
144 151
 	`)
145 152
 
146 153
 	result, err := Parse(dockerfile)