Skip to content

Commit

Permalink
all: apply Go 1.19's gofmt
Browse files Browse the repository at this point in the history
The automated changes boil down to:

* No empty lines at the end of a godoc

* Quoted blocks are always preceded by a tab

* Lists are always preceded by spaces

* Lists follow a more consistent formatting

* Lines which look like godoc headings now use "#" prefixes

We don't do any other changes right now.
In the near future, we can start using formatted links.

Plus a few manual fixes, mainly for bits of godoc which were being
recognized as block quotes when that wasn't intended.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: Ib0fd1f130f0d602cc1866fa94ccff89e226e156e
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/542567
Reviewed-by: Paul Jolly <[email protected]>
Unity-Result: CUEcueckoo <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
  • Loading branch information
mvdan committed Aug 23, 2022
1 parent e187f9f commit 3f3f181
Show file tree
Hide file tree
Showing 82 changed files with 619 additions and 634 deletions.
2 changes: 0 additions & 2 deletions cue/ast/astutil/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func (c *cursor) Delete() { panic("unsupported") }
//
// Children are traversed in the order in which they appear in the
// respective node's struct definition.
//
func Apply(node ast.Node, before, after func(Cursor) bool) ast.Node {
apply(&applier{before: before, after: after}, nil, &node)
return node
Expand Down Expand Up @@ -303,7 +302,6 @@ func apply(v applyVisitor, parent Cursor, nodePtr interface{}) {
// v.Visit(node) is not nil, apply is invoked recursively with visitor
// w for each of the non-nil children of node, followed by a call of
// w.Visit(nil).
//
func applyCursor(v applyVisitor, c Cursor) {
if v = v.Before(c); v == nil {
return
Expand Down
1 change: 0 additions & 1 deletion cue/ast/astutil/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func ResolveExpr(e ast.Expr, errFn ErrFunc) {
// A Scope maintains the set of named language entities declared
// in the scope and a link to the immediately surrounding (outer)
// scope.
//
type scope struct {
file *ast.File
outer *scope
Expand Down
8 changes: 3 additions & 5 deletions cue/ast/astutil/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ import (
// construction of an AST.
//
// Rewrites:
// - auto inserts imports associated with Idents
// - unshadows imports associated with idents
// - unshadows references for identifiers that were already resolved.
//
// - auto inserts imports associated with Idents
// - unshadows imports associated with idents
// - unshadows references for identifiers that were already resolved.
func Sanitize(f *ast.File) error {
z := &sanitizer{
file: f,
Expand Down Expand Up @@ -324,7 +323,6 @@ func (z *sanitizer) handleIdent(s *scope, n *ast.Ident) bool {
// It prefers short extensions over large ones, while ensuring the likelihood of
// fast termination is high. There are at least two digits to make it visually
// clearer this concerns a generated number.
//
func (z *sanitizer) uniqueName(base string, hidden bool) string {
if hidden && !strings.HasPrefix(base, "_") {
base = "_" + base
Expand Down
6 changes: 3 additions & 3 deletions cue/ast/astutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
// ImportPathName derives the package name from the given import path.
//
// Examples:
// string string
// foo.com/bar bar
// foo.com/bar:baz baz
//
// string string
// foo.com/bar bar
// foo.com/bar:baz baz
func ImportPathName(id string) string {
name := path.Base(id)
if p := strings.LastIndexByte(name, ':'); p > 0 {
Expand Down
1 change: 0 additions & 1 deletion cue/ast/astutil/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func walkDeclList(v visitor, list []ast.Decl) {
// v.Visit(node) is not nil, walk is invoked recursively with visitor
// w for each of the non-nil children of node, followed by a call of
// w.Visit(nil).
//
func walk(v visitor, node ast.Node) {
if v = v.Before(node); v == nil {
return
Expand Down
17 changes: 8 additions & 9 deletions cue/ast/ident.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ func parseIdent(pos token.Pos, ident string) (string, error) {
//
// Examples:
//
// Label Result
// foo "foo" true nil
// true "true" true nil
// "foo" "foo" false nil
// "x-y" "x-y" false nil
// "foo "" false invalid string
// "\(x)" "" false errors.Is(err, ErrIsExpression)
// X=foo "foo" true nil
//
// Label Result
// foo "foo" true nil
// true "true" true nil
// "foo" "foo" false nil
// "x-y" "x-y" false nil
// "foo "" false invalid string
// "\(x)" "" false errors.Is(err, ErrIsExpression)
// X=foo "foo" true nil
func LabelName(l Label) (name string, isIdent bool, err error) {
if a, ok := l.(*Alias); ok {
l, _ = a.Expr.(Label)
Expand Down
2 changes: 0 additions & 2 deletions cue/ast/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
// node must not be nil. If before returns true, Walk invokes f recursively for
// each of the non-nil children of node, followed by a call of after. Both
// functions may be nil. If before is nil, it is assumed to always return true.
//
func Walk(node Node, before func(Node) bool, after func(Node)) {
walk(&inspector{before: before, after: after}, node)
}
Expand Down Expand Up @@ -56,7 +55,6 @@ func walkDeclList(v visitor, list []Decl) {
// v.Visit(node) is not nil, walk is invoked recursively with visitor
// w for each of the non-nil children of node, followed by a call of
// w.Visit(nil).
//
func walk(v visitor, node Node) {
if v = v.Before(node); v == nil {
return
Expand Down
9 changes: 4 additions & 5 deletions cue/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
//
// Use
//
// ctx := cuecontext.New()
// ctx := cuecontext.New()
//
// to create a new Context.
type Context runtime.Runtime
Expand Down Expand Up @@ -338,9 +338,9 @@ func NilIsAny(isAny bool) EncodeOption {
// and used as CUE struct field names by applying the following rules, subject
// to the UTF-8 coercion described for string values above:
//
// - keys of any string type are used directly
// - encoding.TextMarshalers are marshaled
// - integer keys are converted to strings
// - keys of any string type are used directly
// - encoding.TextMarshalers are marshaled
// - integer keys are converted to strings
//
// Pointer values encode as the value pointed to. A nil pointer encodes as the
// null CUE value.
Expand All @@ -352,7 +352,6 @@ func NilIsAny(isAny bool) EncodeOption {
// Channel, complex, and function values cannot be encoded in CUE. Attempting to
// encode such a value results in the returned value being an error, accessible
// through the Err method.
//
func (c *Context) Encode(x interface{}, option ...EncodeOption) Value {
switch v := x.(type) {
case adt.Value:
Expand Down
14 changes: 6 additions & 8 deletions cue/cue.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@
// A Context defines the set of active packages, the translations of field
// names to unique codes, as well as the set of builtins. Use
//
// import "cuelang.org/go/cue/cuecontext"
// import "cuelang.org/go/cue/cuecontext"
//
// ctx := cuecontext.New()
// ctx := cuecontext.New()
//
// to obtain a context.
//
//
// Note that the following types are DEPRECATED and their usage should be
// avoided if possible:
//
// FieldInfo
// Instance
// Runtime
// Struct
// FieldInfo
// Instance
// Runtime
// Struct
//
// Many types also have deprecated methods. Code that already uses deprecated
// methods can keep using them for at least some time. We aim to provide a
// go or cue fix solution to automatically rewrite code using the new API.
//
package cue
5 changes: 3 additions & 2 deletions cue/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,9 @@ func (o tagOptions) Contains(optionName string) bool {
// 4) simpleLetterEqualFold, no specials, no non-letters.
//
// The letters S and K are special because they map to 3 runes, not just 2:
// * S maps to s and to U+017F 'ſ' Latin small letter long s
// * k maps to K and to U+212A 'K' Kelvin sign
// - S maps to s and to U+017F 'ſ' Latin small letter long s
// - k maps to K and to U+212A 'K' Kelvin sign
//
// See https://play.golang.org/p/tTxjOc0OGo
//
// The returned function is specialized for matching against s and
Expand Down
2 changes: 0 additions & 2 deletions cue/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ func Sanitize(err Error) Error {
// Sort sorts an List. *posError entries are sorted by position,
// other errors are sorted by error message, and before any *posError
// entry.
//
func (p list) Sort() {
sort.Sort(p)
}
Expand Down Expand Up @@ -531,7 +530,6 @@ type Config struct {
// Print is a utility function that prints a list of errors to w,
// one error per line, if the err parameter is an List. Otherwise
// it prints the err string.
//
func Print(w io.Writer, err error, cfg *Config) {
if cfg == nil {
cfg = &Config{}
Expand Down
32 changes: 16 additions & 16 deletions cue/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ import (

// Format prints a CUE value.
//
// WARNING:
// although we are narrowing down the semantics, the verbs and options
// are still subject to change. this API is experimental although it is
// likely getting close to the final design.
// WARNING: although we are narrowing down the semantics, the verbs and options
// are still subject to change. this API is experimental although it is likely
// getting close to the final design.
//
// It recognizes the following verbs:
//
// v print CUE value
// v print CUE value
//
// The verbs support the following flags:
// # print as schema and include definitions.
// The result is printed as a self-contained file, instead of an the
// expression format.
// + evaluate: resolve defaults and error on incomplete errors
//
// # print as schema and include definitions.
// The result is printed as a self-contained file, instead of an the
// expression format.
// + evaluate: resolve defaults and error on incomplete errors
//
// Indentation can be controlled as follows:
// width indent the cue block by <width> tab stops (e.g. %2v)
// precision convert tabs to <precision> spaces (e.g. %.2v), where
// a value of 0 means no indentation or newlines (TODO).
//
// width indent the cue block by <width> tab stops (e.g. %2v)
// precision convert tabs to <precision> spaces (e.g. %.2v), where
// a value of 0 means no indentation or newlines (TODO).
//
// If the value kind corresponds to one of the following Go types, the
// usual Go formatting verbs for that type can be used:
//
// Int: b,d,o,O,q,x,X
// Float: f,e,E,g,G
// String/Bytes: s,q,x,X
// Int: b,d,o,O,q,x,X
// Float: f,e,E,g,G
// String/Bytes: s,q,x,X
//
// The %v directive will be used if the type is not supported for that verb.
//
func (v Value) Format(state fmt.State, verb rune) {
if v.v == nil {
fmt.Fprint(state, "<nil>")
Expand Down
2 changes: 0 additions & 2 deletions cue/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func sortImportsOption() Option {
//
// The function may return early (before the entire result is written) and
// return a formatting error, for instance due to an incorrect AST.
//
func Node(node ast.Node, opt ...Option) ([]byte, error) {
cfg := newConfig(opt)
return cfg.fprint(node)
Expand All @@ -105,7 +104,6 @@ func Node(node ast.Node, opt ...Option) ([]byte, error) {
// Caution: Tools relying on consistent formatting based on the installed
// version of cue (for instance, such as for presubmit checks) should execute
// that cue binary instead of calling Source.
//
func Source(b []byte, opt ...Option) ([]byte, error) {
cfg := newConfig(opt)

Expand Down
26 changes: 13 additions & 13 deletions cue/format/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ func reduceDepth(depth int) int {
// (Algorithm suggestion by Russ Cox.)
//
// The precedences are:
//
// 7 * / % quo rem div mod
// 6 + -
// 5 == != < <= > >=
Expand All @@ -826,23 +827,22 @@ func reduceDepth(depth int) int {
// To choose the cutoff, look at the whole expression but excluding primary
// expressions (function calls, parenthesized exprs), and apply these rules:
//
// 1) If there is a binary operator with a right side unary operand
// that would clash without a space, the cutoff must be (in order):
//
// /* 8
// ++ 7 // not necessary, but to avoid confusion
// -- 7
// 1. If there is a binary operator with a right side unary operand
// that would clash without a space, the cutoff must be (in order):
//
// (Comparison operators always have spaces around them.)
// /* 8
// ++ 7 // not necessary, but to avoid confusion
// -- 7
//
// 2) If there is a mix of level 7 and level 6 operators, then the cutoff
// is 7 (use spaces to distinguish precedence) in Normal mode
// and 6 (never use spaces) in Compact mode.
// (Comparison operators always have spaces around them.)
//
// 3) If there are no level 6 operators or no level 7 operators, then the
// cutoff is 8 (always use spaces) in Normal mode
// and 6 (never use spaces) in Compact mode.
// 2. If there is a mix of level 7 and level 6 operators, then the cutoff
// is 7 (use spaces to distinguish precedence) in Normal mode
// and 6 (never use spaces) in Compact mode.
//
// 3. If there are no level 6 operators or no level 7 operators, then the
// cutoff is 8 (always use spaces) in Normal mode
// and 6 (never use spaces) in Compact mode.
func (f *formatter) binaryExpr(x *ast.BinaryExpr, prec1, cutoff, depth int) {
f.nestExpr++
defer func() { f.nestExpr-- }()
Expand Down
16 changes: 8 additions & 8 deletions cue/literal/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ const (
// unquoteChar decodes the first character or byte in the escaped string.
// It returns four values:
//
// 1) value, the decoded Unicode code point or byte value if non-negative, or
// one of the following special values:
// - terminatedByQuote indicates terminated by quotes
// - terminatedByExpr means terminated by \(
// - escapedNewline means that the line-termination character was quoted and should be omitted
// 2) multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation;
// 3) tail, the remainder of the string after the character; and
// 4) an error that will be nil if the character is syntactically valid.
// 1. value, the decoded Unicode code point or byte value if non-negative, or
// one of the following special values:
// - terminatedByQuote indicates terminated by quotes
// - terminatedByExpr means terminated by \(
// - escapedNewline means that the line-termination character was quoted and should be omitted
// 2. multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation;
// 3. tail, the remainder of the string after the character; and
// 4. an error that will be nil if the character is syntactically valid.
//
// The second argument, kind, specifies the type of literal being parsed
// and therefore which kind of escape sequences are permitted.
Expand Down
10 changes: 5 additions & 5 deletions cue/load/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@ func (c *Config) absDirFromImportPath(pos token.Pos, p importPath) (absDir, name

// Complete updates the configuration information. After calling complete,
// the following invariants hold:
// - c.ModuleRoot != ""
// - c.Module is set to the module import prefix if there is a cue.mod file
// with the module property.
// - c.loader != nil
// - c.cache != ""
// - c.ModuleRoot != ""
// - c.Module is set to the module import prefix if there is a cue.mod file
// with the module property.
// - c.loader != nil
// - c.cache != ""
func (c Config) complete() (cfg *Config, err error) {
// Each major CUE release should add a tag here.
// Old tags should not be removed. That is, the cue1.x tag is present
Expand Down
12 changes: 6 additions & 6 deletions cue/load/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ const (
// In the directory and ancestor directories up to including one with a
// cue.mod file, all .cue files are considered part of the package except for:
//
// - files starting with _ or . (likely editor temporary files)
// - files with build constraints not satisfied by the context
// - files starting with _ or . (likely editor temporary files)
// - files with build constraints not satisfied by the context
//
// If an error occurs, importPkg sets the error in the returned instance,
// which then may contain partial information.
//
// pkgName indicates which packages to load. It supports the following
// values:
// "" the default package for the directory, if only one
// is present.
// _ anonymous files (which may be marked with _)
// * all packages
//
// "" the default package for the directory, if only one
// is present.
// _ anonymous files (which may be marked with _)
// * all packages
func (l *loader) importPkg(pos token.Pos, p *build.Instance) []*build.Instance {
l.stk.Push(p.ImportPath)
defer l.stk.Pop()
Expand Down
3 changes: 2 additions & 1 deletion cue/load/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func varToString(s string, err error) (ast.Expr, error) {
// A tag binds an identifier to a field to allow passing command-line values.
//
// A tag is of the form
// @tag(<name>,[type=(string|int|number|bool)][,short=<shorthand>+])
//
// @tag(<name>,[type=(string|int|number|bool)][,short=<shorthand>+])
//
// The name is mandatory and type defaults to string. Tags are set using the -t
// option on the command line. -t name=value will parse value for the type
Expand Down
Loading

0 comments on commit 3f3f181

Please sign in to comment.