pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
125 stars 34 forks source link

Incorrect/missing code formatting on some examples #2990

Open scottslowe opened 9 months ago

scottslowe commented 9 months ago

What happened?

While browsing the API docs for the Azure Native provider, I noted that numerous examples were incorrectly formatted or were missing formatting. While this doesn't make it impossible to use the example for guidance, it does significantly raise the level of effort required. Based on what I have observed so far, this only seems to affect examples in Go, and not any other languages.

URLs of specific examples: https://www.pulumi.com/registry/packages/azure-native/api-docs/storage/storageaccount/ (see the second example in Go) https://www.pulumi.com/registry/packages/azure-native/api-docs/compute/virtualmachine/ (see the first example in Go)

I strongly suspect there are more, but these are the ones I can for sure confirm.

I viewed these using Firefox, and have not checked any other browsers.

Example

https://www.pulumi.com/registry/packages/azure-native/api-docs/storage/storageaccount/ (see the second example in Go) https://www.pulumi.com/registry/packages/azure-native/api-docs/compute/virtualmachine/ (see the first example in Go)

Output of pulumi about

N/A

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

cnunciato commented 9 months ago

The leading whitespace is missing from these examples in schema.json as well, so transferring the issue to pulumi/pulumi-azure-native to correct it at the source.

mjeffryes commented 9 months ago

Thanks for reporting this @scottslowe; we'll take a look.

danielrbradley commented 4 months ago

It seems that we've managed to reduce the number of incorrectly formated examples, but quite a few remain.

It's possible to identify the affected resources by searching for a newline directly followed by pulumi.Run - with no whitespace between e.g. using the regex \npulumi\.Run.

Some examples are always misformatted and some examples are sometimes misformatted.

Here's a list of resources which at least sometimes contain mis-formatted Go examples:

danielrbradley commented 4 months ago

The cause of the missing formatting appears to be related to the code being invalid and therefore failing when we attempt to reformat it.

One example of this is azurestackhci/UpdateRun. Ignoring whitespace, the diff is:

    Steps: azurestackhci.StepArray{
-       interface{}{
+       &azurestackhci.StepArgs{
            Description:        pulumi.String("Prepare for SSU update"),

When generated with interface{}{ it fails to reformat. When using &azurestackhci.StepArgs{ it works correctly.