From 774d4a6da47ef895e3395ec01844124ad96d9f36 Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Tue, 4 Oct 2022 13:36:36 -0700 Subject: [PATCH 1/9] refactor --- pkg/tfgen/docs.go | 66 ++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/pkg/tfgen/docs.go b/pkg/tfgen/docs.go index bcdafe5aa..ef33d1c65 100644 --- a/pkg/tfgen/docs.go +++ b/pkg/tfgen/docs.go @@ -18,9 +18,6 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/hashicorp/go-multierror" - "golang.org/x/text/cases" - "golang.org/x/text/language" "io" "os" "os/exec" @@ -30,6 +27,10 @@ import ( "strings" "sync" + "github.com/hashicorp/go-multierror" + "golang.org/x/text/cases" + "golang.org/x/text/language" + "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/gen/python" "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" "github.com/spf13/afero" @@ -1356,6 +1357,9 @@ func (g *Generator) convertHCL(hcl, path, exampleTitle string, languages []strin } result.WriteString(hclConversionsToString(hclConversions)) + if len(failedLangs) == 0 { + return result.String(), nil + } if len(failedLangs) == len(languages) { hclAllLangsConversionFailures++ @@ -1372,39 +1376,37 @@ func (g *Generator) convertHCL(hcl, path, exampleTitle string, languages []strin } // Log the results when an example fails to convert to some languages, but not all - if len(failedLangs) > 0 && len(failedLangs) < len(languages) { - var failedLangsStrings []string - - for lang := range failedLangs { - failedLangsStrings = append(failedLangsStrings, lang) - - switch lang { - case convert.LanguageTypescript: - hclTypeScriptPartialConversionFailures++ - case convert.LanguagePython: - hclPythonPartialConversionFailures++ - case convert.LanguageCSharp: - hclCSharpPartialConversionFailures++ - case convert.LanguageGo: - hclGoPartialConversionFailures++ - } - } - - if exampleTitle == "" { - g.warn(fmt.Sprintf("unable to convert HCL example for Pulumi entity '%s' in the following language(s): "+ - "%s. Examples for these languages will be dropped from any generated docs or SDKs.", - path, strings.Join(failedLangsStrings, ", "))) - } else { - g.warn(fmt.Sprintf("unable to convert HCL example '%s' for Pulumi entity '%s' in the following language(s): "+ - "%s. Examples for these languages will be dropped from any generated docs or SDKs.", - exampleTitle, path, strings.Join(failedLangsStrings, ", "))) + var failedLangsStrings []string + + for lang := range failedLangs { + failedLangsStrings = append(failedLangsStrings, lang) + + switch lang { + case convert.LanguageTypescript: + hclTypeScriptPartialConversionFailures++ + case convert.LanguagePython: + hclPythonPartialConversionFailures++ + case convert.LanguageCSharp: + hclCSharpPartialConversionFailures++ + case convert.LanguageGo: + hclGoPartialConversionFailures++ } + } - // At least one language out of the given set has been generated, which is considered a success - // nolint:ineffassign - err = nil + if exampleTitle == "" { + g.warn(fmt.Sprintf("unable to convert HCL example for Pulumi entity '%s' in the following language(s): "+ + "%s. Examples for these languages will be dropped from any generated docs or SDKs.", + path, strings.Join(failedLangsStrings, ", "))) + } else { + g.warn(fmt.Sprintf("unable to convert HCL example '%s' for Pulumi entity '%s' in the following language(s): "+ + "%s. Examples for these languages will be dropped from any generated docs or SDKs.", + exampleTitle, path, strings.Join(failedLangsStrings, ", "))) } + // At least one language out of the given set has been generated, which is considered a success + // nolint:ineffassign + err = nil + return result.String(), nil } From 214aef09c0c48023ad133646864ab90ba555f2a9 Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Wed, 5 Oct 2022 08:08:27 -0700 Subject: [PATCH 2/9] wip --- pkg/tfgen/docs.go | 98 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 76 insertions(+), 22 deletions(-) diff --git a/pkg/tfgen/docs.go b/pkg/tfgen/docs.go index ef33d1c65..f528f12a6 100644 --- a/pkg/tfgen/docs.go +++ b/pkg/tfgen/docs.go @@ -19,6 +19,7 @@ import ( "encoding/json" "fmt" "io" + "log" "os" "os/exec" "path/filepath" @@ -1327,6 +1328,65 @@ func hclConversionsToString(hclConversions map[string]string) string { return result.String() } +type diagnostic struct { + exampleTitle string + hclProgram string + isCompleteFailure bool + langErrors map[string]error + conversions map[string]string + g *Generator +} + +func (d *diagnostic) Display() error { + f, err := os.OpenFile(fmt.Sprintf("./errors.%d.md", os.Getpid()), + os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + log.Println(err) + } + defer f.Close() + out := "" + + header := fmt.Sprintf("\n## [*partial failure*] %s\n", d.exampleTitle) + if d.isCompleteFailure { + header = fmt.Sprintf("\n## [**complete failure**] %s\n", d.exampleTitle) + } + out += header + out += fmt.Sprintf("\n### HCL\n") + out += fmt.Sprintf("\n```terraform\n") + out += d.hclProgram + "\n" + out += fmt.Sprintf("\n```\n") + out += fmt.Sprintf("\n### Failed Languages\n") + for lang, err := range d.langErrors { + out += fmt.Sprintf("\n#### %s\n", lang) + out += fmt.Sprintf("\n```text\n") + out += err.Error() + out += fmt.Sprintf("\n```\n") + } + if d.isCompleteFailure { + if _, err := f.WriteString(out); err != nil { + log.Println(err) + } + return nil + } + out += fmt.Sprintf("\n### Successes\n") + for lang, convertedProgram := range d.conversions { + if convertedProgram == "" { + continue + } + out += fmt.Sprintf("\n
\n") + out += fmt.Sprintf("\n%s\n", lang) + out += fmt.Sprintf("\n```%s\n", lang) + out += convertedProgram + out += fmt.Sprintf("\n```\n") + out += fmt.Sprintf("\n
\n") + + } + if _, err := f.WriteString(out); err != nil { + log.Println(err) + } + return nil +} + // convertHCL takes a string of example HCL, its path in the Pulumi schema, the title of the example in the upstream // docs, and a slice of the languages to convert the sample to, and returns a string containing a series of Markdown // code blocks with the example converted in each supplied language. @@ -1361,17 +1421,24 @@ func (g *Generator) convertHCL(hcl, path, exampleTitle string, languages []strin return result.String(), nil } - if len(failedLangs) == len(languages) { - hclAllLangsConversionFailures++ + isCompleteFailure := len(failedLangs) == len(languages) - if exampleTitle == "" { - g.warn(fmt.Sprintf("unable to convert HCL example for Pulumi entity '%s': %v. The example will be dropped "+ - "from any generated docs or SDKs.", path, err)) - } else { - g.warn(fmt.Sprintf("unable to convert HCL example '%s' for Pulumi entity '%s': %v. The example will be "+ - "dropped from any generated docs or SDKs.", exampleTitle, path, err)) - } + if exampleTitle == "" { + exampleTitle = path + } + d := diagnostic{ + exampleTitle: exampleTitle, + hclProgram: hcl, + isCompleteFailure: isCompleteFailure, + langErrors: failedLangs, + conversions: hclConversions, + g: g, + } + + d.Display() + if isCompleteFailure { + hclAllLangsConversionFailures++ return "", err } @@ -1393,20 +1460,7 @@ func (g *Generator) convertHCL(hcl, path, exampleTitle string, languages []strin } } - if exampleTitle == "" { - g.warn(fmt.Sprintf("unable to convert HCL example for Pulumi entity '%s' in the following language(s): "+ - "%s. Examples for these languages will be dropped from any generated docs or SDKs.", - path, strings.Join(failedLangsStrings, ", "))) - } else { - g.warn(fmt.Sprintf("unable to convert HCL example '%s' for Pulumi entity '%s' in the following language(s): "+ - "%s. Examples for these languages will be dropped from any generated docs or SDKs.", - exampleTitle, path, strings.Join(failedLangsStrings, ", "))) - } - // At least one language out of the given set has been generated, which is considered a success - // nolint:ineffassign - err = nil - return result.String(), nil } From 8da880f2c57d2a896773b4e9f43bb7027861a84b Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Wed, 5 Oct 2022 11:59:01 -0700 Subject: [PATCH 3/9] updated --- pkg/tfgen/docs.go | 76 +---------------- pkg/tfgen/examples_coverage_exporter.go | 108 +++++++++++++++++++++++- pkg/tfgen/examples_coverage_tracker.go | 6 +- 3 files changed, 112 insertions(+), 78 deletions(-) diff --git a/pkg/tfgen/docs.go b/pkg/tfgen/docs.go index f528f12a6..2ad6f283a 100644 --- a/pkg/tfgen/docs.go +++ b/pkg/tfgen/docs.go @@ -19,7 +19,6 @@ import ( "encoding/json" "fmt" "io" - "log" "os" "os/exec" "path/filepath" @@ -1248,7 +1247,7 @@ func (g *Generator) convertHCLToString(hcl, path, languageName string) (string, convertedHcl = strings.TrimSpace(string(output)) } - g.coverageTracker.languageConversionSuccess(languageName) + g.coverageTracker.languageConversionSuccess(languageName, convertedHcl) return convertedHcl, nil } @@ -1328,65 +1327,6 @@ func hclConversionsToString(hclConversions map[string]string) string { return result.String() } -type diagnostic struct { - exampleTitle string - hclProgram string - isCompleteFailure bool - langErrors map[string]error - conversions map[string]string - g *Generator -} - -func (d *diagnostic) Display() error { - f, err := os.OpenFile(fmt.Sprintf("./errors.%d.md", os.Getpid()), - os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - log.Println(err) - } - defer f.Close() - out := "" - - header := fmt.Sprintf("\n## [*partial failure*] %s\n", d.exampleTitle) - if d.isCompleteFailure { - header = fmt.Sprintf("\n## [**complete failure**] %s\n", d.exampleTitle) - } - out += header - out += fmt.Sprintf("\n### HCL\n") - out += fmt.Sprintf("\n```terraform\n") - out += d.hclProgram + "\n" - out += fmt.Sprintf("\n```\n") - out += fmt.Sprintf("\n### Failed Languages\n") - for lang, err := range d.langErrors { - out += fmt.Sprintf("\n#### %s\n", lang) - out += fmt.Sprintf("\n```text\n") - out += err.Error() - out += fmt.Sprintf("\n```\n") - } - if d.isCompleteFailure { - if _, err := f.WriteString(out); err != nil { - log.Println(err) - } - return nil - } - out += fmt.Sprintf("\n### Successes\n") - for lang, convertedProgram := range d.conversions { - if convertedProgram == "" { - continue - } - out += fmt.Sprintf("\n
\n") - out += fmt.Sprintf("\n%s\n", lang) - out += fmt.Sprintf("\n```%s\n", lang) - out += convertedProgram - out += fmt.Sprintf("\n```\n") - out += fmt.Sprintf("\n
\n") - - } - if _, err := f.WriteString(out); err != nil { - log.Println(err) - } - return nil -} - // convertHCL takes a string of example HCL, its path in the Pulumi schema, the title of the example in the upstream // docs, and a slice of the languages to convert the sample to, and returns a string containing a series of Markdown // code blocks with the example converted in each supplied language. @@ -1423,20 +1363,6 @@ func (g *Generator) convertHCL(hcl, path, exampleTitle string, languages []strin isCompleteFailure := len(failedLangs) == len(languages) - if exampleTitle == "" { - exampleTitle = path - } - d := diagnostic{ - exampleTitle: exampleTitle, - hclProgram: hcl, - isCompleteFailure: isCompleteFailure, - langErrors: failedLangs, - conversions: hclConversions, - g: g, - } - - d.Display() - if isCompleteFailure { hclAllLangsConversionFailures++ return "", err diff --git a/pkg/tfgen/examples_coverage_exporter.go b/pkg/tfgen/examples_coverage_exporter.go index 16f911196..f75c863cb 100644 --- a/pkg/tfgen/examples_coverage_exporter.go +++ b/pkg/tfgen/examples_coverage_exporter.go @@ -56,7 +56,11 @@ func (ce *coverageExportUtil) tryExport(outputDirectory string) error { if err != nil { return err } - return ce.exportHumanReadable(outputDirectory, "shortSummary.txt") + err = ce.exportHumanReadable(outputDirectory, "shortSummary.txt") + if err != nil { + return err + } + return ce.exportMarkdown(outputDirectory, "summary.md") } // Four different ways to export coverage data: @@ -294,6 +298,108 @@ func (ce *coverageExportUtil) exportOverall(outputDirectory string, fileName str return marshalAndWriteJSON(providerStatistic, jsonOutputLocation) } +// The fourth mode, which simply gives the provider name, and success percentage. +func (ce *coverageExportUtil) exportMarkdown(outputDirectory string, fileName string) error { + + // The Coverage Tracker data structure is flattened down to the example level, and they all + // get individually written to the file in order to not have the "{ }" brackets at the start and end + type FlattenedExample struct { + ExampleName string + OriginalHCL string `json:"OriginalHCL,omitempty"` + ConversionResults map[string]*LanguageConversionResult + } + + // All the examples in the tracker are iterated by page ID + index, and marshalled into one large byte + // array separated by \n, making the end result look like a bunch of Json files that got concatenated + var brokenExamples []FlattenedExample + + for _, page := range ce.Tracker.EncounteredPages { + for index, example := range page.Examples { + flattenedName := page.Name + if len(page.Examples) > 1 { + flattenedName += fmt.Sprintf("#%d", index) + } + + noErrors := true + for _, result := range example.ConversionResults { + if result.FailureSeverity == Success { + continue + } + noErrors = false + } + if noErrors { + break + } + + brokenExamples = append(brokenExamples, FlattenedExample{ + ExampleName: flattenedName, + OriginalHCL: example.OriginalHCL, + ConversionResults: example.ConversionResults, + }) + } + } + targetFile, err := createEmptyFile(outputDirectory, fileName) + if err != nil { + return err + } + + out := "" + for _, example := range brokenExamples { + + successes := make(map[string]LanguageConversionResult) + failures := make(map[string]LanguageConversionResult) + + for lang, result := range example.ConversionResults { + if result.FailureSeverity == Success { + successes[lang] = *result + continue + } + failures[lang] = *result + } + + isCompleteFailure := len(successes) == 0 + + // print example header + summaryText := "*partial failure*" + if isCompleteFailure { + summaryText = "**complete failure**" + } + + out += fmt.Sprintf("\n## [%s] %s\n", summaryText, example.ExampleName) + + // print original HCL + out += fmt.Sprintf("\n### HCL\n") + out += fmt.Sprintf("\n```terraform\n") + out += example.OriginalHCL + "\n" + out += fmt.Sprintf("\n```\n") + + // print failures + out += fmt.Sprintf("\n### Failed Languages\n") + for lang, err := range failures { + out += fmt.Sprintf("\n#### %s\n", lang) + out += fmt.Sprintf("\n```text\n") + out += err.FailureInfo + out += fmt.Sprintf("\n```\n") + } + if isCompleteFailure { + continue + } + + // print successes + out += fmt.Sprintf("\n### Successes\n") + for lang, success := range successes { + out += fmt.Sprintf("\n
\n") + out += fmt.Sprintf("\n%s\n", lang) + out += fmt.Sprintf("\n```%s\n", lang) + out += success.Program + out += fmt.Sprintf("\n```\n") + out += fmt.Sprintf("\n
\n") + } + } + + return os.WriteFile(targetFile, []byte(out), 0600) +} + // The fourth mode, which simply gives the provider name, and success percentage. func (ce *coverageExportUtil) exportHumanReadable(outputDirectory string, fileName string) error { diff --git a/pkg/tfgen/examples_coverage_tracker.go b/pkg/tfgen/examples_coverage_tracker.go index 133bff764..d76960bc8 100644 --- a/pkg/tfgen/examples_coverage_tracker.go +++ b/pkg/tfgen/examples_coverage_tracker.go @@ -76,6 +76,7 @@ type Example struct { type LanguageConversionResult struct { FailureSeverity int // This conversion's outcome: [Success, Warning, Failure, Fatal] FailureInfo string // Additional in-depth information + Program string // Converted program // How many times this example has been converted to this language. // It is expected that this will be equal to 1. @@ -116,7 +117,7 @@ func (ct *CoverageTracker) foundExample(pageName string, hcl string) { } // Used when: current example has been successfully converted to a certain language -func (ct *CoverageTracker) languageConversionSuccess(languageName string) { +func (ct *CoverageTracker) languageConversionSuccess(languageName string, program string) { if ct == nil { return } @@ -124,10 +125,11 @@ func (ct *CoverageTracker) languageConversionSuccess(languageName string) { FailureSeverity: Success, FailureInfo: "", TranslationCount: 1, + Program: program, }) } -//nolint +// nolint // Used when: generator has successfully converted current example, but threw out some warnings func (ct *CoverageTracker) languageConversionWarning(languageName string, warningDiagnostics hcl.Diagnostics) { if ct == nil { From cc2827f95fbc33065a351ee9aef062bfc92be534 Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Wed, 5 Oct 2022 13:21:00 -0700 Subject: [PATCH 4/9] added break lines --- pkg/tfgen/examples_coverage_exporter.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/tfgen/examples_coverage_exporter.go b/pkg/tfgen/examples_coverage_exporter.go index f75c863cb..fc170333a 100644 --- a/pkg/tfgen/examples_coverage_exporter.go +++ b/pkg/tfgen/examples_coverage_exporter.go @@ -365,6 +365,7 @@ func (ce *coverageExportUtil) exportMarkdown(outputDirectory string, fileName st summaryText = "**complete failure**" } + out += fmt.Sprintf("\n---\n") out += fmt.Sprintf("\n## [%s] %s\n", summaryText, example.ExampleName) // print original HCL From 83a02c08cf77a042641bcf8ae016a5042e06fa88 Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Wed, 5 Oct 2022 13:54:12 -0700 Subject: [PATCH 5/9] truncated long error messages --- pkg/tfgen/examples_coverage_exporter.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/tfgen/examples_coverage_exporter.go b/pkg/tfgen/examples_coverage_exporter.go index fc170333a..961b96a4c 100644 --- a/pkg/tfgen/examples_coverage_exporter.go +++ b/pkg/tfgen/examples_coverage_exporter.go @@ -379,7 +379,12 @@ func (ce *coverageExportUtil) exportMarkdown(outputDirectory string, fileName st for lang, err := range failures { out += fmt.Sprintf("\n#### %s\n", lang) out += fmt.Sprintf("\n```text\n") - out += err.FailureInfo + + errMsg := err.FailureInfo + if len(err.FailureInfo) > 1000 { + errMsg = err.FailureInfo[:1000] + } + out += errMsg out += fmt.Sprintf("\n```\n") } if isCompleteFailure { From 99cb5088eb20ffde6202a7fef3fe68c0d584d2b6 Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Mon, 5 Dec 2022 13:52:44 -0800 Subject: [PATCH 6/9] cleaned up --- pkg/tfgen/docs.go | 24 +++++++++++++++++++++++- pkg/tfgen/examples_coverage_exporter.go | 12 +++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/pkg/tfgen/docs.go b/pkg/tfgen/docs.go index 2ad6f283a..3f9746c49 100644 --- a/pkg/tfgen/docs.go +++ b/pkg/tfgen/docs.go @@ -1365,6 +1365,14 @@ func (g *Generator) convertHCL(hcl, path, exampleTitle string, languages []strin if isCompleteFailure { hclAllLangsConversionFailures++ + if exampleTitle == "" { + g.warn(fmt.Sprintf("unable to convert HCL example for Pulumi entity '%s': %v. The example will be dropped "+ + "from any generated docs or SDKs.", path, err)) + } else { + g.warn(fmt.Sprintf("unable to convert HCL example '%s' for Pulumi entity '%s': %v. The example will be "+ + "dropped from any generated docs or SDKs.", exampleTitle, path, err)) + } + return "", err } @@ -1384,9 +1392,23 @@ func (g *Generator) convertHCL(hcl, path, exampleTitle string, languages []strin case convert.LanguageGo: hclGoPartialConversionFailures++ } + + if exampleTitle == "" { + g.warn(fmt.Sprintf("unable to convert HCL example for Pulumi entity '%s' in the following language(s): "+ + "%s. Examples for these languages will be dropped from any generated docs or SDKs.", + path, strings.Join(failedLangsStrings, ", "))) + } else { + g.warn(fmt.Sprintf("unable to convert HCL example '%s' for Pulumi entity '%s' in the following language(s): "+ + "%s. Examples for these languages will be dropped from any generated docs or SDKs.", + exampleTitle, path, strings.Join(failedLangsStrings, ", "))) + } + + // At least one language out of the given set has been generated, which is considered a success + // nolint:ineffassign + err = nil + } - // At least one language out of the given set has been generated, which is considered a success return result.String(), nil } diff --git a/pkg/tfgen/examples_coverage_exporter.go b/pkg/tfgen/examples_coverage_exporter.go index 961b96a4c..05358d044 100644 --- a/pkg/tfgen/examples_coverage_exporter.go +++ b/pkg/tfgen/examples_coverage_exporter.go @@ -56,11 +56,11 @@ func (ce *coverageExportUtil) tryExport(outputDirectory string) error { if err != nil { return err } - err = ce.exportHumanReadable(outputDirectory, "shortSummary.txt") + err = ce.exportMarkdown(outputDirectory, "summary.md") if err != nil { return err } - return ce.exportMarkdown(outputDirectory, "summary.md") + return ce.exportHumanReadable(outputDirectory, "shortSummary.txt") } // Four different ways to export coverage data: @@ -298,7 +298,10 @@ func (ce *coverageExportUtil) exportOverall(outputDirectory string, fileName str return marshalAndWriteJSON(providerStatistic, jsonOutputLocation) } -// The fourth mode, which simply gives the provider name, and success percentage. +// The fifth mode, which provides outputs a markdown file with: +// - the example's name +// - the original HCL +// - the conversion results for all languages func (ce *coverageExportUtil) exportMarkdown(outputDirectory string, fileName string) error { // The Coverage Tracker data structure is flattened down to the example level, and they all @@ -382,12 +385,15 @@ func (ce *coverageExportUtil) exportMarkdown(outputDirectory string, fileName st errMsg := err.FailureInfo if len(err.FailureInfo) > 1000 { + // truncate extremely long error messages errMsg = err.FailureInfo[:1000] } out += errMsg out += fmt.Sprintf("\n```\n") } + if isCompleteFailure { + // it's a complete failure, no successes to print continue } From f50f357ff906d30465534039346f94b4452ebebd Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Mon, 5 Dec 2022 14:10:31 -0800 Subject: [PATCH 7/9] fixed lint --- pkg/tfgen/examples_coverage_exporter.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/tfgen/examples_coverage_exporter.go b/pkg/tfgen/examples_coverage_exporter.go index 05358d044..7b3940026 100644 --- a/pkg/tfgen/examples_coverage_exporter.go +++ b/pkg/tfgen/examples_coverage_exporter.go @@ -368,20 +368,20 @@ func (ce *coverageExportUtil) exportMarkdown(outputDirectory string, fileName st summaryText = "**complete failure**" } - out += fmt.Sprintf("\n---\n") + out += "\n---\n" out += fmt.Sprintf("\n## [%s] %s\n", summaryText, example.ExampleName) // print original HCL - out += fmt.Sprintf("\n### HCL\n") - out += fmt.Sprintf("\n```terraform\n") + out += "\n### HCL\n" + out += "\n```terraform\n" out += example.OriginalHCL + "\n" - out += fmt.Sprintf("\n```\n") + out += "\n```\n" // print failures - out += fmt.Sprintf("\n### Failed Languages\n") + out += "\n### Failed Languages\n" for lang, err := range failures { out += fmt.Sprintf("\n#### %s\n", lang) - out += fmt.Sprintf("\n```text\n") + out += "\n```text\n" errMsg := err.FailureInfo if len(err.FailureInfo) > 1000 { @@ -389,7 +389,7 @@ func (ce *coverageExportUtil) exportMarkdown(outputDirectory string, fileName st errMsg = err.FailureInfo[:1000] } out += errMsg - out += fmt.Sprintf("\n```\n") + out += "\n```\n" } if isCompleteFailure { @@ -398,14 +398,14 @@ func (ce *coverageExportUtil) exportMarkdown(outputDirectory string, fileName st } // print successes - out += fmt.Sprintf("\n### Successes\n") + out += "\n### Successes\n" for lang, success := range successes { - out += fmt.Sprintf("\n
\n") + out += "\n
\n" out += fmt.Sprintf("\n%s\n", lang) out += fmt.Sprintf("\n```%s\n", lang) out += success.Program - out += fmt.Sprintf("\n```\n") - out += fmt.Sprintf("\n
\n") + out += "\n```\n" + out += "\n
\n" } } From bf515caba748610a6632ef561dd82f7aab054f0c Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Mon, 5 Dec 2022 14:12:09 -0800 Subject: [PATCH 8/9] Update pkg/tfgen/examples_coverage_tracker.go --- pkg/tfgen/examples_coverage_tracker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/tfgen/examples_coverage_tracker.go b/pkg/tfgen/examples_coverage_tracker.go index d76960bc8..8e8d71b4e 100644 --- a/pkg/tfgen/examples_coverage_tracker.go +++ b/pkg/tfgen/examples_coverage_tracker.go @@ -129,7 +129,7 @@ func (ct *CoverageTracker) languageConversionSuccess(languageName string, progra }) } -// nolint +//nolint // Used when: generator has successfully converted current example, but threw out some warnings func (ct *CoverageTracker) languageConversionWarning(languageName string, warningDiagnostics hcl.Diagnostics) { if ct == nil { From 0c7170558f19f49f0ce9028760c66466f9fcf5cd Mon Sep 17 00:00:00 2001 From: Kyle Dixler Date: Tue, 6 Dec 2022 07:01:01 -0800 Subject: [PATCH 9/9] Update pkg/tfgen/docs.go --- pkg/tfgen/docs.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/tfgen/docs.go b/pkg/tfgen/docs.go index 3f9746c49..a09021b93 100644 --- a/pkg/tfgen/docs.go +++ b/pkg/tfgen/docs.go @@ -1406,7 +1406,6 @@ func (g *Generator) convertHCL(hcl, path, exampleTitle string, languages []strin // At least one language out of the given set has been generated, which is considered a success // nolint:ineffassign err = nil - } return result.String(), nil