From f8bb6772ec4736e18013ef3f19fdd868b8331326 Mon Sep 17 00:00:00 2001 From: Adam Snyder Date: Mon, 19 Jul 2021 17:21:28 -0700 Subject: [PATCH] Update XS001 and XR005 to allow more ways of setting the Description field --- xpasses/XR005/XR005.go | 2 +- xpasses/XR005/testdata/src/a/main.go | 16 ++++++++++++++++ xpasses/XR005/testdata/src/a/main_v2.go | 16 ++++++++++++++++ xpasses/XS001/XS001.go | 2 +- xpasses/XS001/testdata/src/a/main.go | 18 ++++++++++++++++++ xpasses/XS001/testdata/src/a/main_v2.go | 18 ++++++++++++++++++ 6 files changed, 70 insertions(+), 2 deletions(-) diff --git a/xpasses/XR005/XR005.go b/xpasses/XR005/XR005.go index 07829bfb..c93f3314 100644 --- a/xpasses/XR005/XR005.go +++ b/xpasses/XR005/XR005.go @@ -40,7 +40,7 @@ func run(pass *analysis.Pass) (interface{}, error) { continue } - if resourceInfo.Resource.Description != "" { + if resourceInfo.Fields["Description"] != nil { continue } diff --git a/xpasses/XR005/testdata/src/a/main.go b/xpasses/XR005/testdata/src/a/main.go index a947280a..0dc9448e 100644 --- a/xpasses/XR005/testdata/src/a/main.go +++ b/xpasses/XR005/testdata/src/a/main.go @@ -25,6 +25,22 @@ func f() { Schema: map[string]*schema.Schema{}, } + _ = schema.Resource{ + Create: createFunc, + Description: "Line one.\n\n" + + "Line two", + Read: readFunc, + Schema: map[string]*schema.Schema{}, + } + + descriptions := map[string]string{"name": "test"} + _ = schema.Resource{ + Create: createFunc, + Description: descriptions["name"], + Read: readFunc, + Schema: map[string]*schema.Schema{}, + } + _ = schema.Resource{ // want "resource should configure Description" Read: readFunc, Schema: map[string]*schema.Schema{}, diff --git a/xpasses/XR005/testdata/src/a/main_v2.go b/xpasses/XR005/testdata/src/a/main_v2.go index 6a87b465..33001630 100644 --- a/xpasses/XR005/testdata/src/a/main_v2.go +++ b/xpasses/XR005/testdata/src/a/main_v2.go @@ -25,6 +25,22 @@ func f_v2() { Schema: map[string]*schema.Schema{}, } + _ = schema.Resource{ + Create: createFunc_v2, + Description: "Line one.\n\n" + + "Line two", + Read: readFunc_v2, + Schema: map[string]*schema.Schema{}, + } + + descriptions := map[string]string{"name": "test"} + _ = schema.Resource{ + Create: createFunc_v2, + Description: descriptions["name"], + Read: readFunc_v2, + Schema: map[string]*schema.Schema{}, + } + _ = schema.Resource{ // want "resource should configure Description" Read: readFunc_v2, Schema: map[string]*schema.Schema{}, diff --git a/xpasses/XS001/XS001.go b/xpasses/XS001/XS001.go index 0ae6a9f8..5262dcb4 100644 --- a/xpasses/XS001/XS001.go +++ b/xpasses/XS001/XS001.go @@ -41,7 +41,7 @@ func run(pass *analysis.Pass) (interface{}, error) { continue } - if schemaInfo.Schema.Description != "" { + if schemaInfo.Fields["Description"] != nil { continue } diff --git a/xpasses/XS001/testdata/src/a/main.go b/xpasses/XS001/testdata/src/a/main.go index 944f811b..744d622e 100644 --- a/xpasses/XS001/testdata/src/a/main.go +++ b/xpasses/XS001/testdata/src/a/main.go @@ -26,4 +26,22 @@ func f() { Type: schema.TypeString, }, } + + _ = map[string]*schema.Schema{ + "name": { + Description: "Line one.\n\n" + + "Line two.", + Optional: true, + Type: schema.TypeString, + }, + } + + descriptions := map[string]string{"name": "test"} + _ = map[string]*schema.Schema{ + "name": { + Description: descriptions["name"], + Optional: true, + Type: schema.TypeString, + }, + } } diff --git a/xpasses/XS001/testdata/src/a/main_v2.go b/xpasses/XS001/testdata/src/a/main_v2.go index 5a744b3a..8b7ac557 100644 --- a/xpasses/XS001/testdata/src/a/main_v2.go +++ b/xpasses/XS001/testdata/src/a/main_v2.go @@ -26,4 +26,22 @@ func f_v2() { Type: schema.TypeString, }, } + + _ = map[string]*schema.Schema{ + "name": { + Description: "Line one.\n\n" + + "Line two.", + Optional: true, + Type: schema.TypeString, + }, + } + + descriptions := map[string]string{"name": "test"} + _ = map[string]*schema.Schema{ + "name": { + Description: descriptions["name"], + Optional: true, + Type: schema.TypeString, + }, + } }