Skip to content

Commit

Permalink
Merge pull request #120 from dokku/109-backslash-comments
Browse files Browse the repository at this point in the history
Add support for // as comments
  • Loading branch information
josegonzalez authored Feb 9, 2024
2 parents be01a15 + 6b3bdcf commit 133c819
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions fixtures/forwardslash-comments.Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// ignore this
web: python web.py
# this too
worker: node worker.js # testing inline comment
worker-2: node worker.js // testing inline forwardslash comment
8 changes: 6 additions & 2 deletions procfile/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func ParseProcfile(text string, delimiter string, strict bool) ([]ProcfileEntry,
reOldCmd, _ := regexp.Compile(`^([A-Za-z0-9_-]+)` + delimiter + `\s*(.+)$`)

reComment, _ := regexp.Compile(`^(.*)\s#.+$`)
reForwardslashComment, _ := regexp.Compile(`^(.*)\s//.+$`)

lineNumber := 0
names := make(map[string]bool)
Expand All @@ -55,7 +56,7 @@ func ParseProcfile(text string, delimiter string, strict bool) ([]ProcfileEntry,
params := reCmd.FindStringSubmatch(line)
isCommand := len(params) == 4
isOldCommand := len(oldParams) == 3
isComment := strings.HasPrefix(line, "#")
isComment := strings.HasPrefix(line, "#") || strings.HasPrefix(line, "//")
if isComment {
continue
}
Expand Down Expand Up @@ -88,12 +89,15 @@ func ParseProcfile(text string, delimiter string, strict bool) ([]ProcfileEntry,
names[name] = true

commentParams := reComment.FindStringSubmatch(cmd)
reForwardslashCommentParams := reForwardslashComment.FindStringSubmatch(cmd)
if len(commentParams) == 2 {
cmd = commentParams[1]
} else if len(reForwardslashCommentParams) == 2 {
cmd = reForwardslashCommentParams[1]
}

cmd = strings.TrimSpace(cmd)
if strings.HasPrefix(cmd, "#") {
if strings.HasPrefix(cmd, "#") || strings.HasPrefix(cmd, "//") {
return entries, fmt.Errorf("comment specified in place of command, line %d", lineNumber)
}

Expand Down
28 changes: 28 additions & 0 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ teardown_file() {
assert_output_contains "valid procfile detected 2custom, cron, custom, release, web, wor-ker"
}

@test "[lax] forwardslash-comments" {
run $PROCFILE_BIN check -P fixtures/forwardslash-comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output_contains "valid procfile detected web, worker, worker-2"

run $PROCFILE_BIN show -P fixtures/forwardslash-comments.Procfile -p worker
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output_contains "node worker.js"
}

@test "[lax] multiple" {
run $PROCFILE_BIN check -P fixtures/multiple.Procfile
echo "output: $output"
Expand Down Expand Up @@ -49,6 +63,20 @@ teardown_file() {
assert_output_contains "valid procfile detected 2custom, cron, custom, release, web, wor-ker"
}

@test "[strict] forwardslash-comments" {
run $PROCFILE_BIN check -S -P fixtures/forwardslash-comments.Procfile
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output_contains "valid procfile detected web, worker, worker-2"

run $PROCFILE_BIN show -S -P fixtures/forwardslash-comments.Procfile -p worker
echo "output: $output"
echo "status: $status"
[[ "$status" -eq 0 ]]
assert_output_contains "node worker.js"
}

@test "[strict] multiple" {
run $PROCFILE_BIN check -S -P fixtures/multiple.Procfile
echo "output: $output"
Expand Down

0 comments on commit 133c819

Please sign in to comment.