Skip to content

Commit d571c6f

Browse files
authored
feat(internal/godocfx): mark status of deprecated items (#4525)
A separate PR will update the template to use this new field. A future PR here may include a `status` for the overall package and in the TOC.
1 parent e5a891a commit d571c6f

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

internal/godocfx/godocfx_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,29 @@ stem: "/appengine/docs/standard/go/reference/services/bundled"
254254
}
255255
}
256256
}
257+
258+
func TestGetStatus(t *testing.T) {
259+
tests := []struct {
260+
doc string
261+
want string
262+
}{
263+
{
264+
doc: `Size returns the size of the object in bytes.
265+
The returned value is always the same and is not affected by
266+
calls to Read or Close.
267+
268+
Deprecated: use Reader.Attrs.Size.`,
269+
want: "deprecated",
270+
},
271+
{
272+
doc: `This will never be deprecated!`,
273+
want: "",
274+
},
275+
}
276+
277+
for _, test := range tests {
278+
if got := getStatus(test.doc); got != test.want {
279+
t.Errorf("getStatus(%v) got %q, want %q", test.doc, got, test.want)
280+
}
281+
}
282+
}

internal/godocfx/parse.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type item struct {
9393
Examples []example `yaml:"codeexamples,omitempty"`
9494
Children []child `yaml:"children,omitempty"`
9595
AltLink string `yaml:"alt_link,omitempty"`
96+
Status string `yaml:"status,omitempty"`
9697
}
9798

9899
func (p *page) addItem(i *item) {
@@ -186,6 +187,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
186187
Summary: c.Doc,
187188
Langs: onlyGo,
188189
Syntax: syntax{Content: pkgsite.PrintType(pi.Fset, c.Decl, link.toURL, topLevelDecls)},
190+
Status: getStatus(c.Doc),
189191
})
190192
}
191193
for _, v := range pi.Doc.Vars {
@@ -202,6 +204,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
202204
Summary: v.Doc,
203205
Langs: onlyGo,
204206
Syntax: syntax{Content: pkgsite.PrintType(pi.Fset, v.Decl, link.toURL, topLevelDecls)},
207+
Status: getStatus(v.Doc),
205208
})
206209
}
207210
for _, t := range pi.Doc.Types {
@@ -217,6 +220,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
217220
Langs: onlyGo,
218221
Syntax: syntax{Content: pkgsite.PrintType(pi.Fset, t.Decl, link.toURL, topLevelDecls)},
219222
Examples: processExamples(t.Examples, pi.Fset),
223+
Status: getStatus(t.Doc),
220224
}
221225
// Note: items are added as page.Children, rather than
222226
// typeItem.Children, as a workaround for the DocFX template.
@@ -235,6 +239,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
235239
Summary: c.Doc,
236240
Langs: onlyGo,
237241
Syntax: syntax{Content: pkgsite.PrintType(pi.Fset, c.Decl, link.toURL, topLevelDecls)},
242+
Status: getStatus(c.Doc),
238243
})
239244
}
240245
for _, v := range t.Vars {
@@ -251,6 +256,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
251256
Summary: v.Doc,
252257
Langs: onlyGo,
253258
Syntax: syntax{Content: pkgsite.PrintType(pi.Fset, v.Decl, link.toURL, topLevelDecls)},
259+
Status: getStatus(v.Doc),
254260
})
255261
}
256262

