Skip to content

Commit

Permalink
Ignore unrelated, commented-out fields.
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Miguel Custódio <[email protected]>
  • Loading branch information
bmcustodio committed Jun 8, 2021
1 parent 8abd6f4 commit 13db10f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
42 changes: 42 additions & 0 deletions pkg/document/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,3 +1373,45 @@ after: 3
assert.Equal(t, "", valuesRows[0].Description)
assert.Equal(t, "after desc", valuesRows[0].AutoDescription)
}

func TestIgnoreCommentedFields(t *testing.T) {
helmValues := parseYamlValues(`
# -- Qux!
qux: 1
# must not appear
# must not appear too
foo:
# -- Bar!
bar: true
# -- Baz!
baz: false
`)

valuesRows, err := getSortedValuesTableRows(helmValues, make(map[string]helm.ChartValueDescription))

assert.Nil(t, err)
assert.Len(t, valuesRows, 3)

assert.Equal(t, "qux", valuesRows[2].Key)
assert.Equal(t, intType, valuesRows[2].Type)
assert.Equal(t, "`1`", valuesRows[2].Default)
assert.Equal(t, "", valuesRows[2].AutoDefault)
assert.Equal(t, "", valuesRows[2].Description)
assert.Equal(t, "Qux!", valuesRows[2].AutoDescription)

assert.Equal(t, "foo.baz", valuesRows[1].Key)
assert.Equal(t, boolType, valuesRows[1].Type)
assert.Equal(t, "`false`", valuesRows[1].Default)
assert.Equal(t, "", valuesRows[1].AutoDefault)
assert.Equal(t, "", valuesRows[1].Description)
assert.Equal(t, "Baz!", valuesRows[1].AutoDescription)

assert.Equal(t, "foo.bar", valuesRows[0].Key)
assert.Equal(t, boolType, valuesRows[0].Type)
assert.Equal(t, "`true`", valuesRows[0].Default)
assert.Equal(t, "", valuesRows[0].AutoDefault)
assert.Equal(t, "", valuesRows[0].Description)
assert.Equal(t, "Bar!", valuesRows[0].AutoDescription)
}
6 changes: 5 additions & 1 deletion pkg/helm/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func ParseComment(commentLines []string) (string, ChartValueDescription) {

// Work around https://github.com/norwoodj/helm-docs/issues/96 by considering only
// the last "group" of comment lines starting with '# --'.
lastIndex := 0
lastIndex := -1
for i, v := range commentLines {
if strings.HasPrefix(v, "# --") {
lastIndex = i
Expand All @@ -21,6 +21,10 @@ func ParseComment(commentLines []string) (string, ChartValueDescription) {
// If there's a non-zero last index, consider that alone.
return ParseComment(commentLines[lastIndex:])
}
if lastIndex == -1 {
// There are no lines starting with '# --', so we assume there's no documentation for the current field.
return "", ChartValueDescription{}
}

for i := range commentLines {
match := valuesDescriptionRegex.FindStringSubmatch(commentLines[i])
Expand Down

0 comments on commit 13db10f

Please sign in to comment.