Skip to content

Commit 5c898c6

Browse files
remove deprecation origin for now
we will add sth like this again when we will be able display a nicer diagnostic with the origin
1 parent 9a4b90c commit 5c898c6

File tree

3 files changed

+31
-44
lines changed

3 files changed

+31
-44
lines changed

internal/lang/marks/marks.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package marks
55

66
import (
7-
"github.com/hashicorp/hcl/v2"
87
"github.com/zclconf/go-cty/cty"
98
)
109

@@ -94,21 +93,21 @@ const Ephemeral = valueMark("Ephemeral")
9493
// `type` function.
9594
const TypeType = valueMark("TypeType")
9695

96+
// DeprecationMark is a mark indicating that a value is deprecated. It is a struct
97+
// rather than a primitive type so that it can carry a deprecation message.
9798
type DeprecationMark struct {
9899
Message string
99-
Origin *hcl.Range
100100
}
101101

102102
func (d DeprecationMark) GoString() string {
103103
return "marks.deprecation<" + d.Message + ">"
104104
}
105105

106106
// Empty deprecation mark for usage in marks.Has / Contains / etc
107-
var Deprecation = NewDeprecation("", nil)
107+
var Deprecation = NewDeprecation("")
108108

109-
func NewDeprecation(message string, origin *hcl.Range) DeprecationMark {
109+
func NewDeprecation(message string) DeprecationMark {
110110
return DeprecationMark{
111111
Message: message,
112-
Origin: origin,
113112
}
114113
}

internal/lang/marks/marks_test.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,34 @@ package marks
66
import (
77
"testing"
88

9-
"github.com/hashicorp/hcl/v2"
109
"github.com/zclconf/go-cty/cty"
1110
)
1211

1312
func TestDeprecationMark(t *testing.T) {
14-
deprecationWithoutRange := cty.StringVal("OldValue").Mark(NewDeprecation("This is outdated", nil))
15-
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}}))
13+
deprecation := cty.StringVal("OldValue").Mark(NewDeprecation("This is outdated"))
1614

1715
composite := cty.ObjectVal(map[string]cty.Value{
18-
"foo": deprecationWithRange,
19-
"bar": deprecationWithoutRange,
16+
"foo": deprecation,
17+
"bar": deprecation,
2018
"baz": cty.StringVal("Not deprecated"),
2119
})
2220

23-
if !deprecationWithRange.IsMarked() {
24-
t.Errorf("Expected deprecationWithRange to be marked")
25-
}
26-
if !deprecationWithoutRange.IsMarked() {
27-
t.Errorf("Expected deprecationWithoutRange to be marked")
21+
if !deprecation.IsMarked() {
22+
t.Errorf("Expected deprecation to be marked")
2823
}
2924
if composite.IsMarked() {
3025
t.Errorf("Expected composite to be marked")
3126
}
3227

33-
if !Has(deprecationWithRange, Deprecation) {
34-
t.Errorf("Expected deprecationWithRange to be marked with Deprecation")
35-
}
36-
if !Has(deprecationWithoutRange, Deprecation) {
37-
t.Errorf("Expected deprecationWithoutRange to be marked with Deprecation")
28+
if !Has(deprecation, Deprecation) {
29+
t.Errorf("Expected deprecation to be marked with Deprecation")
3830
}
3931
if Has(composite, Deprecation) {
4032
t.Errorf("Expected composite to be marked with Deprecation")
4133
}
4234

43-
if !Contains(deprecationWithRange, Deprecation) {
44-
t.Errorf("Expected deprecationWithRange to be contain Deprecation Mark")
45-
}
46-
if !Contains(deprecationWithoutRange, Deprecation) {
47-
t.Errorf("Expected deprecationWithoutRange to be contain Deprecation Mark")
35+
if !Contains(deprecation, Deprecation) {
36+
t.Errorf("Expected deprecation to be contain Deprecation Mark")
4837
}
4938
if !Contains(composite, Deprecation) {
5039
t.Errorf("Expected composite to be contain Deprecation Mark")

internal/lang/marks/paths_test.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"testing"
99

1010
"github.com/google/go-cmp/cmp"
11-
"github.com/hashicorp/hcl/v2"
1211
"github.com/zclconf/go-cty-debug/ctydebug"
1312
"github.com/zclconf/go-cty/cty"
1413
)
@@ -33,15 +32,15 @@ func TestPathsWithMark(t *testing.T) {
3332
},
3433
{
3534
Path: cty.GetAttrPath("deprecated"),
36-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)),
35+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")),
3736
},
3837
{
3938
Path: cty.GetAttrPath("multipleDeprecations"),
40-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)),
39+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")),
4140
},
4241
{
4342
Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"),
44-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"),
43+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"),
4544
},
4645
}
4746

