Skip to content

Commit b1824e6

Browse files
authored
fix(lang): render function signatures using standard formatting (#53)
1 parent 63ab7db commit b1824e6

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lang/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ func NewFile(header, footer string, packages []*Package) *File
349349

350350
NewFile creates a new instance of File with the provided information\.
351351

352-
## type [Func](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L11-L15>)
352+
## type [Func](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L12-L16>)
353353

354354
Func holds documentation information for a single func declaration within a package or type\.
355355

@@ -359,79 +359,79 @@ type Func struct {
359359
}
360360
```
361361

362-
### func [NewFunc](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L20>)
362+
### func [NewFunc](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L21>)
363363

364364
```go
365365
func NewFunc(cfg *Config, doc *doc.Func, examples []*doc.Example) *Func
366366
```
367367

368368
NewFunc creates a new Func from the corresponding documentation construct from the standard library\, the related token\.FileSet for the package and the list of examples for the package\.
369369

370-
### func \(\*Func\) [Doc](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L65>)
370+
### func \(\*Func\) [Doc](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L66>)
371371

372372
```go
373373
func (fn *Func) Doc() *Doc
374374
```
375375

376376
Doc provides the structured contents of the documentation comment for the function\.
377377

378-
### func \(\*Func\) [Examples](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L77>)
378+
### func \(\*Func\) [Examples](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L79>)
379379

380380
```go
381381
func (fn *Func) Examples() (examples []*Example)
382382
```
383383

384384
Examples provides the list of examples from the list given on initialization that pertain to the function\.
385385

386-
### func \(\*Func\) [Level](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L26>)
386+
### func \(\*Func\) [Level](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L27>)
387387

388388
```go
389389
func (fn *Func) Level() int
390390
```
391391

392392
Level provides the default level at which headers for the func should be rendered in the final documentation\.
393393

394-
### func \(\*Func\) [Location](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L53>)
394+
### func \(\*Func\) [Location](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L54>)
395395

396396
```go
397397
func (fn *Func) Location() Location
398398
```
399399

400400
Location returns a representation of the node's location in a file within a repository\.
401401

402-
### func \(\*Func\) [Name](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L31>)
402+
### func \(\*Func\) [Name](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L32>)
403403

404404
```go
405405
func (fn *Func) Name() string
406406
```
407407

408408
Name provides the name of the function\.
409409

410-
### func \(\*Func\) [Receiver](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L47>)
410+
### func \(\*Func\) [Receiver](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L48>)
411411

412412
```go
413413
func (fn *Func) Receiver() string
414414
```
415415

416416
Receiver provides the type of the receiver for the function\, or empty string if there is no receiver type\.
417417

418-
### func \(\*Func\) [Signature](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L71>)
418+
### func \(\*Func\) [Signature](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L72>)
419419

420420
```go
421421
func (fn *Func) Signature() (string, error)
422422
```
423423

424424
Signature provides the raw text representation of the code for the function's signature\.
425425

426-
### func \(\*Func\) [Summary](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L59>)
426+
### func \(\*Func\) [Summary](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L60>)
427427

428428
```go
429429
func (fn *Func) Summary() string
430430
```
431431

432432
Summary provides the one\-sentence summary of the function's documentation comment
433433

434-
### func \(\*Func\) [Title](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L37>)
434+
### func \(\*Func\) [Title](<https://github.com/princjef/gomarkdoc/blob/master/lang/func.go#L38>)
435435

436436
```go
437437
func (fn *Func) Title() string

lang/func.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package lang
33
import (
44
"fmt"
55
"go/doc"
6+
"go/token"
67
"strings"
78
)
89

@@ -69,7 +70,8 @@ func (fn *Func) Doc() *Doc {
6970
// Signature provides the raw text representation of the code for the
7071
// function's signature.
7172
func (fn *Func) Signature() (string, error) {
72-
return printNode(fn.doc.Decl, fn.cfg.FileSet)
73+
// We use a custom FileSet so that we don't inherit multiline formatting
74+
return printNode(fn.doc.Decl, token.NewFileSet())
7375
}
7476

7577
// Examples provides the list of examples from the list given on initialization

0 commit comments

Comments
 (0)