From a8561e048b347741808c3a6eb44820e1fa772d8d Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Thu, 13 Jul 2023 13:40:49 +0200 Subject: [PATCH] fix: skip content checks for cdktf files they are translated and the original documents are valid already --- check/legacy_resource_file.go | 14 +++++++++++--- check/registry_resource_file.go | 9 ++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/check/legacy_resource_file.go b/check/legacy_resource_file.go index cd55ead..fa89e5a 100644 --- a/check/legacy_resource_file.go +++ b/check/legacy_resource_file.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "path/filepath" "github.com/hashicorp/go-multierror" ) @@ -58,6 +59,11 @@ func NewLegacyResourceFileCheck(opts *LegacyResourceFileOptions) *LegacyResource func (check *LegacyResourceFileCheck) Run(path string, exampleLanguage string) error { fullpath := check.Options.FullPath(path) + // skip cdktf directories + if IsValidCdktfDirectory(path) { + return nil + } + log.Printf("[DEBUG] Checking file: %s", fullpath) if err := LegacyFileExtensionCheck(path); err != nil { @@ -78,10 +84,12 @@ func (check *LegacyResourceFileCheck) Run(path string, exampleLanguage string) e return fmt.Errorf("%s: error checking file frontmatter: %w", path, err) } - if err := NewContentsCheck(check.Options.Contents).Run(fullpath, exampleLanguage); err != nil { - return fmt.Errorf("%s: error checking file contents: %w", path, err) + // We don't want to check the content for CDKTF files since they are converted + if !IsValidCdktfDirectory(filepath.Dir(fullpath)) { + if err := NewContentsCheck(check.Options.Contents).Run(fullpath, exampleLanguage); err != nil { + return fmt.Errorf("%s: error checking file contents: %w", path, err) + } } - return nil } diff --git a/check/registry_resource_file.go b/check/registry_resource_file.go index 15e31a9..caccc37 100644 --- a/check/registry_resource_file.go +++ b/check/registry_resource_file.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "path/filepath" "github.com/hashicorp/go-multierror" ) @@ -76,10 +77,12 @@ func (check *RegistryResourceFileCheck) Run(path string, exampleLanguage string) return fmt.Errorf("%s: error checking file frontmatter: %w", path, err) } - if err := NewContentsCheck(check.Options.Contents).Run(fullpath, exampleLanguage); err != nil { - return fmt.Errorf("%s: error checking file contents: %w", path, err) + // We don't want to check the content for CDKTF files since they are converted + if !IsValidCdktfDirectory(filepath.Dir(fullpath)) { + if err := NewContentsCheck(check.Options.Contents).Run(fullpath, exampleLanguage); err != nil { + return fmt.Errorf("%s: error checking file contents: %w", path, err) + } } - return nil }