-
-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add lint job to CI #477
Add lint job to CI #477
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
run: | ||
timeout: 5m | ||
|
||
linters-settings: | ||
errcheck: | ||
check-type-assertions: true | ||
gci: | ||
sections: | ||
- "standard" | ||
- "default" | ||
- "prefix(github.com/goccy/go-yaml)" | ||
- "blank" | ||
- "dot" | ||
gofmt: | ||
simplify: true | ||
govet: | ||
disable: | ||
- tests | ||
misspell: | ||
locale: US | ||
staticcheck: | ||
checks: ["all", "-ST1000", "-ST1005"] | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- errcheck | ||
- gci | ||
- gofmt | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- misspell | ||
- staticcheck | ||
- typecheck | ||
- unused | ||
|
||
issues: | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- staticcheck |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ func (d *Decoder) castToFloat(v interface{}) interface{} { | |
|
||
func (d *Decoder) mergeValueNode(value ast.Node) ast.Node { | ||
if value.Type() == ast.AliasType { | ||
aliasNode := value.(*ast.AliasNode) | ||
aliasNode, _ := value.(*ast.AliasNode) | ||
aliasName := aliasNode.Value.GetToken().Value | ||
return d.anchorNodeMap[aliasName] | ||
} | ||
|
@@ -360,7 +360,7 @@ func (d *Decoder) resolveAlias(node ast.Node) (ast.Node, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
n.Values[idx] = value.(*ast.MappingValueNode) | ||
n.Values[idx], _ = value.(*ast.MappingValueNode) | ||
} | ||
case *ast.TagNode: | ||
value, err := d.resolveAlias(n.Value) | ||
|
@@ -389,7 +389,7 @@ func (d *Decoder) resolveAlias(node ast.Node) (ast.Node, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
n.Key = key.(ast.MapKeyNode) | ||
n.Key, _ = key.(ast.MapKeyNode) | ||
value, err := d.resolveAlias(n.Value) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -476,15 +476,6 @@ func (d *Decoder) getArrayNode(node ast.Node) (ast.ArrayNode, error) { | |
return arrayNode, nil | ||
} | ||
|
||
func (d *Decoder) fileToNode(f *ast.File) ast.Node { | ||
for _, doc := range f.Docs { | ||
if v := d.nodeToValue(doc.Body); v != nil { | ||
return doc.Body | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (d *Decoder) convertValue(v reflect.Value, typ reflect.Type, src ast.Node) (reflect.Value, error) { | ||
if typ.Kind() != reflect.String { | ||
if !v.Type().ConvertibleTo(typ) { | ||
|
@@ -590,7 +581,7 @@ func (d *Decoder) deleteStructKeys(structType reflect.Type, unknownFields map[st | |
} | ||
|
||
if structField.IsInline { | ||
d.deleteStructKeys(field.Type, unknownFields) | ||
_ = d.deleteStructKeys(field.Type, unknownFields) | ||
} else { | ||
delete(unknownFields, structField.RenderName) | ||
} | ||
|
@@ -1275,7 +1266,7 @@ func (d *Decoder) decodeStruct(ctx context.Context, dst reflect.Value, src ast.N | |
} | ||
continue | ||
} | ||
d.setDefaultValueIfConflicted(newFieldValue, structFieldMap) | ||
_ = d.setDefaultValueIfConflicted(newFieldValue, structFieldMap) | ||
fieldValue.Set(d.castToAssignableValue(newFieldValue, fieldValue.Type())) | ||
continue | ||
} | ||
|
@@ -1623,13 +1614,13 @@ func (d *Decoder) readersUnderDir(dir string) ([]io.Reader, error) { | |
|
||
func (d *Decoder) readersUnderDirRecursive(dir string) ([]io.Reader, error) { | ||
readers := []io.Reader{} | ||
if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check the err here? 🤔 |
||
if err := filepath.Walk(dir, func(path string, info os.FileInfo, _ error) error { | ||
if !d.isYAMLFile(path) { | ||
return nil | ||
} | ||
reader, err := d.fileToReader(path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shadows the outer err variable. |
||
if err != nil { | ||
return errors.Wrapf(err, "failed to get reader") | ||
reader, readerErr := d.fileToReader(path) | ||
if readerErr != nil { | ||
return errors.Wrapf(readerErr, "failed to get reader") | ||
} | ||
readers = append(readers, reader) | ||
return nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -592,11 +592,11 @@ func TestDecoder(t *testing.T) { | |
}, | ||
{ | ||
"v: [A,B,C,]", | ||
map[string][]string{"v": []string{"A", "B", "C"}}, | ||
map[string][]string{"v": {"A", "B", "C"}}, | ||
}, | ||
{ | ||
"v: [A,1,C]", | ||
map[string][]string{"v": []string{"A", "1", "C"}}, | ||
map[string][]string{"v": {"A", "1", "C"}}, | ||
}, | ||
{ | ||
"v: [A,1,C]", | ||
|
@@ -610,11 +610,11 @@ func TestDecoder(t *testing.T) { | |
}, | ||
{ | ||
"v:\n - A\n - B\n - C", | ||
map[string][]string{"v": []string{"A", "B", "C"}}, | ||
map[string][]string{"v": {"A", "B", "C"}}, | ||
}, | ||
{ | ||
"v:\n - A\n - 1\n - C", | ||
map[string][]string{"v": []string{"A", "1", "C"}}, | ||
map[string][]string{"v": {"A", "1", "C"}}, | ||
}, | ||
{ | ||
"v:\n - A\n - 1\n - C", | ||
|
@@ -1470,7 +1470,7 @@ items: | |
if err := dec.Decode(&v); err != nil { | ||
t.Fatalf("%+v", err) | ||
} | ||
items := v.(map[string]interface{})["items"].([]interface{}) | ||
items, _ := v.(map[string]interface{})["items"].([]interface{}) | ||
if len(items) != 2 { | ||
t.Fatal("failed to decode with merge key") | ||
} | ||
|
@@ -2152,16 +2152,16 @@ func Example_DisallowUnknownField() { | |
|
||
const src = `--- | ||
simple: string | ||
complecated: string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
unknown: string | ||
` | ||
err := yaml.NewDecoder(strings.NewReader(src), yaml.DisallowUnknownField()).Decode(&v) | ||
fmt.Printf("%v\n", err) | ||
|
||
// OUTPUT: | ||
// [3:1] unknown field "complecated" | ||
// [3:1] unknown field "unknown" | ||
// 1 | --- | ||
// 2 | simple: string | ||
// > 3 | complecated: string | ||
// > 3 | unknown: string | ||
// ^ | ||
} | ||
|
||
|
@@ -2712,22 +2712,22 @@ func TestDecoder_LiteralWithNewLine(t *testing.T) { | |
LastNode string `yaml:"last"` | ||
} | ||
tests := []A{ | ||
A{ | ||
{ | ||
Node: "hello\nworld", | ||
}, | ||
A{ | ||
{ | ||
Node: "hello\nworld\n", | ||
}, | ||
A{ | ||
{ | ||
Node: "hello\nworld\n\n", | ||
}, | ||
A{ | ||
{ | ||
LastNode: "hello\nworld", | ||
}, | ||
A{ | ||
{ | ||
LastNode: "hello\nworld\n", | ||
}, | ||
A{ | ||
{ | ||
LastNode: "hello\nworld\n\n", | ||
}, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused