diff --git a/.changes/unreleased/ENHANCEMENTS-20250613-162958.yaml b/.changes/unreleased/ENHANCEMENTS-20250613-162958.yaml new file mode 100644 index 00000000..df64549f --- /dev/null +++ b/.changes/unreleased/ENHANCEMENTS-20250613-162958.yaml @@ -0,0 +1,5 @@ +kind: ENHANCEMENTS +body: 'generate: Remove trailing whitespace from default function template when `.HasVariadic` evaluates to false' +time: 2025-06-13T16:29:58.411584-04:00 +custom: + Issue: "489" diff --git a/cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_no_templates.txtar b/cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_no_templates.txtar index 861b396e..1163936d 100644 --- a/cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_no_templates.txtar +++ b/cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_no_templates.txtar @@ -9,6 +9,7 @@ cmp docs/index.md expected-index.md cmp docs/data-sources/example.md expected-datasource.md cmp docs/resources/example.md expected-resource.md cmp docs/functions/example.md expected-function.md +cmp docs/functions/no-variadic.md expected-no-variadic-function.md cmp docs/ephemeral-resources/example.md expected-ephemeral-resource.md -- expected-output.txt -- @@ -22,6 +23,7 @@ generating missing data source content generating new template for data-source "scaffolding_example" generating missing function content generating new template for function "example" +generating new template for function "no-variadic" generating missing ephemeral resource content generating new template for "scaffolding_example" generating missing provider content @@ -32,6 +34,7 @@ rendering templated website to static markdown rendering "data-sources/example.md.tmpl" rendering "ephemeral-resources/example.md.tmpl" rendering "functions/example.md.tmpl" +rendering "functions/no-variadic.md.tmpl" rendering "index.md.tmpl" rendering "resources/example.md.tmpl" -- expected-datasource.md -- @@ -99,6 +102,38 @@ example(input string, variadicInput string...) string 1. `input` (String) Value to echo. 1. `variadicInput` (Variadic, String) Variadic input to echo. +-- expected-no-variadic-function.md -- +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "no-variadic function - terraform-provider-scaffolding" +subcategory: "" +description: |- + Echo a string +--- + +# function: no-variadic + +Given a string value, returns the same value. + +## Example Usage + +```terraform +output "test" { + value = provider::scaffolding::no-variadic("testvalue1") +} +``` + +## Signature + + +```text +no-variadic(input string) string +``` + +## Arguments + + +1. `input` (String) Value to echo. -- expected-index.md -- --- # generated by https://github.com/hashicorp/terraform-plugin-docs @@ -208,6 +243,10 @@ data "scaffolding_example" "example" { output "test" { value = provider::scaffolding::example("testvalue1", "testvalue2") } +-- examples/functions/no-variadic/function.tf -- +output "test" { + value = provider::scaffolding::no-variadic("testvalue1") +} -- examples/provider/provider.tf -- provider "scaffolding" { # example configuration here @@ -341,6 +380,18 @@ resource "scaffolding_example" "example" { "description": "Variadic input to echo.", "type": "string" } + }, + "no-variadic": { + "description": "Given a string value, returns the same value.", + "summary": "Echo a string", + "return_type": "string", + "parameters": [ + { + "name": "input", + "description": "Value to echo.", + "type": "string" + } + ] } } } diff --git a/internal/provider/template.go b/internal/provider/template.go index 58766489..e7025737 100644 --- a/internal/provider/template.go +++ b/internal/provider/template.go @@ -323,7 +323,7 @@ description: |- ## Arguments {{ .FunctionArgumentsMarkdown }} -{{ if .HasVariadic -}} +{{- if .HasVariadic }} {{ .FunctionVariadicArgumentMarkdown }} {{- end }} `