Upgrade to golangci-lint v2 (#1008)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// Package gotoml-test-decoder is a minimal decoder program used to compare this library with other TOML implementations.
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package gotoml-test-encoder is a minimal encoder program used to compare this library with other TOML implementations.
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -24,7 +25,7 @@ func main() {
|
||||
}
|
||||
|
||||
func usage() {
|
||||
log.Printf("Usage: %s < toml-file\n", path.Base(os.Args[0]))
|
||||
log.Printf("Usage: %s < json-file\n", path.Base(os.Args[0]))
|
||||
flag.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -34,10 +34,10 @@ Reading from a file:
|
||||
jsontoml file.json > file.toml
|
||||
`
|
||||
|
||||
var useJsonNumber bool
|
||||
var useJSONNumber bool
|
||||
|
||||
func main() {
|
||||
flag.BoolVar(&useJsonNumber, "use-json-number", false, "unmarshal numbers into `json.Number` type instead of as `float64`")
|
||||
flag.BoolVar(&useJSONNumber, "use-json-number", false, "unmarshal numbers into `json.Number` type instead of as `float64`")
|
||||
|
||||
p := cli.Program{
|
||||
Usage: usage,
|
||||
@@ -52,9 +52,9 @@ func convert(r io.Reader, w io.Writer) error {
|
||||
d := json.NewDecoder(r)
|
||||
e := toml.NewEncoder(w)
|
||||
|
||||
if useJsonNumber {
|
||||
if useJSONNumber {
|
||||
d.UseNumber()
|
||||
e.SetMarshalJsonNumbers(true)
|
||||
e.SetMarshalJSONNumbers(true)
|
||||
}
|
||||
|
||||
err := d.Decode(&v)
|
||||
|
||||
@@ -14,7 +14,7 @@ func TestConvert(t *testing.T) {
|
||||
input string
|
||||
expected string
|
||||
errors bool
|
||||
useJsonNumber bool
|
||||
useJSONNumber bool
|
||||
}{
|
||||
{
|
||||
name: "valid json",
|
||||
@@ -30,7 +30,7 @@ a = 42.0
|
||||
},
|
||||
{
|
||||
name: "use json number",
|
||||
useJsonNumber: true,
|
||||
useJSONNumber: true,
|
||||
input: `
|
||||
{
|
||||
"mytoml": {
|
||||
@@ -50,7 +50,7 @@ a = 42
|
||||
|
||||
for _, e := range examples {
|
||||
b := new(bytes.Buffer)
|
||||
useJsonNumber = e.useJsonNumber
|
||||
useJSONNumber = e.useJSONNumber
|
||||
err := convert(strings.NewReader(e.input), b)
|
||||
if e.errors {
|
||||
assert.Error(t, err)
|
||||
|
||||
@@ -2,7 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -56,5 +56,5 @@ a = 42`),
|
||||
type badReader struct{}
|
||||
|
||||
func (r *badReader) Read([]byte) (int, error) {
|
||||
return 0, fmt.Errorf("reader failed on purpose")
|
||||
return 0, errors.New("reader failed on purpose")
|
||||
}
|
||||
|
||||
+21
-18
@@ -18,6 +18,7 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type invalid struct {
|
||||
@@ -28,7 +29,7 @@ type invalid struct {
|
||||
type valid struct {
|
||||
Name string
|
||||
Input string
|
||||
JsonRef string
|
||||
JSONRef string
|
||||
}
|
||||
|
||||
type testsCollection struct {
|
||||
@@ -39,12 +40,11 @@ type testsCollection struct {
|
||||
Count int
|
||||
}
|
||||
|
||||
const srcTemplate = "// Generated by tomltestgen for toml-test ref {{.Ref}} on {{.Timestamp}}\n" +
|
||||
const srcTemplate = "// Code generated by tomltestgen for toml-test ref {{.Ref}} on {{.Timestamp}}. DO NOT EDIT.\n" +
|
||||
"package toml_test\n" +
|
||||
" import (\n" +
|
||||
" \"testing\"\n" +
|
||||
")\n" +
|
||||
|
||||
"{{range .Invalid}}\n" +
|
||||
"func TestTOMLTest_Invalid_{{.Name}}(t *testing.T) {\n" +
|
||||
" input := {{.Input|gostr}}\n" +
|
||||
@@ -55,28 +55,31 @@ const srcTemplate = "// Generated by tomltestgen for toml-test ref {{.Ref}} on {
|
||||
"{{range .Valid}}\n" +
|
||||
"func TestTOMLTest_Valid_{{.Name}}(t *testing.T) {\n" +
|
||||
" input := {{.Input|gostr}}\n" +
|
||||
" jsonRef := {{.JsonRef|gostr}}\n" +
|
||||
" jsonRef := {{.JSONRef|gostr}}\n" +
|
||||
" testgenValid(t, input, jsonRef)\n" +
|
||||
"}\n" +
|
||||
"{{end}}\n"
|
||||
|
||||
func kebabToCamel(kebab string) string {
|
||||
camel := ""
|
||||
var buf strings.Builder
|
||||
nextUpper := true
|
||||
for _, c := range kebab {
|
||||
if nextUpper {
|
||||
camel += strings.ToUpper(string(c))
|
||||
buf.WriteRune(unicode.ToUpper(c))
|
||||
nextUpper = false
|
||||
} else if c == '-' {
|
||||
nextUpper = true
|
||||
} else if c == '/' {
|
||||
nextUpper = true
|
||||
camel += "_"
|
||||
} else {
|
||||
camel += string(c)
|
||||
switch c {
|
||||
case '-':
|
||||
nextUpper = true
|
||||
case '/':
|
||||
nextUpper = true
|
||||
buf.WriteByte('_')
|
||||
default:
|
||||
buf.WriteRune(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
return camel
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func templateGoStr(input string) string {
|
||||
@@ -110,7 +113,7 @@ func main() {
|
||||
|
||||
log.Printf("> [%s] %s\n", "invalid", name)
|
||||
|
||||
tomlContent, err := os.ReadFile(f)
|
||||
tomlContent, err := os.ReadFile(f) // #nosec G304
|
||||
if err != nil {
|
||||
fmt.Printf("failed to read test file: %s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -131,14 +134,14 @@ func main() {
|
||||
|
||||
log.Printf("> [%s] %s\n", "valid", name)
|
||||
|
||||
tomlContent, err := os.ReadFile(f)
|
||||
tomlContent, err := os.ReadFile(f) // #nosec G304
|
||||
if err != nil {
|
||||
fmt.Printf("failed reading test file: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
filename = strings.TrimSuffix(f, ".toml")
|
||||
jsonContent, err := os.ReadFile(filename + ".json")
|
||||
jsonContent, err := os.ReadFile(filename + ".json") // #nosec G304
|
||||
if err != nil {
|
||||
fmt.Printf("failed reading validation json: %s\n", err)
|
||||
os.Exit(1)
|
||||
@@ -147,7 +150,7 @@ func main() {
|
||||
collection.Valid = append(collection.Valid, valid{
|
||||
Name: name,
|
||||
Input: string(tomlContent),
|
||||
JsonRef: string(jsonContent),
|
||||
JSONRef: string(jsonContent),
|
||||
})
|
||||
collection.Count++
|
||||
}
|
||||
@@ -173,7 +176,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
err = os.WriteFile(*out, outputBytes, 0o644)
|
||||
err = os.WriteFile(*out, outputBytes, 0o600)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user