From b592ab91fe1b34eafd288d14ffebcb7b0718d8c3 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Mon, 15 Aug 2022 10:37:48 -0400 Subject: [PATCH] Go 1.19 --- .github/workflows/coverage.yml | 2 +- .github/workflows/release.yml | 2 +- .github/workflows/workflow.yml | 2 +- cmd/jsontoml/main.go | 10 +++---- cmd/tomljson/main.go | 10 +++---- cmd/tomll/main.go | 10 +++---- cmd/tomltestgen/main.go | 2 +- errors.go | 1 + fuzz_test.go | 3 +-- internal/ast/ast.go | 8 +++--- .../imported_tests/unmarshal_imported_test.go | 25 ++++++++++++++++++ marshaler.go | 20 +++++++------- unmarshaler.go | 26 +++++++++---------- 13 files changed, 73 insertions(+), 48 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index fb1d51ed..9dd5e042 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -15,6 +15,6 @@ jobs: - name: Setup go uses: actions/setup-go@master with: - go-version: 1.18 + go-version: 1.19 - name: Run tests with coverage run: ./ci.sh coverage -d "${GITHUB_BASE_REF-HEAD}" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e3bdda4..daa49158 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: 1.18 + go-version: 1.19 - name: Login to GitHub Container Registry uses: docker/login-action@v2 with: diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index a5241b89..f8c19cc3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest'] - go: [ '1.17', '1.18' ] + go: [ '1.18', '1.19' ] runs-on: ${{ matrix.os }} name: ${{ matrix.go }}/${{ matrix.os }} steps: diff --git a/cmd/jsontoml/main.go b/cmd/jsontoml/main.go index a95aa625..5a1fbe4a 100644 --- a/cmd/jsontoml/main.go +++ b/cmd/jsontoml/main.go @@ -1,20 +1,20 @@ // Package jsontoml is a program that converts JSON to TOML. // -// Usage +// # Usage // // Reading from stdin: // -// cat file.json | jsontoml > file.toml +// cat file.json | jsontoml > file.toml // // Reading from a file: // -// jsontoml file.json > file.toml +// jsontoml file.json > file.toml // -// Installation +// # Installation // // Using Go: // -// go install github.com/pelletier/go-toml/v2/cmd/jsontoml@latest +// go install github.com/pelletier/go-toml/v2/cmd/jsontoml@latest package main import ( diff --git a/cmd/tomljson/main.go b/cmd/tomljson/main.go index 8fc6bb5b..297b0a58 100644 --- a/cmd/tomljson/main.go +++ b/cmd/tomljson/main.go @@ -1,20 +1,20 @@ // Package tomljson is a program that converts TOML to JSON. // -// Usage +// # Usage // // Reading from stdin: // -// cat file.toml | tomljson > file.json +// cat file.toml | tomljson > file.json // // Reading from a file: // -// tomljson file.toml > file.json +// tomljson file.toml > file.json // -// Installation +// # Installation // // Using Go: // -// go install github.com/pelletier/go-toml/v2/cmd/tomljson@latest +// go install github.com/pelletier/go-toml/v2/cmd/tomljson@latest package main import ( diff --git a/cmd/tomll/main.go b/cmd/tomll/main.go index 94f68a25..2ae3a71f 100644 --- a/cmd/tomll/main.go +++ b/cmd/tomll/main.go @@ -1,20 +1,20 @@ // Package tomll is a linter program for TOML. // -// Usage +// # Usage // // Reading from stdin, writing to stdout: // -// cat file.toml | tomll +// cat file.toml | tomll // // Reading and updating a list of files in place: // -// tomll a.toml b.toml c.toml +// tomll a.toml b.toml c.toml // -// Installation +// # Installation // // Using Go: // -// go install github.com/pelletier/go-toml/v2/cmd/tomll@latest +// go install github.com/pelletier/go-toml/v2/cmd/tomll@latest package main import ( diff --git a/cmd/tomltestgen/main.go b/cmd/tomltestgen/main.go index 1d53a81d..ff2dfd5b 100644 --- a/cmd/tomltestgen/main.go +++ b/cmd/tomltestgen/main.go @@ -3,7 +3,7 @@ // // Within the go-toml package, run `go generate`. Otherwise, use: // -// go run github.com/pelletier/go-toml/cmd/tomltestgen -o toml_testgen_test.go +// go run github.com/pelletier/go-toml/cmd/tomltestgen -o toml_testgen_test.go package main import ( diff --git a/errors.go b/errors.go index 5e6635c3..2e7f0ffd 100644 --- a/errors.go +++ b/errors.go @@ -103,6 +103,7 @@ func (e *DecodeError) Key() Key { // // The function copies all bytes used in DecodeError, so that document and // highlight can be freely deallocated. +// //nolint:funlen func wrapDecodeError(document []byte, de *decodeError) *DecodeError { offset := danger.SubsliceOffset(document, de.highlight) diff --git a/fuzz_test.go b/fuzz_test.go index c6d12c49..6d4b5f2f 100644 --- a/fuzz_test.go +++ b/fuzz_test.go @@ -1,5 +1,4 @@ -//go:build go1.18 -// +build go1.18 +//go:build go1.18 || go1.19 package toml_test diff --git a/internal/ast/ast.go b/internal/ast/ast.go index 33c7f915..9dec2e00 100644 --- a/internal/ast/ast.go +++ b/internal/ast/ast.go @@ -11,10 +11,10 @@ import ( // // For example: // -// it := n.Children() -// for it.Next() { -// it.Node() -// } +// it := n.Children() +// for it.Next() { +// it.Node() +// } type Iterator struct { started bool node *Node diff --git a/internal/imported_tests/unmarshal_imported_test.go b/internal/imported_tests/unmarshal_imported_test.go index 37dc4447..7a396e21 100644 --- a/internal/imported_tests/unmarshal_imported_test.go +++ b/internal/imported_tests/unmarshal_imported_test.go @@ -151,6 +151,7 @@ type quotedKeyMarshalTestStruct struct { } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var quotedKeyMarshalTestData = quotedKeyMarshalTestStruct{ String: "Hello", @@ -160,6 +161,7 @@ var quotedKeyMarshalTestData = quotedKeyMarshalTestStruct{ } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var quotedKeyMarshalTestToml = []byte(`"Yfloat-𝟘" = 3.5 "Z.string-àéù" = "Hello" @@ -272,6 +274,7 @@ var docData = testDoc{ } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var mapTestDoc = testMapDoc{ Title: "TOML Marshal Testing", @@ -559,10 +562,12 @@ func (c customMarshaler) MarshalTOML() ([]byte, error) { var customMarshalerData = customMarshaler{FirstName: "Sally", LastName: "Fields"} // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var customMarshalerToml = []byte(`Sally Fields`) // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var nestedCustomMarshalerData = customMarshalerParent{ Self: customMarshaler{FirstName: "Maiku", LastName: "Suteda"}, @@ -570,6 +575,7 @@ var nestedCustomMarshalerData = customMarshalerParent{ } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var nestedCustomMarshalerToml = []byte(`friends = ["Sally Fields"] me = "Maiku Suteda" @@ -611,6 +617,7 @@ func TestUnmarshalTextMarshaler(t *testing.T) { } // TODO: Remove nolint once type and methods are used by a test +// //nolint:unused type precedentMarshaler struct { FirstName string @@ -629,6 +636,7 @@ func (m precedentMarshaler) MarshalTOML() ([]byte, error) { } // TODO: Remove nolint once type and method are used by a test +// //nolint:unused type customPointerMarshaler struct { FirstName string @@ -641,6 +649,7 @@ func (m *customPointerMarshaler) MarshalTOML() ([]byte, error) { } // TODO: Remove nolint once type and method are used by a test +// //nolint:unused type textPointerMarshaler struct { FirstName string @@ -653,6 +662,7 @@ func (m *textPointerMarshaler) MarshalText() ([]byte, error) { } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var commentTestToml = []byte(` # it's a comment on type @@ -690,6 +700,7 @@ type mapsTestStruct struct { } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var mapsTestData = mapsTestStruct{ Simple: map[string]string{ @@ -713,6 +724,7 @@ var mapsTestData = mapsTestStruct{ } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var mapsTestToml = []byte(` [Other] @@ -735,6 +747,7 @@ var mapsTestToml = []byte(` `) // TODO: Remove nolint once type is used by a test +// //nolint:deadcode,unused type structArrayNoTag struct { A struct { @@ -744,6 +757,7 @@ type structArrayNoTag struct { } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var customTagTestToml = []byte(` [postgres] @@ -758,6 +772,7 @@ var customTagTestToml = []byte(` `) // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var customCommentTagTestToml = []byte(` # db connection @@ -771,6 +786,7 @@ var customCommentTagTestToml = []byte(` `) // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var customCommentedTagTestToml = []byte(` [postgres] @@ -825,6 +841,7 @@ func TestUnmarshalTabInStringAndQuotedKey(t *testing.T) { } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var customMultilineTagTestToml = []byte(`int_slice = [ 1, @@ -834,6 +851,7 @@ var customMultilineTagTestToml = []byte(`int_slice = [ `) // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var testDocBasicToml = []byte(` [document] @@ -846,12 +864,14 @@ var testDocBasicToml = []byte(` `) // TODO: Remove nolint once type is used by a test +// //nolint:deadcode type testDocCustomTag struct { Doc testDocBasicsCustomTag `file:"document"` } // TODO: Remove nolint once type is used by a test +// //nolint:deadcode type testDocBasicsCustomTag struct { Bool bool `file:"bool_val"` @@ -864,6 +884,7 @@ type testDocBasicsCustomTag struct { } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,varcheck var testDocCustomTagData = testDocCustomTag{ Doc: testDocBasicsCustomTag{ @@ -966,6 +987,7 @@ func TestUnmarshalInvalidPointerKind(t *testing.T) { } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused type testDuration struct { Nanosec time.Duration `toml:"nanosec"` @@ -980,6 +1002,7 @@ type testDuration struct { } // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var testDurationToml = []byte(` nanosec = "1ns" @@ -994,6 +1017,7 @@ a_string = "15s" `) // TODO: Remove nolint once var is used by a test +// //nolint:deadcode,unused,varcheck var testDurationToml2 = []byte(`a_string = "15s" hour = "1h0m0s" @@ -1007,6 +1031,7 @@ sec = "1s" `) // TODO: Remove nolint once type is used by a test +// //nolint:deadcode,unused type testBadDuration struct { Val time.Duration `toml:"val"` diff --git a/marshaler.go b/marshaler.go index c9b3ef5f..76896691 100644 --- a/marshaler.go +++ b/marshaler.go @@ -54,7 +54,7 @@ func NewEncoder(w io.Writer) *Encoder { // This behavior can be controlled on an individual struct field basis with the // inline tag: // -// MyField `toml:",inline"` +// MyField `toml:",inline"` func (enc *Encoder) SetTablesInline(inline bool) *Encoder { enc.tablesInline = inline return enc @@ -65,7 +65,7 @@ func (enc *Encoder) SetTablesInline(inline bool) *Encoder { // // This behavior can be controlled on an individual struct field basis with the multiline tag: // -// MyField `multiline:"true"` +// MyField `multiline:"true"` func (enc *Encoder) SetArraysMultiline(multiline bool) *Encoder { enc.arraysMultiline = multiline return enc @@ -89,7 +89,7 @@ func (enc *Encoder) SetIndentTables(indent bool) *Encoder { // // If v cannot be represented to TOML it returns an error. // -// Encoding rules +// # Encoding rules // // A top level slice containing only maps or structs is encoded as [[table // array]]. @@ -120,17 +120,17 @@ func (enc *Encoder) SetIndentTables(indent bool) *Encoder { // Tables and array tables are separated by empty lines. However, consecutive // subtables definitions are not. For example: // -// [top1] +// [top1] // -// [top2] -// [top2.child1] +// [top2] +// [top2.child1] // -// [[array]] +// [[array]] // -// [[array]] -// [array.child2] +// [[array]] +// [array.child2] // -// Struct tags +// # Struct tags // // The encoding of each public struct field can be customized by the format // string in the "toml" key of the struct field's tag. This follows diff --git a/unmarshaler.go b/unmarshaler.go index b3596f6d..24673f72 100644 --- a/unmarshaler.go +++ b/unmarshaler.go @@ -79,22 +79,22 @@ func (d *Decoder) DisallowUnknownFields() *Decoder { // strict mode and a field is missing, a `toml.StrictMissingError` is // returned. In any other case, this function returns a standard Go error. // -// Type mapping +// # Type mapping // // List of supported TOML types and their associated accepted Go types: // -// String -> string -// Integer -> uint*, int*, depending on size -// Float -> float*, depending on size -// Boolean -> bool -// Offset Date-Time -> time.Time -// Local Date-time -> LocalDateTime, time.Time -// Local Date -> LocalDate, time.Time -// Local Time -> LocalTime, time.Time -// Array -> slice and array, depending on elements types -// Table -> map and struct -// Inline Table -> same as Table -// Array of Tables -> same as Array and Table +// String -> string +// Integer -> uint*, int*, depending on size +// Float -> float*, depending on size +// Boolean -> bool +// Offset Date-Time -> time.Time +// Local Date-time -> LocalDateTime, time.Time +// Local Date -> LocalDate, time.Time +// Local Time -> LocalTime, time.Time +// Array -> slice and array, depending on elements types +// Table -> map and struct +// Inline Table -> same as Table +// Array of Tables -> same as Array and Table func (d *Decoder) Decode(v interface{}) error { b, err := ioutil.ReadAll(d.r) if err != nil {