Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent declaration of unused variables #93

Merged
merged 4 commits into from
Nov 22, 2023
Merged

Conversation

bendbennett
Copy link
Contributor

Closes: #92

If the spec contains a single nested attribute that has no attributes defined within it, for example:

{
    "name": "details",
    "single_nested": {
        "computed_optional_required": "computed"
    }
}

The generated output, contains unused variable declarations. Specifically

func (t DetailsType) ValueFromObject(ctx context.Context, in basetypes.ObjectValue) (basetypes.ObjectValuable, diag.Diagnostics) {
	var diags diag.Diagnostics

	attributes := in.Attributes() // Unused
        ...

func (v DetailsValue) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
	attrTypes := make(map[string]tftypes.Type, 0)

	var val tftypes.Value  // Unused
	var err error          // Unused
        ...

This PR prevents the generation of variable declarations that are unused in the ValueFromObject(), and ToTerraformValue() methods for list, map, set, and single nested attributes, and list, set, and single nested blocks.

@bendbennett bendbennett added the bug Something isn't working label Nov 21, 2023
@bendbennett bendbennett requested a review from a team as a code owner November 21, 2023 10:01
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably also add a changelog, but other than that looks great! 🚀

Can probably just release v0.3.1 after merging if you'd like 👍🏻

@austinvalle austinvalle added this to the v0.3.1 milestone Nov 21, 2023
@bendbennett bendbennett merged commit 868c558 into main Nov 22, 2023
4 checks passed
@bendbennett bendbennett deleted the bendbennett/issues-92 branch November 22, 2023 15:28
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generator Items with no properties, creates declared but not used variables
2 participants