@@ -267,6 +273,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
267273
Langs: onlyGo,
268274
Syntax: syntax{Content: pkgsite.Synopsis(pi.Fset, fn.Decl, link.linkify)},
269275
Examples: processExamples(fn.Examples, pi.Fset),
276+
Status: getStatus(fn.Doc),
270277
})
271278
}
272279
for _, fn := range t.Methods {
@@ -282,6 +289,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
282289
Langs: onlyGo,
283290
Syntax: syntax{Content: pkgsite.Synopsis(pi.Fset, fn.Decl, link.linkify)},
284291
Examples: processExamples(fn.Examples, pi.Fset),
292+
Status: getStatus(fn.Doc),
285293
})
286294
}
287295
}
@@ -298,6 +306,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
298306
Langs: onlyGo,
299307
Syntax: syntax{Content: pkgsite.Synopsis(pi.Fset, fn.Decl, link.linkify)},
300308
Examples: processExamples(fn.Examples, pi.Fset),
309+
Status: getStatus(fn.Doc),
301310
})
302311
}
303312
}
@@ -310,6 +319,16 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
310319
}, nil
311320
}
312321

322+
// getStatus returns a possibly empty status string for the given
323+
// docs.
324+
func getStatus(doc string) string {
325+
deprecated := "\nDeprecated:"
326+
if strings.Contains(doc, deprecated) {
327+
return "deprecated"
328+
}
329+
return ""
330+
}
331+
313332
type linker struct {
314333
// imports is a map from local package name to import path.
315334
// Behavior is undefined when a single import has different names in

internal/godocfx/testdata/golden/index.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2699,6 +2699,7 @@ items:
26992699
syntax:
27002700
content: func (r *<a href="#cloud_google_com_go_storage_Reader">Reader</a>) CacheControl()
27012701
<a href="https://pkg.go.dev/builtin#string">string</a>
2702+
status: deprecated
27022703
- uid: cloud.google.com/go/storage.Reader.Close
27032704
name: |
27042705
func (*Reader) Close
@@ -2727,6 +2728,7 @@ items:
27272728
syntax:
27282729
content: func (r *<a href="#cloud_google_com_go_storage_Reader">Reader</a>) ContentEncoding()
27292730
<a href="https://pkg.go.dev/builtin#string">string</a>
2731+
status: deprecated
27302732
- uid: cloud.google.com/go/storage.Reader.ContentType
27312733
name: |
27322734
func (*Reader) ContentType
@@ -2742,6 +2744,7 @@ items:
27422744
syntax:
27432745
content: func (r *<a href="#cloud_google_com_go_storage_Reader">Reader</a>) ContentType()
27442746
<a href="https://pkg.go.dev/builtin#string">string</a>
2747+
status: deprecated
27452748
- uid: cloud.google.com/go/storage.Reader.LastModified
27462749
name: |
27472750
func (*Reader) LastModified
@@ -2758,6 +2761,7 @@ items:
27582761
content: func (r *<a href="#cloud_google_com_go_storage_Reader">Reader</a>) LastModified()
27592762
(<a href="https://pkg.go.dev/time">time</a>.<a href="https://pkg.go.dev/time#Time">Time</a>,
27602763
<a href="https://pkg.go.dev/builtin#error">error</a>)
2764+
status: deprecated
27612765
- uid: cloud.google.com/go/storage.Reader.Read
27622766
name: |
27632767
func (*Reader) Read
@@ -2800,6 +2804,7 @@ items:
28002804
syntax:
28012805
content: func (r *<a href="#cloud_google_com_go_storage_Reader">Reader</a>) Size()
28022806
<a href="https://pkg.go.dev/builtin#int64">int64</a>
2807+
status: deprecated
28032808
- uid: cloud.google.com/go/storage.ReaderObjectAttrs
28042809
name: ReaderObjectAttrs
28052810
id: ReaderObjectAttrs
@@ -3108,6 +3113,7 @@ items:
31083113
syntax:
31093114
content: func (w *<a href="#cloud_google_com_go_storage_Writer">Writer</a>) CloseWithError(err
31103115
<a href="https://pkg.go.dev/builtin#error">error</a>) <a href="https://pkg.go.dev/builtin#error">error</a>
3116+
status: deprecated
31113117
- uid: cloud.google.com/go/storage.Writer.Write
31123118
name: |
31133119
func (*Writer) Write

0 commit comments

Comments
 (0)