Skip to content

Commit 2f25d2c

Browse files
jooolaSBGoods
andauthored
fix: remove double newlines when no variadic argument (#489)
* fix: remove double newlines when no variadic argument * Add acceptance test * Add changelog entry --------- Co-authored-by: Selena Goods <[email protected]>
1 parent 2ffec57 commit 2f25d2c

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: 'generate: Remove trailing whitespace from default function template when `.HasVariadic` evaluates to false'
3+
time: 2025-06-13T16:29:58.411584-04:00
4+
custom:
5+
Issue: "489"

cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_no_templates.txtar

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ cmp docs/index.md expected-index.md
99
cmp docs/data-sources/example.md expected-datasource.md
1010
cmp docs/resources/example.md expected-resource.md
1111
cmp docs/functions/example.md expected-function.md
12+
cmp docs/functions/no-variadic.md expected-no-variadic-function.md
1213
cmp docs/ephemeral-resources/example.md expected-ephemeral-resource.md
1314

1415
-- expected-output.txt --
@@ -22,6 +23,7 @@ generating missing data source content
2223
generating new template for data-source "scaffolding_example"
2324
generating missing function content
2425
generating new template for function "example"
26+
generating new template for function "no-variadic"
2527
generating missing ephemeral resource content
2628
generating new template for "scaffolding_example"
2729
generating missing provider content
@@ -32,6 +34,7 @@ rendering templated website to static markdown
3234
rendering "data-sources/example.md.tmpl"
3335
rendering "ephemeral-resources/example.md.tmpl"
3436
rendering "functions/example.md.tmpl"
37+
rendering "functions/no-variadic.md.tmpl"
3538
rendering "index.md.tmpl"
3639
rendering "resources/example.md.tmpl"
3740
-- expected-datasource.md --
@@ -99,6 +102,38 @@ example(input string, variadicInput string...) string
99102
1. `input` (String) Value to echo.
100103
<!-- variadic argument generated by tfplugindocs -->
101104
1. `variadicInput` (Variadic, String) Variadic input to echo.
105+
-- expected-no-variadic-function.md --
106+
---
107+
# generated by https://github.com/hashicorp/terraform-plugin-docs
108+
page_title: "no-variadic function - terraform-provider-scaffolding"
109+
subcategory: ""
110+
description: |-
111+
Echo a string
112+
---
113+
114+
# function: no-variadic
115+
116+
Given a string value, returns the same value.
117+
118+
## Example Usage
119+
120+
```terraform
121+
output "test" {
122+
value = provider::scaffolding::no-variadic("testvalue1")
123+
}
124+
```
125+
126+
## Signature
127+
128+
<!-- signature generated by tfplugindocs -->
129+
```text
130+
no-variadic(input string) string
131+
```
132+
133+
## Arguments
134+
135+
<!-- arguments generated by tfplugindocs -->
136+
1. `input` (String) Value to echo.
102137
-- expected-index.md --
103138
---
104139
# generated by https://github.com/hashicorp/terraform-plugin-docs
@@ -207,6 +242,10 @@ data "scaffolding_example" "example" {
207242
output "test" {
208243
value = provider::scaffolding::example("testvalue1", "testvalue2")
209244
}
245+
-- examples/functions/no-variadic/function.tf --
246+
output "test" {
247+
value = provider::scaffolding::no-variadic("testvalue1")
248+
}
210249
-- examples/provider/provider.tf --
211250
provider "scaffolding" {
212251
# example configuration here
@@ -340,6 +379,18 @@ resource "scaffolding_example" "example" {
340379
"description": "Variadic input to echo.",
341380
"type": "string"
342381
}
382+
},
383+
"no-variadic": {
384+
"description": "Given a string value, returns the same value.",
385+
"summary": "Echo a string",
386+
"return_type": "string",
387+
"parameters": [
388+
{
389+
"name": "input",
390+
"description": "Value to echo.",
391+
"type": "string"
392+
}
393+
]
343394
}
344395
}
345396
}

internal/provider/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ description: |-
323323
## Arguments
324324
325325
{{ .FunctionArgumentsMarkdown }}
326-
{{ if .HasVariadic -}}
326+
{{- if .HasVariadic }}
327327
{{ .FunctionVariadicArgumentMarkdown }}
328328
{{- end }}
329329
`

0 commit comments

Comments
 (0)