Skip to content

Commit

Permalink
🧹 remove todo comments from docs (#699)
Browse files Browse the repository at this point in the history
Additionally:
- 🐛 Fix field comments in gcp.lr : see commit messages

Fixes #598

Co-authored-by: Tim Smith <[email protected]>
  • Loading branch information
jaym and tas50 authored Jan 3, 2023
1 parent 5924bd8 commit e0ec1be
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
4 changes: 3 additions & 1 deletion resources/lr/cli/cmd/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ func (l *lrSchemaRenderer) renderResourcePage(resource *lr.Resource, schema *res

for k := range basicFields {
field := basicFields[k]
rows = append(rows, []string{field.ID, renderLrType(field.Type, l.resourceHrefMap), strings.Join(sanitizeComments(comments[k]), ", ")})
rows = append(rows, []string{field.ID, renderLrType(field.Type, l.resourceHrefMap),
strings.Join(sanitizeComments(comments[k]), ", ")})
}

table := tablewriter.NewWriter(builder)
Expand Down Expand Up @@ -360,5 +361,6 @@ func sanitizeComments(c []string) []string {
for i := range c {
c[i] = strings.TrimPrefix(c[i], "// ")
}

return c
}
23 changes: 17 additions & 6 deletions resources/lr/lr.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,28 @@ func (r *Resource) GetInitFields() []*Init {
return inits
}

func extractComments(raw []string) (string, string) {
if len(raw) == 0 {
return "", ""
}

func SanitizeComments(raw []string) []string {
todoStart := -1
for i := range raw {
if raw[i] != "" {
raw[i] = strings.Trim(raw[i][2:], " \t\n")
}
if todoStart == -1 && strings.HasPrefix(raw[i], "TODO") {
todoStart = i
}
}
if todoStart != -1 {
raw = raw[0:todoStart]
}
return raw
}

func extractTitleAndDescription(raw []string) (string, string) {
if len(raw) == 0 {
return "", ""
}
title, rest := raw[0], raw[1:]

desc := strings.Join(rest, " ")

return title, desc
Expand All @@ -218,7 +228,8 @@ func Parse(input string) (*LR, error) {
for i := range res.Resources {
resource := res.Resources[i]

resource.title, resource.desc = extractComments(resource.Comments)
resource.Comments = SanitizeComments(resource.Comments)
resource.title, resource.desc = extractTitleAndDescription(resource.Comments)
resource.Comments = nil

// List types have an implicit list field
Expand Down
3 changes: 2 additions & 1 deletion resources/lr/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func resourceFields(r *Resource, ast *LR) map[string]*resources.Field {
}
}

title, desc := extractComments(f.Comments)
f.Comments = SanitizeComments(f.Comments)
title, desc := extractTitleAndDescription(f.Comments)
fields[f.BasicField.ID] = &resources.Field{
Name: f.BasicField.ID,
Type: string(f.BasicField.Type.Type(ast)),
Expand Down
7 changes: 4 additions & 3 deletions resources/packs/gcp/gcp.lr
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ private gcp.storage.bucket @defaults("id") {
location string
//
locationType string
//
projectNumber string // TODO: project number / project id / project name
// TODO: project number / project id / project name
projectNumber string
//
storageClass string
//
Expand Down Expand Up @@ -585,7 +585,8 @@ private gcp.sql.instance @defaults("name") {
// Instance state
state string
// Project
project string // TODO: should this be id or name
// TODO: should this be id or name
project string
// Region
region string
// Service account email address
Expand Down
2 changes: 1 addition & 1 deletion resources/packs/gcp/info/gcp.lr.json

Large diffs are not rendered by default.

0 comments on commit e0ec1be

Please sign in to comment.