@@ -72,15 +71,15 @@ func TestPathsWithMark(t *testing.T) {
7271
},
7372
{
7473
Path: cty.GetAttrPath("deprecated"),
75-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)),
74+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")),
7675
},
7776
{
7877
Path: cty.GetAttrPath("multipleDeprecations"),
79-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)),
78+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")),
8079
},
8180
{
8281
Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"),
83-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"),
82+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"),
8483
},
8584
}
8685

@@ -117,7 +116,7 @@ func TestPathsWithMark(t *testing.T) {
117116
},
118117
{
119118
Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"),
120-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"),
119+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"),
121120
},
122121
}
123122

@@ -167,15 +166,15 @@ func TestRemoveAll_dataMarks(t *testing.T) {
167166
input := []cty.PathValueMarks{
168167
{
169168
Path: cty.GetAttrPath("deprecated"),
170-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil)),
169+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated")),
171170
},
172171
{
173172
Path: cty.GetAttrPath("multipleDeprecations"),
174-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil)),
173+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated")),
175174
},
176175
{
177176
Path: cty.GetAttrPath("multipleDeprecationsAndSensitive"),
178-
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated", nil), NewDeprecation("this is also deprecated", nil), "sensitive"),
177+
Marks: cty.NewValueMarks(NewDeprecation("this is deprecated"), NewDeprecation("this is also deprecated"), "sensitive"),
179178
},
180179
}
181180

@@ -251,7 +250,7 @@ func TestMarkPaths(t *testing.T) {
251250
cty.GetAttrPath("o").GetAttr("b"),
252251
cty.GetAttrPath("t").IndexInt(0),
253252
}
254-
deprecationMark := NewDeprecation("this is deprecated", nil)
253+
deprecationMark := NewDeprecation("this is deprecated")
255254
got = MarkPaths(value, deprecationMark, deprecatedPaths)
256255
want = cty.ObjectVal(map[string]cty.Value{
257256
"s": cty.StringVal(".s").Mark(deprecationMark),
@@ -366,30 +365,30 @@ func TestMarksEqual(t *testing.T) {
366365
},
367366
{
368367
[]cty.PathValueMarks{
369-
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", nil))},
368+
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))},
370369
},
371370
[]cty.PathValueMarks{
372-
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message", nil))},
371+
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))},
373372
},
374373
true,
375374
},
376375
{
377376
[]cty.PathValueMarks{
378-
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("different", nil))},
377+
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("different"))},
379378
},
380379
[]cty.PathValueMarks{
381-
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("message", nil))},
380+
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("message"))},
382381
},
383382
false,
384383
},
385384
{
386385
[]cty.PathValueMarks{
387-
{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}}))},
386+
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))},
388387
},
389388
[]cty.PathValueMarks{
390-
{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}}))},
389+
{Path: cty.Path{cty.GetAttrStep{Name: "a"}}, Marks: cty.NewValueMarks(NewDeprecation("same message"))},
391390
},
392-
false, // TODO: Should this really be different?
391+
true,
393392
},
394393
} {
395394
t.Run(fmt.Sprint(i), func(t *testing.T) {

0 commit comments

Comments
 (0)