Skip to content

Commit

Permalink
re-generate with Go 1.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdan committed Aug 15, 2023
1 parent 39163cc commit 2102385
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion internal/govendor/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func Diff(oldName string, old []byte, newName string, new []byte) []byte {

// Expand matching lines as far possible,
// establishing that x[start.x:end.x] == y[start.y:end.y].
// Note that on the first (or last) iteration we may (or definitey do)
// Note that on the first (or last) iteration we may (or definitely do)
// have an empty match: start.x==end.x and start.y==end.y.
start := m
for start.x > done.x && start.y > done.y && x[start.x-1] == y[start.y-1] {
Expand Down
2 changes: 0 additions & 2 deletions internal/govendor/go/doc/comment/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ func (h *Heading) DefaultID() string {

type commentPrinter struct {
*Printer
headingPrefix string
needDoc map[string]bool
}

// Comment returns the standard Go formatting of the Doc,
Expand Down
3 changes: 3 additions & 0 deletions internal/govendor/go/doc/comment/std.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions internal/govendor/go/printer/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ func formatDocComment(list []*ast.Comment) []*ast.Comment {
kind = "//"
var b strings.Builder
for _, c := range list {
if !strings.HasPrefix(c.Text, "//") {
after, found := strings.CutPrefix(c.Text, "//")
if !found {
return list
}
// Accumulate //go:build etc lines separately.
if isDirective(c.Text[2:]) {
if isDirective(after) {
directives = append(directives, c)
continue
}
b.WriteString(strings.TrimPrefix(c.Text[2:], " "))
b.WriteString(strings.TrimPrefix(after, " "))
b.WriteString("\n")
}
text = b.String()
Expand Down
20 changes: 14 additions & 6 deletions internal/govendor/go/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ type printer struct {
// white space). If there's a difference and SourcePos is set in
// ConfigMode, //line directives are used in the output to restore
// original source positions for a reader.
pos token.Position // current position in AST (source) space
out token.Position // current position in output space
last token.Position // value of pos after calling writeString
linePtr *int // if set, record out.Line for the next token in *linePtr
pos token.Position // current position in AST (source) space
out token.Position // current position in output space
last token.Position // value of pos after calling writeString
linePtr *int // if set, record out.Line for the next token in *linePtr
sourcePosErr error // if non-nil, the first error emitting a //line directive

// The list of all source comments, in order of appearance.
comments []*ast.CommentGroup // may be nil
Expand Down Expand Up @@ -196,6 +197,13 @@ func (p *printer) lineFor(pos token.Pos) int {
// writeLineDirective writes a //line directive if necessary.
func (p *printer) writeLineDirective(pos token.Position) {
if pos.IsValid() && (p.out.Line != pos.Line || p.out.Filename != pos.Filename) {
if strings.ContainsAny(pos.Filename, "\r\n") {
if p.sourcePosErr == nil {
p.sourcePosErr = fmt.Errorf("mvdan.cc/gofumpt/internal/govendor/go/printer: source filename contains unexpected newline character: %q", pos.Filename)
}
return
}

p.output = append(p.output, tabwriter.Escape) // protect '\n' in //line from tabwriter interpretation
p.output = append(p.output, fmt.Sprintf("//line %s:%d\n", pos.Filename, pos.Line)...)
p.output = append(p.output, tabwriter.Escape)
Expand Down Expand Up @@ -804,7 +812,7 @@ func (p *printer) intersperseComments(next token.Position, tok token.Token) (wro
return
}

// whiteWhitespace writes the first n whitespace entries.
// writeWhitespace writes the first n whitespace entries.
func (p *printer) writeWhitespace(n int) {
// write entries
for i := 0; i < n; i++ {
Expand Down Expand Up @@ -1168,7 +1176,7 @@ func (p *printer) printNode(node any) error {
goto unsupported
}

return nil
return p.sourcePosErr

unsupported:
return fmt.Errorf("mvdan.cc/gofumpt/internal/govendor/go/printer: unsupported node type %T", node)
Expand Down
2 changes: 1 addition & 1 deletion internal/govendor/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
go1.20.3
go1.21.0

0 comments on commit 2102385

Please sign in to comment.