From 93a38f893bdee0e82fe3719b3dcd73edd8ddc30a Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Fri, 12 Dec 2025 14:26:30 +0100 Subject: [PATCH] remove deprecation origin for now we will add sth like this again when we will be able display a nicer diagnostic with the origin --- internal/lang/marks/marks.go | 9 ++++---- internal/lang/marks/marks_test.go | 29 ++++++++---------------- internal/lang/marks/paths_test.go | 37 +++++++++++++++---------------- 3 files changed, 31 insertions(+), 44 deletions(-) diff --git a/internal/lang/marks/marks.go b/internal/lang/marks/marks.go index 1d763e0b80..54850ca00d 100644 --- a/internal/lang/marks/marks.go +++ b/internal/lang/marks/marks.go @@ -4,7 +4,6 @@ package marks import ( - "github.com/hashicorp/hcl/v2" "github.com/zclconf/go-cty/cty" ) @@ -94,9 +93,10 @@ const Ephemeral = valueMark("Ephemeral") // `type` function. const TypeType = valueMark("TypeType") +// DeprecationMark is a mark indicating that a value is deprecated. It is a struct +// rather than a primitive type so that it can carry a deprecation message. type DeprecationMark struct { Message string - Origin *hcl.Range } func (d DeprecationMark) GoString() string { @@ -104,11 +104,10 @@ func (d DeprecationMark) GoString() string { } // Empty deprecation mark for usage in marks.Has / Contains / etc -var Deprecation = NewDeprecation("", nil) +var Deprecation = NewDeprecation("") -func NewDeprecation(message string, origin *hcl.Range) DeprecationMark { +func NewDeprecation(message string) DeprecationMark { return DeprecationMark{ Message: message, - Origin: origin, } } diff --git a/internal/lang/marks/marks_test.go b/internal/lang/marks/marks_test.go index 1e5f2a71f7..8190385d27 100644 --- a/internal/lang/marks/marks_test.go +++ b/internal/lang/marks/marks_test.go @@ -6,45 +6,34 @@ package marks import ( "testing" - "github.com/hashicorp/hcl/v2" "github.com/zclconf/go-cty/cty" ) func TestDeprecationMark(t *testing.T) { - deprecationWithoutRange := cty.StringVal("OldValue").Mark(NewDeprecation("This is outdated", nil)) - deprecationWithRange := cty.StringVal("OldValue").Mark(NewDeprecation("This is outdated", &hcl.Range{Filename: "example.tf", Start: hcl.Pos{Line: 1, Column: 1}, End: hcl.Pos{Line: 1, Column: 10}})) + deprecation := cty.StringVal("OldValue").Mark(NewDeprecation("This is outdated")) composite := cty.ObjectVal(map[string]cty.Value{ - "foo": deprecationWithRange, - "bar": deprecationWithoutRange, + "foo": deprecation, + "bar": deprecation, "baz": cty.StringVal("Not deprecated"), }) - if !deprecationWithRange.IsMarked() { - t.Errorf("Expected deprecationWithRange to be marked") - } - if !deprecationWithoutRange.IsMarked() { - t.Errorf("Expected deprecationWithoutRange to be marked") + if !deprecation.IsMarked() { + t.Errorf("Expected deprecation to be marked") } if composite.IsMarked() { t.Errorf("Expected composite to be marked") } - if !Has(deprecationWithRange, Deprecation) { - t.Errorf("Expected deprecationWithRange to be marked with Deprecation") - } - if !Has(deprecationWithoutRange, Deprecation) { - t.Errorf("Expected deprecationWithoutRange to be marked with Deprecation") + if !Has(deprecation, Deprecation) { + t.Errorf("Expected deprecation to be marked with Deprecation") } if Has(composite, Deprecation) { t.Errorf("Expected composite to be marked with Deprecation") } - if !Contains(deprecationWithRange, Deprecation) { - t.Errorf("Expected deprecationWithRange to be contain Deprecation Mark") - } - if !Contains(deprecationWithoutRange, Deprecation) { - t.Errorf("Expected deprecationWithoutRange to be contain Deprecation Mark") + if !Contains(deprecation, Deprecation) { + t.Errorf("Expected deprecation to be contain Deprecation Mark") } if !Contains(composite, Deprecation) { t.Errorf("Expected composite to be contain Deprecation Mark") diff --git a/internal/lang/marks/paths_test.go b/internal/lang/marks/paths_test.go index e441c398e0..3d21689dbb 100644 --- a/internal/lang/marks/paths_test.go +++ b/internal/lang/marks/paths_test.go @@ -8,7 +8,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/hcl/v2" "github.com/zclconf/go-cty-debug/ctydebug" "github.com/zclconf/go-cty/cty" ) @@ -33,15 +32,15 @@ func TestPathsWithMark(t *testing.T) { }, { Path: cty.GetAttrPath("deprecated"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")), }, { Path: cty.GetAttrPath("multipleDeprecations"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")), }, { Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"), }, } @@ -72,15 +71,15 @@ func TestPathsWithMark(t *testing.T) { }, { Path: cty.GetAttrPath("deprecated"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")), }, { Path: cty.GetAttrPath("multipleDeprecations"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")), }, { Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"), }, } @@ -117,7 +116,7 @@ func TestPathsWithMark(t *testing.T) { }, { Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"), }, } @@ -167,15 +166,15 @@ func TestRemoveAll_dataMarks(t *testing.T) { input := []cty.PathValueMarks{ { Path: cty.GetAttrPath("deprecated"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")), }, { Path: cty.GetAttrPath("multipleDeprecations"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")), }, { Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"), - Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"), + Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"), }, } @@ -251,7 +250,7 @@ func TestMarkPaths(t *testing.T) { cty.GetAttrPath("o").GetAttr("b"), cty.GetAttrPath("t").IndexInt(0), } - deprecationMark := NewDeprecation("this is deprecated", nil) + deprecationMark := NewDeprecation("this is deprecated") got = MarkPaths(value, deprecationMark, deprecatedPaths) want = cty.ObjectVal(map[string]cty.Value{ "s": cty.StringVal(".s").Mark(deprecationMark), @@ -366,30 +365,30 @@ func TestMarksEqual(t *testing.T) { }, { []cty.PathValueMarks{ - {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", nil))}, + {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))}, }, []cty.PathValueMarks{ - {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", nil))}, + {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))}, }, true, }, { []cty.PathValueMarks{ - {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("different", nil))}, + {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("different"))}, }, []cty.PathValueMarks{ - {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("message", nil))}, + {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("message"))}, }, false, }, { []cty.PathValueMarks{ - {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", &hcl.Range{Filename: "test.tf", Start: hcl.Pos{Line: 1, Column: 1}, End: hcl.Pos{Line: 1, Column: 1}}))}, + {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))}, }, []cty.PathValueMarks{ - {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", &hcl.Range{Filename: "otherFile.tf", Start: hcl.Pos{Line: 1, Column: 1}, End: hcl.Pos{Line: 1, Column: 1}}))}, + {Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))}, }, - false, // TODO: Should this really be different? + true, }, } { t.Run(fmt.Sprint(i), func(t *testing.T) {