Skip to content

Rendered documentation for function ends with 2 new lines #488

Closed
@jooola

Description

@jooola

Terraform CLI and terraform-plugin-docs Versions

When generating the docs for a function that has no variadic argument, the generated file ends with 2 new lines.

This break our CI pipeline that clean any missing our extra new lines at the end of a file.

Provider Code

import (
    "github.com/hashicorp/terraform-plugin-framework/function"
)

// Ensure the implementation satisfies the desired interfaces.
var _ function.Function = &EchoFunction{}

type EchoFunction struct {}

func (f *EchoFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) {
    resp.Name = "echo"
}

func (f *EchoFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) {
    resp.Definition = function.Definition{
        Summary:     "Echo a string",
        Description: "Given a string value, returns the same value.",

        Parameters: []function.Parameter{
            function.StringParameter{
                Name:        "input",
                Description: "Value to echo",
            },
        },
        Return: function.StringReturn{},
    }
}

func (f *EchoFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) {
    var input string

    // Read Terraform argument data into the variable
    resp.Error = function.ConcatFuncErrors(resp.Error, req.Arguments.Get(ctx, &input))

    // Set the result to the same data
    resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, input))
}

Expected Behavior

The generated file to end with a single new line.

Actual Behavior

The generate file ends with 2 new lines.

Steps to Reproduce

  1. tfplugindocs generate --flags

How much impact is this issue causing?

Low

Logs

No response

Additional Information

I was able to fix that using my own template:

---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}"
subcategory: ""
description: |-
{{ .Summary | plainmarkdown | trimspace | prefixlines "  " }}
---

# {{.Type}}: {{.Name}}

{{ .Description | trimspace }}

{{ if .HasExample -}}
## Example Usage

{{tffile .ExampleFile }}
{{- end }}

## Signature

{{ .FunctionSignatureMarkdown }}

## Arguments

{{ .FunctionArgumentsMarkdown }}
{{- if .HasVariadic }}
{{ .FunctionVariadicArgumentMarkdown }}
{{- end }}

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions