From f2033bdc40b80c2d0caf8c88a3f079d80af88a6f Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 12 Mar 2024 15:52:17 -0700 Subject: [PATCH] Use Go 1.20 Versions before this are unsupported by the Go team anyway, but the main reason is because our pull request checks workflow uses this to determine which toolchain version to run the tests with. This also brings in the new "go fmt" conventions for godoc comments, so this commit updates them all to match those conventions. --- diagnostic.go | 2 +- doc.go | 32 ++++++++++++++++---------------- ext/typeexpr/doc.go | 6 +++--- ext/typeexpr/type_type.go | 3 ++- ext/userfunc/doc.go | 8 ++++---- go.mod | 2 +- gohcl/doc.go | 12 ++++++------ hclwrite/parser.go | 8 ++++---- traversal_for_expr.go | 22 +++++++++++----------- 9 files changed, 48 insertions(+), 47 deletions(-) diff --git a/diagnostic.go b/diagnostic.go index 578f81a2..c84225af 100644 --- a/diagnostic.go +++ b/diagnostic.go @@ -121,7 +121,7 @@ func (d Diagnostics) Error() string { // This is provided as a convenience for returning from a function that // collects and then returns a set of diagnostics: // -// return nil, diags.Append(&hcl.Diagnostic{ ... }) +// return nil, diags.Append(&hcl.Diagnostic{ ... }) // // Note that this modifies the array underlying the diagnostics slice, so // must be used carefully within a single codepath. It is incorrect (and rude) diff --git a/doc.go b/doc.go index a0e3119f..665ad6ca 100644 --- a/doc.go +++ b/doc.go @@ -9,25 +9,25 @@ // configurations in either native HCL syntax or JSON syntax into a Go struct // type: // -// package main +// package main // -// import ( -// "log" -// "github.com/hashicorp/hcl/v2/hclsimple" -// ) +// import ( +// "log" +// "github.com/hashicorp/hcl/v2/hclsimple" +// ) // -// type Config struct { -// LogLevel string `hcl:"log_level"` -// } +// type Config struct { +// LogLevel string `hcl:"log_level"` +// } // -// func main() { -// var config Config -// err := hclsimple.DecodeFile("config.hcl", nil, &config) -// if err != nil { -// log.Fatalf("Failed to load configuration: %s", err) -// } -// log.Printf("Configuration is %#v", config) -// } +// func main() { +// var config Config +// err := hclsimple.DecodeFile("config.hcl", nil, &config) +// if err != nil { +// log.Fatalf("Failed to load configuration: %s", err) +// } +// log.Printf("Configuration is %#v", config) +// } // // If your application needs more control over the evaluation of the // configuration, you can use the functions in the subdirectories hclparse, diff --git a/ext/typeexpr/doc.go b/ext/typeexpr/doc.go index 9c5ab6e2..a5a3a8e1 100644 --- a/ext/typeexpr/doc.go +++ b/ext/typeexpr/doc.go @@ -8,7 +8,7 @@ // use any of the usual language operators. This is similar to type expressions // in statically-typed programming languages. // -// variable "example" { -// type = list(string) -// } +// variable "example" { +// type = list(string) +// } package typeexpr diff --git a/ext/typeexpr/type_type.go b/ext/typeexpr/type_type.go index 3ca0ba43..d86d1f89 100644 --- a/ext/typeexpr/type_type.go +++ b/ext/typeexpr/type_type.go @@ -46,7 +46,8 @@ func TypeConstraintFromVal(v cty.Value) cty.Type { // ConvertFunc is a cty function that implements type conversions. // // Its signature is as follows: -// convert(value, type_constraint) +// +// convert(value, type_constraint) // // ...where type_constraint is a type constraint expression as defined by // typeexpr.TypeConstraint. diff --git a/ext/userfunc/doc.go b/ext/userfunc/doc.go index 4134e807..7bc2d7e1 100644 --- a/ext/userfunc/doc.go +++ b/ext/userfunc/doc.go @@ -10,10 +10,10 @@ // // The function declaration syntax looks like this: // -// function "foo" { -// params = ["name"] -// result = "Hello, ${name}!" -// } +// function "foo" { +// params = ["name"] +// result = "Hello, ${name}!" +// } // // When a user-defined function is called, the expression given for the "result" // attribute is evaluated in an isolated evaluation context that defines variables diff --git a/go.mod b/go.mod index ec1556b3..47a23097 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/hcl/v2 -go 1.18 +go 1.20 require ( github.com/agext/levenshtein v1.2.1 diff --git a/gohcl/doc.go b/gohcl/doc.go index cfec2530..5e103a6a 100644 --- a/gohcl/doc.go +++ b/gohcl/doc.go @@ -10,18 +10,18 @@ // A struct field tag scheme is used, similar to other decoding and // unmarshalling libraries. The tags are formatted as in the following example: // -// ThingType string `hcl:"thing_type,attr"` +// ThingType string `hcl:"thing_type,attr"` // // Within each tag there are two comma-separated tokens. The first is the // name of the corresponding construct in configuration, while the second // is a keyword giving the kind of construct expected. The following // kind keywords are supported: // -// attr (the default) indicates that the value is to be populated from an attribute -// block indicates that the value is to populated from a block -// label indicates that the value is to populated from a block label -// optional is the same as attr, but the field is optional -// remain indicates that the value is to be populated from the remaining body after populating other fields +// attr (the default) indicates that the value is to be populated from an attribute +// block indicates that the value is to populated from a block +// label indicates that the value is to populated from a block label +// optional is the same as attr, but the field is optional +// remain indicates that the value is to be populated from the remaining body after populating other fields // // "attr" fields may either be of type *hcl.Expression, in which case the raw // expression is assigned, or of any type accepted by gocty, in which case diff --git a/hclwrite/parser.go b/hclwrite/parser.go index 53415aeb..b36153df 100644 --- a/hclwrite/parser.go +++ b/hclwrite/parser.go @@ -521,10 +521,10 @@ func writerTokens(nativeTokens hclsyntax.Tokens) Tokens { // boundaries, such that the slice operator could be used to produce // three token sequences for before, within, and after respectively: // -// start, end := partitionTokens(toks, rng) -// before := toks[:start] -// within := toks[start:end] -// after := toks[end:] +// start, end := partitionTokens(toks, rng) +// before := toks[:start] +// within := toks[start:end] +// after := toks[end:] // // This works best when the range is aligned with token boundaries (e.g. // because it was produced in terms of the scanner's result) but if that isn't diff --git a/traversal_for_expr.go b/traversal_for_expr.go index 87eeb159..d3cb4507 100644 --- a/traversal_for_expr.go +++ b/traversal_for_expr.go @@ -74,7 +74,7 @@ func RelTraversalForExpr(expr Expression) (Traversal, Diagnostics) { // For example, the following attribute has an expression that would produce // the keyword "foo": // -// example = foo +// example = foo // // This function is a variant of AbsTraversalForExpr, which uses the same // interface on the given expression. This helper constrains the result @@ -84,16 +84,16 @@ func RelTraversalForExpr(expr Expression) (Traversal, Diagnostics) { // situations where one of a fixed set of keywords is required and arbitrary // expressions are not allowed: // -// switch hcl.ExprAsKeyword(expr) { -// case "allow": -// // (take suitable action for keyword "allow") -// case "deny": -// // (take suitable action for keyword "deny") -// default: -// diags = append(diags, &hcl.Diagnostic{ -// // ... "invalid keyword" diagnostic message ... -// }) -// } +// switch hcl.ExprAsKeyword(expr) { +// case "allow": +// // (take suitable action for keyword "allow") +// case "deny": +// // (take suitable action for keyword "deny") +// default: +// diags = append(diags, &hcl.Diagnostic{ +// // ... "invalid keyword" diagnostic message ... +// }) +// } // // The above approach will generate the same message for both the use of an // unrecognized keyword and for not using a keyword at all, which is usually