Skip to content

Commit 7ccdb87

Browse files
committed
re-generate to vendor from Go 1.22.0
1 parent b2260fd commit 7ccdb87

File tree

10 files changed

+43
-48
lines changed

10 files changed

+43
-48
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
Enforce a stricter format than `gofmt`, while being backwards compatible.
88
That is, `gofumpt` is happy with a subset of the formats that `gofmt` is happy with.
99

10-
The tool is a fork of `gofmt` as of Go 1.21, and requires Go 1.20 or later.
10+
The tool is a fork of `gofmt` as of Go 1.22, and requires Go 1.21 or later.
1111
It can be used as a drop-in replacement to format your Go code,
1212
and running `gofmt` after `gofumpt` should produce no changes.
1313
For example:
1414

1515
gofumpt -l -w .
1616

1717
Some of the Go source files in this repository belong to the Go project.
18-
The project includes copies of `go/printer` and `go/doc/comment` as of Go 1.21
18+
The project includes copies of `go/printer` and `go/doc/comment` as of Go 1.22
1919
to ensure consistent formatting independent of what Go version is being used.
2020
The [added formatting rules](#Added-rules) are implemented in the `format` package.
2121

internal/govendor/diff/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func Diff(oldName string, old []byte, newName string, new []byte) []byte {
7474
continue
7575
}
7676

77-
// Expand matching lines as far possible,
77+
// Expand matching lines as far as possible,
7878
// establishing that x[start.x:end.x] == y[start.y:end.y].
7979
// Note that on the first (or last) iteration we may (or definitely do)
8080
// have an empty match: start.x==end.x and start.y==end.y.

internal/govendor/go/doc/comment/html.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import (
1010
"strconv"
1111
)
1212

13-
// An htmlPrinter holds the state needed for printing a Doc as HTML.
13+
// An htmlPrinter holds the state needed for printing a [Doc] as HTML.
1414
type htmlPrinter struct {
1515
*Printer
1616
tight bool
1717
}
1818

19-
// HTML returns an HTML formatting of the Doc.
19+
// HTML returns an HTML formatting of the [Doc].
2020
// See the [Printer] documentation for ways to customize the HTML output.
2121
func (p *Printer) HTML(d *Doc) []byte {
2222
hp := &htmlPrinter{Printer: p}

internal/govendor/go/doc/comment/parse.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package comment
66

77
import (
8-
"sort"
8+
"slices"
99
"strings"
1010
"unicode"
1111
"unicode/utf8"
@@ -176,7 +176,7 @@ type DocLink struct {
176176
func (*DocLink) text() {}
177177

178178
// A Parser is a doc comment parser.
179-
// The fields in the struct can be filled in before calling Parse
179+
// The fields in the struct can be filled in before calling [Parser.Parse]
180180
// in order to customize the details of the parsing process.
181181
type Parser struct {
182182
// Words is a map of Go identifier words that
@@ -260,14 +260,12 @@ func (d *parseDoc) lookupPkg(pkg string) (importPath string, ok bool) {
260260
}
261261

262262
func isStdPkg(path string) bool {
263-
// TODO(rsc): Use sort.Find once we don't have to worry about
264-
// copying this code into older Go environments.
265-
i := sort.Search(len(stdPkgs), func(i int) bool { return stdPkgs[i] >= path })
266-
return i < len(stdPkgs) && stdPkgs[i] == path
263+
_, ok := slices.BinarySearch(stdPkgs, path)
264+
return ok
267265
}
268266

269267
// DefaultLookupPackage is the default package lookup
270-
// function, used when [Parser].LookupPackage is nil.
268+
// function, used when [Parser.LookupPackage] is nil.
271269
// It recognizes names of the packages from the standard
272270
// library with single-element import paths, such as math,
273271
// which would otherwise be impossible to name.
@@ -281,7 +279,7 @@ func DefaultLookupPackage(name string) (importPath string, ok bool) {
281279
return "", false
282280
}
283281

284-
// Parse parses the doc comment text and returns the *Doc form.
282+
// Parse parses the doc comment text and returns the *[Doc] form.
285283
// Comment markers (/* // and */) in the text must have already been removed.
286284
func (p *Parser) Parse(text string) *Doc {
287285
lines := unindent(strings.Split(text, "\n"))

internal/govendor/go/doc/comment/print.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ type commentPrinter struct {
150150
*Printer
151151
}
152152

153-
// Comment returns the standard Go formatting of the Doc,
153+
// Comment returns the standard Go formatting of the [Doc],
154154
// without any comment markers.
155155
func (p *Printer) Comment(d *Doc) []byte {
156156
cp := &commentPrinter{Printer: p}

internal/govendor/go/doc/comment/text.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type textPrinter struct {
2121
width int
2222
}
2323

24-
// Text returns a textual formatting of the Doc.
24+
// Text returns a textual formatting of the [Doc].
2525
// See the [Printer] documentation for ways to customize the text output.
2626
func (p *Printer) Text(d *Doc) []byte {
2727
tp := &textPrinter{

internal/govendor/go/format/format.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ const parserMode = parser.ParseComments | parser.SkipObjectResolution
4343

4444
// Node formats node in canonical gofmt style and writes the result to dst.
4545
//
46-
// The node type must be *ast.File, *printer.CommentedNode, []ast.Decl,
47-
// []ast.Stmt, or assignment-compatible to ast.Expr, ast.Decl, ast.Spec,
48-
// or ast.Stmt. Node does not modify node. Imports are not sorted for
46+
// The node type must be *[ast.File], *[printer.CommentedNode], [][ast.Decl],
47+
// [][ast.Stmt], or assignment-compatible to [ast.Expr], [ast.Decl], [ast.Spec],
48+
// or [ast.Stmt]. Node does not modify node. Imports are not sorted for
4949
// nodes representing partial source files (for instance, if the node is
50-
// not an *ast.File or a *printer.CommentedNode not wrapping an *ast.File).
50+
// not an *[ast.File] or a *[printer.CommentedNode] not wrapping an *[ast.File]).
5151
//
5252
// The function may return early (before the entire result is written)
5353
// and return a formatting error, for instance due to an incorrect AST.

internal/govendor/go/printer/nodes.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ import (
4444
// linebreaks. At the moment there is no easy way to know about
4545
// future (not yet interspersed) comments in this function.
4646
func (p *printer) linebreak(line, min int, ws whiteSpace, newSection bool) (nbreaks int) {
47-
n := nlimit(line - p.pos.Line)
48-
if n < min {
49-
n = min
50-
}
47+
n := max(nlimit(line-p.pos.Line), min)
5148
if n > 0 {
5249
p.print(ws)
5350
if newSection {
@@ -670,9 +667,7 @@ func walkBinary(e *ast.BinaryExpr) (has4, has5 bool, maxProblem int) {
670667
h4, h5, mp := walkBinary(l)
671668
has4 = has4 || h4
672669
has5 = has5 || h5
673-
if maxProblem < mp {
674-
maxProblem = mp
675-
}
670+
maxProblem = max(maxProblem, mp)
676671
}
677672

678673
switch r := e.Y.(type) {
@@ -685,9 +680,7 @@ func walkBinary(e *ast.BinaryExpr) (has4, has5 bool, maxProblem int) {
685680
h4, h5, mp := walkBinary(r)
686681
has4 = has4 || h4
687682
has5 = has5 || h5
688-
if maxProblem < mp {
689-
maxProblem = mp
690-
}
683+
maxProblem = max(maxProblem, mp)
691684

692685
case *ast.StarExpr:
693686
if e.Op == token.QUO { // `*/`
@@ -699,9 +692,7 @@ func walkBinary(e *ast.BinaryExpr) (has4, has5 bool, maxProblem int) {
699692
case "/*", "&&", "&^":
700693
maxProblem = 5
701694
case "++", "--":
702-
if maxProblem < 4 {
703-
maxProblem = 4
704-
}
695+
maxProblem = max(maxProblem, 4)
705696
}
706697
}
707698
return
@@ -983,15 +974,24 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int) {
983974
if len(x.Args) > 1 {
984975
depth++
985976
}
986-
var wasIndented bool
987-
if _, ok := x.Fun.(*ast.FuncType); ok {
988-
// conversions to literal function types require parentheses around the type
977+
978+
// Conversions to literal function types or <-chan
979+
// types require parentheses around the type.
980+
paren := false
981+
switch t := x.Fun.(type) {
982+
case *ast.FuncType:
983+
paren = true
984+
case *ast.ChanType:
985+
paren = t.Dir == ast.RECV
986+
}
987+
if paren {
989988
p.print(token.LPAREN)
990-
wasIndented = p.possibleSelectorExpr(x.Fun, token.HighestPrec, depth)
989+
}
990+
wasIndented := p.possibleSelectorExpr(x.Fun, token.HighestPrec, depth)
991+
if paren {
991992
p.print(token.RPAREN)
992-
} else {
993-
wasIndented = p.possibleSelectorExpr(x.Fun, token.HighestPrec, depth)
994993
}
994+
995995
p.setPos(x.Lparen)
996996
p.print(token.LPAREN)
997997
if x.Ellipsis.IsValid() {
@@ -1739,7 +1739,7 @@ func (p *printer) genDecl(d *ast.GenDecl) {
17391739
p.setPos(d.Pos())
17401740
p.print(d.Tok, blank)
17411741

1742-
if d.Lparen.IsValid() || len(d.Specs) > 1 {
1742+
if d.Lparen.IsValid() || len(d.Specs) != 1 {
17431743
// group of parenthesized declarations
17441744
p.setPos(d.Lparen)
17451745
p.print(token.LPAREN)

internal/govendor/go/printer/printer.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -860,10 +860,7 @@ func (p *printer) writeWhitespace(n int) {
860860

861861
// nlimit limits n to maxNewlines.
862862
func nlimit(n int) int {
863-
if n > maxNewlines {
864-
n = maxNewlines
865-
}
866-
return n
863+
return min(n, maxNewlines)
867864
}
868865

869866
func mayCombine(prev token.Token, next byte) (b bool) {
@@ -1412,22 +1409,22 @@ func (cfg *Config) fprint(output io.Writer, fset *token.FileSet, node any, nodeS
14121409
}
14131410

14141411
// A CommentedNode bundles an AST node and corresponding comments.
1415-
// It may be provided as argument to any of the Fprint functions.
1412+
// It may be provided as argument to any of the [Fprint] functions.
14161413
type CommentedNode struct {
14171414
Node any // *ast.File, or ast.Expr, ast.Decl, ast.Spec, or ast.Stmt
14181415
Comments []*ast.CommentGroup
14191416
}
14201417

14211418
// Fprint "pretty-prints" an AST node to output for a given configuration cfg.
14221419
// Position information is interpreted relative to the file set fset.
1423-
// The node type must be *ast.File, *CommentedNode, []ast.Decl, []ast.Stmt,
1424-
// or assignment-compatible to ast.Expr, ast.Decl, ast.Spec, or ast.Stmt.
1420+
// The node type must be *[ast.File], *[CommentedNode], [][ast.Decl], [][ast.Stmt],
1421+
// or assignment-compatible to [ast.Expr], [ast.Decl], [ast.Spec], or [ast.Stmt].
14251422
func (cfg *Config) Fprint(output io.Writer, fset *token.FileSet, node any) error {
14261423
return cfg.fprint(output, fset, node, make(map[ast.Node]int))
14271424
}
14281425

14291426
// Fprint "pretty-prints" an AST node to output.
1430-
// It calls Config.Fprint with default settings.
1427+
// It calls [Config.Fprint] with default settings.
14311428
// Note that gofmt uses tabs for indentation but spaces for alignment;
14321429
// use format.Node (package mvdan.cc/gofumpt/internal/govendor/go/format) for output that matches gofmt.
14331430
func Fprint(output io.Writer, fset *token.FileSet, node any) error {

internal/govendor/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
go1.21.0
1+
go1.22.0

0 commit comments

Comments
 (0)