1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
37 // no newlines between consecutive single imports, but
38 // respect extra line breaks in the source (at most one empty line)
52 import "foo" // a comment
53 import "bar" // a comment
65 "unrenamed" // a comment
67 . "io" /* a comment */
68 _ "io/ioutil" // a comment
69 "io" // testing alignment
74 // a case that caused problems in the past (comment placement)
78 "malloc" // for the malloc count test only
84 // more import examples
87 "much longer name" // comment
88 "short name" // comment
93 "much longer name" // comment
98 "/foo/bar/long_package_path" // a comment
102 "package_a" // comment
104 my_better_c "package_c" // comment
105 "package_d" // comment
106 my_e "package_e" // comment
108 "package_a" // comment
110 "package_ccc" // comment
111 "package_dddd" // comment
114 // at least one empty line between declarations of different kind
119 // printing of constant literals
127 _ = 123456789012345678890
139 _ = 012345678901234567889i
140 _ = 123456789012345678890i
165 type _ map[string]int
179 type _ map[string]struct{}
181 type _ func() struct{}
186 type _ map[string]interface{}
187 type _ chan interface{}
188 type _ func() interface{}
193 var _ map[string]struct{}
195 var _ func() struct{}
200 var _ map[string]interface{}
201 var _ chan interface{}
202 var _ func() interface{}
206 // don't lose blank lines in grouped declarations
247 // don't lose blank lines in this struct
259 UncommonType struct {
263 Size, Hash, Alg, Align, FieldAlign, String, UncommonType int
269 Name, PkgPath, Typ, Tag, Offset int
285 Stackguard, Stackbase, Gobuf int
291 Stackbase, Sched, Status, Alllink int
296 // no tabs for single or ungrouped decls
301 var yyyy float = 3.14
321 // tabs for multiple or grouped decls
323 // no entry has a type
329 // some entries have a type
334 yyyyyyyy float = iota
342 // no entry has a type
348 // no entry has a value
358 // some entries have a type
368 // mixed entries - all comments should be aligned
374 f, ff, fff, ffff int = 0, 1, 2, 3 // comment
376 // respect original line breaks
381 // respect original line breaks
401 // alignment of "=" in consecutive lines (extended example from issue 1414)
403 umax uint = ^uint(0) // maximum value for a uint
404 bpu = 1 << (5 + umax>>63) // bits per uint
418 // excerpt from godoc.go
420 goroot = flag.String("goroot", runtime.GOROOT(), "Go root directory")
421 testDir = flag.String("testdir", "", "Go root subdirectory - for testing only (faster startups)")
422 pkgPath = flag.String("path", "", "additional package directories (colon-separated)")
423 filter = flag.String("filter", "", "filter file containing permitted package directory paths")
424 filterMin = flag.Int("filter_minutes", 0, "filter file update interval in minutes; disabled if <= 0")
425 filterDelay delayTime // actual filter update interval in minutes; usually filterDelay == filterMin, but filterDelay may back off exponentially
429 // formatting of structs
432 type _ struct{ /* this comment should be visible */ }
435 // this comment should be visible and properly indented
438 type _ struct { // this comment must not change indentation
456 string "tag" // comment
472 f int "tag" // comment
480 float "tag" // comment
482 f, ff, fff, ffff int // comment
484 h float "tag" // comment
487 type _ struct { a, b,
488 c, d int // this line should be indented
489 u, v, w, x float // this line should be indented
491 r, s float // this line should be indented
498 text []byte // comment
502 // formatting of interfaces
520 type _ interface { // this comment must not change indentation
521 EI // here's a comment
522 f() // no blank between identifier and ()
523 fffff() // no blank between identifier and ()
524 gggggggggggg(x, y, z int) () // hurray
528 // formatting of variable declarations
530 type day struct { n int; short, long string }
532 Sunday = day{ 0, "SUN", "Sunday" }
533 Monday = day{ 1, "MON", "Monday" }
534 Tuesday = day{ 2, "TUE", "Tuesday" }
535 Wednesday = day{ 3, "WED", "Wednesday" }
536 Thursday = day{ 4, "THU", "Thursday" }
537 Friday = day{ 5, "FRI", "Friday" }
538 Saturday = day{ 6, "SAT", "Saturday" }
543 // formatting of multi-line variable declarations
544 var a1, b1, c1 int // all on one line
547 c2 int // this line should be indented
550 c3, d3 int // this line should be indented
551 a4, b4, c4 int // this line should be indented
556 var privateKey2 = &Block{Type: "RSA PRIVATE KEY",
557 Headers: map[string]string{},
558 Bytes: []uint8{0x30, 0x82, 0x1, 0x3a, 0x2, 0x1, 0x0, 0x2,
559 0x41, 0x0, 0xb2, 0x99, 0xf, 0x49, 0xc4, 0x7d, 0xfa, 0x8c,
560 0xd4, 0x0, 0xae, 0x6a, 0x4d, 0x1b, 0x8a, 0x3b, 0x6a, 0x13,
561 0x64, 0x2b, 0x23, 0xf2, 0x8b, 0x0, 0x3b, 0xfb, 0x97, 0x79,
568 var Universe = Scope {
569 Names: map[string]*Ident {
611 // alignment of map composite entries
613 // small key sizes: always align even if size ratios are large
623 // mixed key sizes: align when key sizes change within accepted ratio
627 abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij: a, // outlier - do not align with previous line
628 abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij: a, // align with previous line
630 ab: a, // do not align with previous line
631 abcde: a, // align with previous line
637 a, // must introduce trailing comma
642 // formatting of function results
644 func _() func(int) { return nil }
645 func _() func(int) int { return nil }
646 func _() func(int) func(int) func() { return nil }
649 // formatting of consecutive single-line functions
654 func _() {} // an empty line before this function
658 func _() { f(1, 2, 3) }
659 func _(x int) int { y := x; return y+1 }
660 func _() int { type T struct{}; var x T; return x }
662 // these must remain multi-line since they are multi-line in the source
670 type T struct{}; var x T; return x
674 // making function declarations safe for new semicolon rules
675 func _() { /* multi-line func because of comment */ }
678 /* multi-line func because block is on multiple lines */ }
681 // ellipsis parameters
686 func _(bool, ...interface{})
687 func _(bool, ...func())
688 func _(bool, ...func(...int))
689 func _(bool, ...map[string]int)
690 func _(bool, ...chan int)
692 func _(b bool, x ...int)
693 func _(b bool, x ...*int)
694 func _(b bool, x ...[]int)
695 func _(b bool, x ...struct{})
696 func _(x ...interface{})
698 func _(x ...func(...int))
699 func _(x ...map[string]int)
700 func _(x ...chan int)
703 // these parameter lists must remain multi-line since they are multi-line in the source
713 func _(bool, // comment
716 func _(x bool, // comment
722 func _(bool, // comment
726 func _(x bool, // comment
754 func _(x int, // comment
760 // properly indent multi-line signatures
761 func ManageStatus(in <-chan *Status, req <-chan Request,
762 stat chan<- *TargetInfo,
763 TargetHistorySize int) {
766 func MultiLineSignature0(
770 func MultiLineSignature1(
775 func MultiLineSignature2(
780 func MultiLineSignature3(
786 func MultiLineSignature4(
792 func MultiLineSignature5(
799 // make sure it also works for methods in interfaces